@@ -74,17 +74,17 @@ func TestCacheMetricsStoreAfterPutsAndGets(t *testing.T) {
7474 "etcd_cache_demux_active_watchers" ,
7575 "etcd_cache_demux_history_size" ,
7676 } {
77- require .Contains (t , families , name , "expected metric family %q" , name )
77+ require .Containsf (t , families , name , "expected metric family %q" , name )
7878 }
7979
8080 keysTotal := gaugeValue (t , families , "etcd_cache_store_keys_total" )
81- require .Equal (t , keysTotal , 5.0 , "expected store_keys_total to be 5" )
81+ require .InEpsilonf (t , 5.0 , keysTotal , 0.01 , "expected store_keys_total to be 5" )
8282
8383 latestRev := gaugeValue (t , families , "etcd_cache_store_latest_revision" )
84- require .Equal (t , latestRev , float64 (lastRev ), "expected store_latest_revision to be %d" , lastRev )
84+ require .InEpsilonf (t , float64 (lastRev ), latestRev , 0.01 , "expected store_latest_revision to be %d" , lastRev )
8585
8686 getSuccessCount := counterValue (t , families , "etcd_cache_get_total" , "result" , "success" )
87- require .Equal (t , getSuccessCount , 2.0 , "expected get_total{success} to be 2" )
87+ require .InEpsilonf (t , 2.0 , getSuccessCount , 0.01 , "expected get_total{success} to be 2" )
8888}
8989
9090func TestCacheMetricsWatchRegistration (t * testing.T ) {
@@ -118,8 +118,8 @@ func TestCacheMetricsWatchRegistration(t *testing.T) {
118118 families := scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
119119
120120 watchSuccess := counterValue (t , families , "etcd_cache_watch_total" , "result" , "success" )
121- require .Equal (t , watchSuccess , 2.0 , "expected watch_total{success} to be 2" )
122- require .Contains (t , families , "etcd_cache_watch_register_duration_seconds" ,
121+ require .InEpsilonf (t , 2.0 , watchSuccess , 0.01 , "expected watch_total{success} to be 2" )
122+ require .Containsf (t , families , "etcd_cache_watch_register_duration_seconds" ,
123123 "expected watch_register_duration_seconds metric" )
124124
125125 cancel1 ()
@@ -152,7 +152,7 @@ func TestCacheMetricsDeleteUpdatesKeyCount(t *testing.T) {
152152
153153 families := scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
154154 keysAfterPuts := gaugeValue (t , families , "etcd_cache_store_keys_total" )
155- require .Equal (t , keysAfterPuts , 3.0 )
155+ require .InEpsilon (t , 3.0 , keysAfterPuts , 0.01 )
156156
157157 // Update operation should not increase key count
158158 resp , putErr := client .Put (ctx , "/d/x" , "newVal" )
@@ -161,15 +161,15 @@ func TestCacheMetricsDeleteUpdatesKeyCount(t *testing.T) {
161161
162162 families = scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
163163 keysAfterPuts = gaugeValue (t , families , "etcd_cache_store_keys_total" )
164- require .Equal (t , keysAfterPuts , 3.0 )
164+ require .InEpsilon (t , 3.0 , keysAfterPuts , 0.01 )
165165
166166 delResp , err := client .Delete (ctx , "/d/z" )
167167 require .NoError (t , err )
168168 require .NoError (t , c .WaitForRevision (ctx , delResp .Header .Revision ))
169169
170170 families = scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
171171 keysAfterDelete := gaugeValue (t , families , "etcd_cache_store_keys_total" )
172- require .Equal (t , keysAfterDelete , 2.0 )
172+ require .InEpsilon (t , 2.0 , keysAfterDelete , 0.01 )
173173}
174174
175175func TestCacheMetricsGetErrors (t * testing.T ) {
@@ -193,7 +193,7 @@ func TestCacheMetricsGetErrors(t *testing.T) {
193193
194194 families := scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
195195 errorCount := counterValue (t , families , "etcd_cache_get_total" , "result" , "error" )
196- require .Equal (t , errorCount , 1.0 , "expected get_total{error} >= 1 after out-of-scope Get" )
196+ require .InEpsilonf (t , 1.0 , errorCount , 0.01 , "expected get_total{error} >= 1 after out-of-scope Get" )
197197}
198198
199199func TestCacheMetricsDefaultPath (t * testing.T ) {
@@ -211,7 +211,7 @@ func TestCacheMetricsDefaultPath(t *testing.T) {
211211 t .Cleanup (c .Close )
212212
213213 families := scrapeHTTPMetrics (t , mux , cache .DefaultMetricsPath )
214- require .Contains (t , families , "etcd_cache_store_keys_total" ,
214+ require .Containsf (t , families , "etcd_cache_store_keys_total" ,
215215 "expected metrics served on default path %s" , cache .DefaultMetricsPath )
216216}
217217
@@ -250,7 +250,7 @@ func gaugeValue(t *testing.T, families map[string]*dto.MetricFamily, name string
250250 t .Helper ()
251251 fam , ok := families [name ]
252252 require .Truef (t , ok , "metric family %q not found" , name )
253- require .NotEmpty (t , fam .GetMetric (), "metric family %q has no samples" , name )
253+ require .NotEmptyf (t , fam .GetMetric (), "metric family %q has no samples" , name )
254254 return fam .GetMetric ()[0 ].GetGauge ().GetValue ()
255255}
256256
0 commit comments