From a5430f49b5fdc2024bff6730c7be64dd59c20056 Mon Sep 17 00:00:00 2001 From: Muhammad Faizan Date: Wed, 24 Apr 2024 12:01:17 +0200 Subject: [PATCH] updated unit test --- api/v1alpha1/zz_generated.deepcopy.go | 2 +- internal/controller/nats/deprovisioner_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index a1a88095..e5a8d0ba 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -21,7 +21,7 @@ limitations under the License. package v1alpha1 import ( - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) diff --git a/internal/controller/nats/deprovisioner_test.go b/internal/controller/nats/deprovisioner_test.go index 343d8945..5f1b0eb3 100644 --- a/internal/controller/nats/deprovisioner_test.go +++ b/internal/controller/nats/deprovisioner_test.go @@ -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" @@ -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 @@ -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)