@@ -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+
126147func (s * SupernodeAPITestSuite ) TestSupernodeAPI_get (c * check.C ) {
127148 type testRes struct {
128149 A int
0 commit comments