@@ -40,6 +40,12 @@ type updateOperationPhaseTestCase struct {
4040 expected operationPhaseExpected
4141}
4242
43+ type updateRebootTestCase struct {
44+ name string
45+ input int
46+ expected float64
47+ }
48+
4349type sabakanInput struct {
4450 isLeader bool
4551 enabled bool
@@ -64,6 +70,7 @@ type updateSabakanIntegrationTestCase struct {
6470func TestMetricsUpdater (t * testing.T ) {
6571 t .Run ("UpdateLeader" , testUpdateLeader )
6672 t .Run ("UpdateOperationPhase" , testUpdateOperationPhase )
73+ t .Run ("UpdateReboot" , testUpdateReboot )
6774 t .Run ("UpdateSabakanIntegration" , testUpdateSabakanIntegration )
6875}
6976
@@ -232,6 +239,62 @@ func testUpdateOperationPhase(t *testing.T) {
232239 }
233240}
234241
242+ func testUpdateReboot (t * testing.T ) {
243+ testCases := []updateRebootTestCase {
244+ {
245+ name : "zero" ,
246+ input : 0 ,
247+ expected : 0 ,
248+ },
249+ {
250+ name : "one" ,
251+ input : 1 ,
252+ expected : 1 ,
253+ },
254+ {
255+ name : "two" ,
256+ input : 2 ,
257+ expected : 2 ,
258+ },
259+ }
260+ for _ , tt := range testCases {
261+ t .Run (tt .name , func (t * testing.T ) {
262+ ctx := context .Background ()
263+ defer ctx .Done ()
264+
265+ collector , _ := newTestCollector ()
266+ handler := GetHandler (collector )
267+
268+ UpdateReboot (tt .input )
269+
270+ w := httptest .NewRecorder ()
271+ req := httptest .NewRequest ("GET" , "/metrics" , nil )
272+ handler .ServeHTTP (w , req )
273+
274+ metricsFamily , err := parseMetrics (w .Result ())
275+ if err != nil {
276+ t .Fatal (err )
277+ }
278+
279+ metricsFound := false
280+ for _ , mf := range metricsFamily {
281+ if * mf .Name != "cke_reboot_queue_entries" {
282+ continue
283+ }
284+ for _ , m := range mf .Metric {
285+ metricsFound = true
286+ if * m .Gauge .Value != tt .expected {
287+ t .Errorf ("value for cke_reboot_queue_entries is wrong. expected: %f, actual: %f" , tt .expected , * m .Gauge .Value )
288+ }
289+ }
290+ }
291+ if ! metricsFound {
292+ t .Errorf ("metrics reboot_queue_entries was not found" )
293+ }
294+ })
295+ }
296+ }
297+
235298func testUpdateSabakanIntegration (t * testing.T ) {
236299 testCases := []updateSabakanIntegrationTestCase {
237300 {
0 commit comments