From 5739ff4d55395e67cea75f7e518cf66593bea4df Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Tue, 24 Dec 2024 16:39:11 -0800 Subject: [PATCH] Tech-Debt: Increase coverage - Rewrite with error validation Signed-off-by: Adil Fulara --- .../pkg/clusters/clientdiscovery_handler_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/admiral/pkg/clusters/clientdiscovery_handler_test.go b/admiral/pkg/clusters/clientdiscovery_handler_test.go index 50da312a..44f96722 100644 --- a/admiral/pkg/clusters/clientdiscovery_handler_test.go +++ b/admiral/pkg/clusters/clientdiscovery_handler_test.go @@ -80,7 +80,7 @@ func TestClientDiscoveryHandler_Added(t *testing.T) { disableCache: true, }, want: want{ - err: errors.New("op=Add type=Job name=obj-rollout-namespace cluster=cluster1 error=task=Add name=obj-rollout-namespace namespace=rollout-namespace cluster=cluster1 message=processing skipped as Admiral cache is not initialized for identity=test.identity1"), + err: errors.New("op=Add type=Job name=obj-rollout-namespace cluster=cluster1 error=task=Add name=obj-rollout-namespace namespace=rollout-namespace cluster=cluster1 message=processing skipped as Admiral cache is not initialized for identity=identity1"), }, }, { @@ -235,7 +235,7 @@ func TestClientDiscoveryHandler_Added(t *testing.T) { }, want: want{ depCtrlAddCalled: 1, - err: errors.New("oops"), + err: errors.New("op=Add type=Job name=obj cluster=cluster1 error=op=Process type= name=obj namespace=namespace cluster=cluster1 message=Error processing client discovery"), }, }, } @@ -308,17 +308,16 @@ func TestClientDiscoveryHandler_Added(t *testing.T) { result := h.Added(ctx, c.args.obj) // Then - if c.want.err == nil { + if c.want.err != nil && assert.Error(t, result) { + // error validation + assert.Equal(t, result, c.want.err) + } else { assert.Equal(t, c.want.partitionIdentityCacheLen, rr.AdmiralCache.PartitionIdentityCache.Len()) assert.Equal(t, c.want.identityClusterNSCacheLen, rr.AdmiralCache.IdentityClusterNamespaceCache.Len()) if c.args.rollout != nil { rolloutFromCache := r.Cache.Get(identity1, "stage") assert.NotNil(t, rolloutFromCache) } - } else { - if result == nil { - t.Fatalf("Expected error '%v' got 'nil'", c.want.err) - } } if c.want.depCtrlAddCalled > 0 {