Skip to content

Commit

Permalink
updated unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mfaizanse committed Apr 24, 2024
1 parent c4e94db commit a5430f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions internal/controller/nats/deprovisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/kyma-project/nats-manager/pkg/nats/mocks"
"github.com/kyma-project/nats-manager/testutils"
natsgo "github.com/nats-io/nats.go"
ptestutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down Expand Up @@ -218,6 +219,10 @@ func Test_handleNATSDeletion(t *testing.T) {
testEnv := NewMockedUnitTestEnvironment(t, objs...)
reconciler := testEnv.Reconciler

// set values in metrics, which should be reset by the method.
reconciler.collector.RecordAvailabilityZonesUsedMetric(5)
reconciler.collector.RecordClusterSizeMetric(5)

nats := givenNats.DeepCopy()

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

// check that metrics are reset.
gotAZMetric, err := reconciler.collector.GetAvailabilityZonesUsedMetric()
require.NoError(t, err)
require.Equal(t, 0.0, ptestutil.ToFloat64(gotAZMetric))

gotSizeMetric, err := reconciler.collector.GetClusterSizeMetric()
require.NoError(t, err)
require.Equal(t, 0.0, ptestutil.ToFloat64(gotSizeMetric))

// check k8s events
gotEvents := testEnv.GetK8sEvents()
require.Equal(t, tc.wantK8sEvents, gotEvents)
Expand Down

0 comments on commit a5430f4

Please sign in to comment.