...

Source file src/edge-infra.dev/pkg/k8s/runtime/controller/metrics/options_test.go

Documentation: edge-infra.dev/pkg/k8s/runtime/controller/metrics

     1  package metrics
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prometheus/client_golang/prometheus/collectors"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestOptions(t *testing.T) {
    11  	t.Run("Basic", func(t *testing.T) {
    12  		r := NewRecorder("test")
    13  		assert.NotNil(t, r.reconcileConditionGauge)
    14  		assert.Nil(t, r.reconcileConditionGaugeWithReason)
    15  		assert.Equal(t, 2, len(r.collectors))
    16  	})
    17  
    18  	t.Run("WithSuspend", func(t *testing.T) {
    19  		r := NewRecorder("test", WithSuspend())
    20  		assert.NotNil(t, r.suspendGauge)
    21  		assert.Equal(t, 3, len(r.collectors))
    22  	})
    23  
    24  	t.Run("WithCollectors", func(t *testing.T) {
    25  		r := NewRecorder("test", WithCollectors(
    26  			collectors.NewGoCollector(),
    27  			collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
    28  		))
    29  		assert.Equal(t, 4, len(r.collectors),
    30  			"Custom collectors weren't added to Recorder.collectors")
    31  	})
    32  
    33  	t.Run("WithReason", func(t *testing.T) {
    34  		r := NewRecorder("test", WithReason())
    35  		assert.NotNil(t, r.reconcileConditionGaugeWithReason)
    36  		assert.Nil(t, r.reconcileConditionGauge)
    37  		assert.Equal(t, 2, len(r.collectors))
    38  	})
    39  }
    40  

View as plain text