Skip to content

Commit

Permalink
Tech-Debt: Increase coverage
Browse files Browse the repository at this point in the history
- Rewrite with error validation

Signed-off-by: Adil Fulara <[email protected]>
  • Loading branch information
Adil Fulara committed Dec 25, 2024
1 parent 786e3dc commit 5739ff4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions admiral/pkg/clusters/clientdiscovery_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
{
Expand Down Expand Up @@ -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"),
},
},
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5739ff4

Please sign in to comment.