44 "fmt"
55 "net/http"
66 "net/http/httptest"
7- "strings"
87 "testing"
98
109 "github.com/stretchr/testify/assert"
@@ -62,36 +61,34 @@ func TestGetMetricValue(t *testing.T) {
6261 BearerToken : "1a2b3bc" ,
6362 }
6463
65- url := strings .TrimPrefix (ts .URL , "https://" )
66-
6764 t .Run ("valid metrics" , func (t * testing.T ) {
6865 t .Run ("counter with no labels" , func (t * testing.T ) {
6966 // when
70- result , err := GetMetricValue (config , url , "sandbox_user_signups_total" , []string {})
67+ result , err := GetMetricValue (config , ts . URL , "sandbox_user_signups_total" , []string {})
7168 // then
7269 require .NoError (t , err )
7370 assert .InDelta (t , float64 (7 ), result , 0.1 )
7471 })
7572
7673 t .Run ("counter with single label" , func (t * testing.T ) {
7774 // when
78- result , err := GetMetricValue (config , url , "workqueue_depth" , []string {"name" , "masteruserrecord-controller" })
75+ result , err := GetMetricValue (config , ts . URL , "workqueue_depth" , []string {"name" , "masteruserrecord-controller" })
7976 // then
8077 require .NoError (t , err )
8178 assert .InDelta (t , float64 (0 ), result , 0.1 )
8279 })
8380
8481 t .Run ("counter with two labels" , func (t * testing.T ) {
8582 // when
86- result , err := GetMetricValue (config , url , "controller_runtime_reconcile_total" , []string {"controller" , "usersignup-controller" , "result" , "success" })
83+ result , err := GetMetricValue (config , ts . URL , "controller_runtime_reconcile_total" , []string {"controller" , "usersignup-controller" , "result" , "success" })
8784 // then
8885 require .NoError (t , err )
8986 assert .InDelta (t , float64 (10 ), result , 0.1 )
9087 })
9188
9289 t .Run ("gauge with no labels" , func (t * testing.T ) {
9390 // when
94- result , err := GetMetricValue (config , url , "sandbox_master_user_record_current" , []string {})
91+ result , err := GetMetricValue (config , ts . URL , "sandbox_master_user_record_current" , []string {})
9592 // then
9693 require .NoError (t , err )
9794 assert .InDelta (t , float64 (7 ), result , 0.01 )
@@ -101,7 +98,7 @@ func TestGetMetricValue(t *testing.T) {
10198 t .Run ("failures" , func (t * testing.T ) {
10299 t .Run ("metric does not exist" , func (t * testing.T ) {
103100 // when
104- result , err := GetMetricValue (config , url , "non_existent_counter" , []string {})
101+ result , err := GetMetricValue (config , ts . URL , "non_existent_counter" , []string {})
105102 // then
106103 require .Error (t , err )
107104 require .EqualError (t , err , "metric 'non_existent_counter{[]}' not found" )
@@ -110,7 +107,7 @@ func TestGetMetricValue(t *testing.T) {
110107
111108 t .Run ("metric family exists but labels do not match" , func (t * testing.T ) {
112109 // when
113- result , err := GetMetricValue (config , url , "workqueue_depth" , []string {"name" , "non-existent-controller" })
110+ result , err := GetMetricValue (config , ts . URL , "workqueue_depth" , []string {"name" , "non-existent-controller" })
114111 // then
115112 require .Error (t , err )
116113 require .EqualError (t , err , "metric 'workqueue_depth{[name non-existent-controller]}' not found" )
@@ -119,7 +116,7 @@ func TestGetMetricValue(t *testing.T) {
119116
120117 t .Run ("odd number of label parameters" , func (t * testing.T ) {
121118 // when
122- result , err := GetMetricValue (config , url , "workqueue_depth" , []string {"name" })
119+ result , err := GetMetricValue (config , ts . URL , "workqueue_depth" , []string {"name" })
123120 // then
124121 require .Error (t , err )
125122 require .EqualError (t , err , "received odd number of label arguments, labels must be key-value pairs" )
0 commit comments