@@ -2,12 +2,14 @@ package datadog
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
67 "net/http"
78 "net/http/httptest"
89 "strings"
910 "testing"
1011
12+ "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
1113 metricsapi "github.com/keptn/lifecycle-toolkit/metrics-operator/api/v1alpha2"
1214 "github.com/keptn/lifecycle-toolkit/metrics-operator/controllers/common/fake"
1315 "github.com/stretchr/testify/require"
@@ -69,7 +71,7 @@ func TestEvaluateQuery_HappyPath(t *testing.T) {
6971 r , raw , e := kdd .EvaluateQuery (context .TODO (), metric , p )
7072 require .Nil (t , e )
7173 require .Equal (t , []byte (ddPayload ), raw )
72- require .Equal (t , fmt .Sprintf ("%.3f" , 84.782 ), r )
74+ require .Equal (t , fmt .Sprintf ("%.3f" , 89.116 ), r )
7375}
7476func TestEvaluateQuery_WrongPayloadHandling (t * testing.T ) {
7577 svr := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -285,3 +287,30 @@ func TestEvaluateQuery_EmptyPayload(t *testing.T) {
285287 require .True (t , strings .Contains (e .Error (), "no values in query result" ))
286288
287289}
290+ func TestGetSingleValue_EmptyPoints (t * testing.T ) {
291+ fakeClient := fake .NewClient ()
292+ kdd := KeptnDataDogProvider {
293+ HttpClient : http.Client {},
294+ Log : ctrl .Log .WithName ("testytest" ),
295+ K8sClient : fakeClient ,
296+ }
297+ var points [][]* float64
298+ value := kdd .getSingleValue (points )
299+
300+ require .Zero (t , value )
301+ }
302+ func TestGetSingleValue_HappyPath (t * testing.T ) {
303+ fakeClient := fake .NewClient ()
304+ kdd := KeptnDataDogProvider {
305+ HttpClient : http.Client {},
306+ Log : ctrl .Log .WithName ("testytest" ),
307+ K8sClient : fakeClient ,
308+ }
309+ result := datadogV1.MetricsQueryResponse {}
310+ _ = json .Unmarshal ([]byte (ddPayload ), & result )
311+ points := (result .Series )[0 ].Pointlist
312+ value := kdd .getSingleValue (points )
313+
314+ require .NotZero (t , value )
315+ require .Equal (t , 89.11554133097331 , value )
316+ }
0 commit comments