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

test: add unit test case for func ReportMetrics #1262

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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