Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1262 from fenggw-fnst/work
Browse files Browse the repository at this point in the history
test: add unit test case for func ReportMetrics
  • Loading branch information
lowzj authored Mar 26, 2020
2 parents b184f25 + 988e45f commit aa709f6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dfget/core/api/supernode_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"testing"

api_types "github.com/dragonflyoss/Dragonfly/apis/types"
"github.com/dragonflyoss/Dragonfly/dfget/types"
"github.com/dragonflyoss/Dragonfly/pkg/constants"
"github.com/dragonflyoss/Dragonfly/pkg/httputils"
Expand Down Expand Up @@ -123,6 +124,26 @@ func (s *SupernodeAPITestSuite) TestSupernodeAPI_ReportClientError(c *check.C) {
c.Check(r.Code, check.Equals, 700)
}

func (s *SupernodeAPITestSuite) TestSupernodeAPI_ReportMetrics(c *check.C) {
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(0, nil, nil)
r, e := s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
c.Assert(r, check.IsNil)
c.Assert(e.Error(), check.Equals, "0:")

s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(0, nil,
fmt.Errorf("test"))
r, e = s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
c.Assert(r, check.IsNil)
c.Assert(e.Error(), check.Equals, "test")

res := types.RegisterResponse{BaseResponse: &types.BaseResponse{}}
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(200, []byte(res.String()), nil)
r, e = s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
c.Assert(e, check.IsNil)
c.Assert(r, check.NotNil)
c.Assert(r.Code, check.Equals, 0)
}

func (s *SupernodeAPITestSuite) TestSupernodeAPI_get(c *check.C) {
type testRes struct {
A int
Expand Down

0 comments on commit aa709f6

Please sign in to comment.