-
Notifications
You must be signed in to change notification settings - Fork 1
/
prometheus_test.go
49 lines (37 loc) · 1.29 KB
/
prometheus_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUnmarshalPrometheusQueryResponse(t *testing.T) {
t.Run("ReturnsUnmarshalledResponse", func(t *testing.T) {
responseBody := []byte("{\"status\":\"success\",\"data\":{\"resultType\":\"vector\",\"result\":[{\"metric\":{\"location\":\"@searchfareapi_gcloud\"},\"value\":[1513161148.757,\"225.4068155675859\"]}]}}")
// act
queryResponse, err := UnmarshalPrometheusQueryResponse(responseBody)
assert.Nil(t, err)
assert.Equal(t, "success", queryResponse.Status)
assert.Equal(t, "vector", queryResponse.Data.ResultType)
//assert.Equal(t, "{\"location\":\"@searchfareapi_gcloud\"}", queryResponse.Data.Result[0].Metric)
assert.Equal(t, "225.4068155675859", queryResponse.Data.Result[0].Value[1])
})
}
func TestGetRequestRate(t *testing.T) {
t.Run("ReturnsQueryValueAsFloat64", func(t *testing.T) {
queryResponse := PrometheusQueryResponse{
Data: PrometheusQueryResponseData{
Result: []PrometheusQueryResponseDataResult{
PrometheusQueryResponseDataResult{
Value: []interface{}{
1513161148.757,
"225.4068155675859",
},
},
},
},
}
// act
floatValue, err := queryResponse.GetRequestRate()
assert.Nil(t, err)
assert.Equal(t, 225.4068155675859, floatValue)
})
}