Skip to content

Commit 36ad77c

Browse files
guzalvclaude
andcommitted
Guard err.Error() calls with require.Error to prevent nil-panic
If CreateComplianceScanConfiguration unexpectedly succeeds for a duplicate profile, err is nil and err.Error() panics. Add require.Error before accessing the error message. Partially generated by AI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c35d257 commit 36ad77c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tests/compliance_operator_v2_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ func TestComplianceV2CreateGetScanConfigurations(t *testing.T) {
692692

693693
// Verify that the duplicate profile was not created and the error message is correct.
694694
_, err = scanConfigService.CreateComplianceScanConfiguration(ctx, duplicateProfileReq)
695+
require.Error(t, err, "expected duplicate profile scan config to be rejected")
695696
assert.Contains(t, err.Error(), "already uses profile")
696697

697698
// Also verify that creating with the TP name is rejected (duplicate TP).
@@ -716,6 +717,7 @@ func TestComplianceV2CreateGetScanConfigurations(t *testing.T) {
716717
},
717718
}
718719
_, err = scanConfigService.CreateComplianceScanConfiguration(ctx, duplicateTPReq)
720+
require.Error(t, err, "expected duplicate TP scan config to be rejected")
719721
assert.Contains(t, err.Error(), "already uses profile")
720722

721723
query = &v2.RawQuery{Query: ""}

0 commit comments

Comments
 (0)