Skip to content

Commit a5430f4

Browse files
committed
updated unit test
1 parent c4e94db commit a5430f4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

api/v1alpha1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/nats/deprovisioner_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/kyma-project/nats-manager/pkg/nats/mocks"
1515
"github.com/kyma-project/nats-manager/testutils"
1616
natsgo "github.com/nats-io/nats.go"
17+
ptestutil "github.com/prometheus/client_golang/prometheus/testutil"
1718
"github.com/stretchr/testify/mock"
1819
"github.com/stretchr/testify/require"
1920
"go.uber.org/zap"
@@ -218,6 +219,10 @@ func Test_handleNATSDeletion(t *testing.T) {
218219
testEnv := NewMockedUnitTestEnvironment(t, objs...)
219220
reconciler := testEnv.Reconciler
220221

222+
// set values in metrics, which should be reset by the method.
223+
reconciler.collector.RecordAvailabilityZonesUsedMetric(5)
224+
reconciler.collector.RecordClusterSizeMetric(5)
225+
221226
nats := givenNats.DeepCopy()
222227

223228
// define mocks behaviour
@@ -266,6 +271,15 @@ func Test_handleNATSDeletion(t *testing.T) {
266271
require.True(t, nmapiv1alpha1.ConditionEquals(*gotCondition, *tc.wantCondition))
267272
}
268273

274+
// check that metrics are reset.
275+
gotAZMetric, err := reconciler.collector.GetAvailabilityZonesUsedMetric()
276+
require.NoError(t, err)
277+
require.Equal(t, 0.0, ptestutil.ToFloat64(gotAZMetric))
278+
279+
gotSizeMetric, err := reconciler.collector.GetClusterSizeMetric()
280+
require.NoError(t, err)
281+
require.Equal(t, 0.0, ptestutil.ToFloat64(gotSizeMetric))
282+
269283
// check k8s events
270284
gotEvents := testEnv.GetK8sEvents()
271285
require.Equal(t, tc.wantK8sEvents, gotEvents)

0 commit comments

Comments
 (0)