From 2793abf1e33019e725ba47171436638753d86d50 Mon Sep 17 00:00:00 2001 From: "Marco A." Date: Fri, 6 Mar 2026 19:20:54 +0100 Subject: [PATCH] chore(domain): Assert errors using ErrorIS for instance and organization tests (#11789) # Which Problems Are Solved This is a small refactoring for tests in `backend/v3/domain` package to use `assert.ErrorIs` instead of `assert.Equal` for error assertion. # How the Problems Are Solved - Add custom `Is()` function to `MultipleObjectsUpdatedError` error - Substitute `assert.Equal` with `assert.ErrorIs` in instance and organization tests # Additional Context This was part of #11035 --- backend/v3/api/object/object_test.go | 2 +- backend/v3/domain/errors.go | 5 +++++ backend/v3/domain/instance_delete_test.go | 4 ++-- backend/v3/domain/instance_domain_add_test.go | 4 ++-- backend/v3/domain/instance_domain_list_test.go | 4 ++-- backend/v3/domain/instance_domain_remove_test.go | 4 ++-- backend/v3/domain/instance_get_test.go | 4 ++-- backend/v3/domain/instance_list_test.go | 4 ++-- backend/v3/domain/instance_trusted_domain_list_test.go | 4 ++-- backend/v3/domain/instance_update_test.go | 4 ++-- backend/v3/domain/org_activate_test.go | 4 ++-- backend/v3/domain/org_deactivate_test.go | 4 ++-- backend/v3/domain/org_delete_test.go | 4 ++-- backend/v3/domain/org_list_test.go | 2 +- backend/v3/domain/org_update_test.go | 4 ++-- 15 files changed, 31 insertions(+), 26 deletions(-) diff --git a/backend/v3/api/object/object_test.go b/backend/v3/api/object/object_test.go index 33cadc6c0..fd5e5081f 100644 --- a/backend/v3/api/object/object_test.go +++ b/backend/v3/api/object/object_test.go @@ -70,7 +70,7 @@ func TestTextQueryMethodToTextOperation(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() got, err := TextQueryMethodToTextOperation(tc.queryOperation) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedOperation, got) }) } diff --git a/backend/v3/domain/errors.go b/backend/v3/domain/errors.go index 76c588c54..6d31b51ad 100644 --- a/backend/v3/domain/errors.go +++ b/backend/v3/domain/errors.go @@ -42,6 +42,11 @@ func (err *MultipleObjectsUpdatedError) Error() string { return fmt.Sprintf("Message=expecting %d row(s) updated, got %d", err.Expected, err.Actual) } +func (err *MultipleObjectsUpdatedError) Is(target error) bool { + _, ok := target.(*MultipleObjectsUpdatedError) + return ok +} + type UnexpectedQueryTypeError[T any] struct { assertedType T } diff --git a/backend/v3/domain/instance_delete_test.go b/backend/v3/domain/instance_delete_test.go index 9c924c0e7..fb8e2a6a1 100644 --- a/backend/v3/domain/instance_delete_test.go +++ b/backend/v3/domain/instance_delete_test.go @@ -86,7 +86,7 @@ func TestDeleteInstanceCommand_Validate(t *testing.T) { err := d.Validate(context.Background(), cmdOpts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -397,7 +397,7 @@ func TestDeleteInstanceCommand_Execute(t *testing.T) { err := d.Execute(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedInstanceName, d.InstanceName) assert.ElementsMatch(t, tc.expectedInstanceDomains, d.InstanceDomains) assert.Equal(t, tc.expectsDeleteTime, d.DeleteTime != nil && !d.DeleteTime.IsZero()) diff --git a/backend/v3/domain/instance_domain_add_test.go b/backend/v3/domain/instance_domain_add_test.go index d81e4576d..9643fd6ac 100644 --- a/backend/v3/domain/instance_domain_add_test.go +++ b/backend/v3/domain/instance_domain_add_test.go @@ -184,7 +184,7 @@ func TestAddInstanceDomainCommand_Validate(t *testing.T) { } err := cmd.Validate(ctx, opts) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -310,7 +310,7 @@ func TestAddInstanceDomainCommand_Execute(t *testing.T) { err := cmd.Execute(ctx, opts) // Then - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } diff --git a/backend/v3/domain/instance_domain_list_test.go b/backend/v3/domain/instance_domain_list_test.go index ef0ad1c9f..532b37b63 100644 --- a/backend/v3/domain/instance_domain_list_test.go +++ b/backend/v3/domain/instance_domain_list_test.go @@ -121,7 +121,7 @@ func TestListInstanceDomainsQuery_Validate(t *testing.T) { if tc.expectedError != nil { assert.Error(t, err) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) } else { assert.NoError(t, err) } @@ -261,7 +261,7 @@ func TestListInstanceDomainsQuery_Execute(t *testing.T) { if tc.expectedError != nil { assert.Error(t, err) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) } else { assert.NoError(t, err) assert.Equal(t, tc.expectedDomains, query.Result()) diff --git a/backend/v3/domain/instance_domain_remove_test.go b/backend/v3/domain/instance_domain_remove_test.go index c71a702ef..ac1c027bb 100644 --- a/backend/v3/domain/instance_domain_remove_test.go +++ b/backend/v3/domain/instance_domain_remove_test.go @@ -214,7 +214,7 @@ func TestRemoveInstanceDomainCommand_Validate(t *testing.T) { } err := cmd.Validate(ctx, opts) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -374,7 +374,7 @@ func TestRemoveInstanceDomainCommand_Execute(t *testing.T) { } err := cmd.Execute(ctx, opts) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectsDeleteTime, cmd.DeleteTime != nil && !cmd.DeleteTime.IsZero()) }) } diff --git a/backend/v3/domain/instance_get_test.go b/backend/v3/domain/instance_get_test.go index 84501279a..950250c0e 100644 --- a/backend/v3/domain/instance_get_test.go +++ b/backend/v3/domain/instance_get_test.go @@ -97,7 +97,7 @@ func TestGetInstanceCommand_Validate(t *testing.T) { err := cmd.Validate(tt.ctx, cmdOpts) // Verify - assert.Equal(t, tt.expectedError, err) + assert.ErrorIs(t, err, tt.expectedError) }) } } @@ -232,7 +232,7 @@ func TestGetInstanceCommand_Execute(t *testing.T) { err := g.Execute(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedInstance, g.Result()) }) } diff --git a/backend/v3/domain/instance_list_test.go b/backend/v3/domain/instance_list_test.go index 59bd05be0..7a47413f1 100644 --- a/backend/v3/domain/instance_list_test.go +++ b/backend/v3/domain/instance_list_test.go @@ -261,7 +261,7 @@ func TestListInstancesCommand_Execute(t *testing.T) { err := cmd.Execute(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.ElementsMatch(t, tc.expectedInstances, cmd.Result()) }) @@ -321,7 +321,7 @@ func TestListInstancesCommand_Validate(t *testing.T) { err := l.Validate(context.Background(), cmdOpts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } diff --git a/backend/v3/domain/instance_trusted_domain_list_test.go b/backend/v3/domain/instance_trusted_domain_list_test.go index 9191b01f1..908bcb575 100644 --- a/backend/v3/domain/instance_trusted_domain_list_test.go +++ b/backend/v3/domain/instance_trusted_domain_list_test.go @@ -121,7 +121,7 @@ func TestListInstanceTrustedDomainsQuery_Validate(t *testing.T) { if tc.expectedError != nil { assert.Error(t, err) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) } else { assert.NoError(t, err) } @@ -253,7 +253,7 @@ func TestListInstanceTrustedDomainsQuery_Execute(t *testing.T) { if tc.expectedError != nil { assert.Error(t, err) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) } else { assert.NoError(t, err) assert.Equal(t, tc.expectedDomains, query.Result()) diff --git a/backend/v3/domain/instance_update_test.go b/backend/v3/domain/instance_update_test.go index 64ce0a073..c85d3ec66 100644 --- a/backend/v3/domain/instance_update_test.go +++ b/backend/v3/domain/instance_update_test.go @@ -168,7 +168,7 @@ func TestUpdateInstanceCommand_Validate(t *testing.T) { } err := cmd.Validate(ctx, opts) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedUpdateSkip, cmd.ShouldSkipUpdate) }) } @@ -285,7 +285,7 @@ func TestUpdateInstanceCommand_Execute(t *testing.T) { err := cmd.Execute(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } diff --git a/backend/v3/domain/org_activate_test.go b/backend/v3/domain/org_activate_test.go index 41b8fa3c2..cbca10bce 100644 --- a/backend/v3/domain/org_activate_test.go +++ b/backend/v3/domain/org_activate_test.go @@ -144,7 +144,7 @@ func TestActivateOrgCommand_Validate(t *testing.T) { err := cmd.Validate(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -264,7 +264,7 @@ func TestActivateOrgCommand_Execute(t *testing.T) { err := opts.Invoke(ctx, cmd) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } diff --git a/backend/v3/domain/org_deactivate_test.go b/backend/v3/domain/org_deactivate_test.go index e201c46b2..ddab9e840 100644 --- a/backend/v3/domain/org_deactivate_test.go +++ b/backend/v3/domain/org_deactivate_test.go @@ -124,7 +124,7 @@ func TestDeactivateOrgCommand_Validate(t *testing.T) { err := cmd.Validate(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -228,7 +228,7 @@ func TestDeactivateOrgCommand_Execute(t *testing.T) { err := opts.Invoke(ctx, cmd) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } diff --git a/backend/v3/domain/org_delete_test.go b/backend/v3/domain/org_delete_test.go index 9bdc18d78..2b25e389f 100644 --- a/backend/v3/domain/org_delete_test.go +++ b/backend/v3/domain/org_delete_test.go @@ -196,7 +196,7 @@ func TestDeleteOrgCommand_Validate(t *testing.T) { err := d.Validate(ctx, opts) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } } @@ -396,7 +396,7 @@ func TestDeleteOrgCommand_Execute(t *testing.T) { err := opts.Invoke(ctx, cmd) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedOrgName, cmd.OrganizationName) }) } diff --git a/backend/v3/domain/org_list_test.go b/backend/v3/domain/org_list_test.go index e9a4e1df0..57ab885db 100644 --- a/backend/v3/domain/org_list_test.go +++ b/backend/v3/domain/org_list_test.go @@ -329,7 +329,7 @@ func TestListOrgsCommand_Execute(t *testing.T) { err := opts.Invoke(ctx, cmd) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.ElementsMatch(t, tc.expectedOrganizations, cmd.Result()) }) } diff --git a/backend/v3/domain/org_update_test.go b/backend/v3/domain/org_update_test.go index 321fb3c6b..8446e04f3 100644 --- a/backend/v3/domain/org_update_test.go +++ b/backend/v3/domain/org_update_test.go @@ -281,7 +281,7 @@ func TestUpdateOrgCommand_Execute(t *testing.T) { err := opts.Invoke(ctx, cmd) // Verify - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) assert.Equal(t, tc.expectedOldDomainName, cmd.OldDomainName) assert.Equal(t, tc.expectedDomainVerified, cmd.IsOldDomainVerified) }) @@ -389,7 +389,7 @@ func TestUpdateOrgCommand_Validate(t *testing.T) { } err := cmd.Validate(ctx, opts) - assert.Equal(t, tc.expectedError, err) + assert.ErrorIs(t, err, tc.expectedError) }) } }