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

Commit

Permalink
test: add unit test case for func ReportMetrics
Browse files Browse the repository at this point in the history
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  • Loading branch information
Guangwen Feng committed Mar 26, 2020
1 parent b184f25 commit 988e45f
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 988e45f

Please sign in to comment.