Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 988e45f

Browse files
author
Guangwen Feng
committed
test: add unit test case for func ReportMetrics
Signed-off-by: Guangwen Feng <[email protected]>
1 parent b184f25 commit 988e45f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

dfget/core/api/supernode_api_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"testing"
2323

24+
api_types "github.com/dragonflyoss/Dragonfly/apis/types"
2425
"github.com/dragonflyoss/Dragonfly/dfget/types"
2526
"github.com/dragonflyoss/Dragonfly/pkg/constants"
2627
"github.com/dragonflyoss/Dragonfly/pkg/httputils"
@@ -123,6 +124,26 @@ func (s *SupernodeAPITestSuite) TestSupernodeAPI_ReportClientError(c *check.C) {
123124
c.Check(r.Code, check.Equals, 700)
124125
}
125126

127+
func (s *SupernodeAPITestSuite) TestSupernodeAPI_ReportMetrics(c *check.C) {
128+
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(0, nil, nil)
129+
r, e := s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
130+
c.Assert(r, check.IsNil)
131+
c.Assert(e.Error(), check.Equals, "0:")
132+
133+
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(0, nil,
134+
fmt.Errorf("test"))
135+
r, e = s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
136+
c.Assert(r, check.IsNil)
137+
c.Assert(e.Error(), check.Equals, "test")
138+
139+
res := types.RegisterResponse{BaseResponse: &types.BaseResponse{}}
140+
s.mock.PostJSONFunc = s.mock.CreatePostJSONFunc(200, []byte(res.String()), nil)
141+
r, e = s.api.ReportMetrics(localhost, &api_types.TaskMetricsRequest{})
142+
c.Assert(e, check.IsNil)
143+
c.Assert(r, check.NotNil)
144+
c.Assert(r.Code, check.Equals, 0)
145+
}
146+
126147
func (s *SupernodeAPITestSuite) TestSupernodeAPI_get(c *check.C) {
127148
type testRes struct {
128149
A int

0 commit comments

Comments
 (0)