Skip to content

Commit a8b8d38

Browse files
authored
Fix staticcheck SA5011 nil pointer dereference in retriever test (#2050)
Combine two separate nil checks into a single condition to eliminate staticcheck SA5011 warnings about possible nil pointer dereference. The previous code had two sequential checks: 1. if testGroupName == "" { t.Skip(...) } 2. if group == nil { t.Skip(...) } Staticcheck couldn't determine that t.Skip() exits the test, so it flagged the later dereference of group.Servers as potentially unsafe. By combining these into a single condition (testGroupName == "" || group == nil), the linter can clearly see that group cannot be nil when execution continues past the check. This maintains the same test behavior while satisfying the linter. Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
1 parent be1e1a5 commit a8b8d38

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

pkg/runner/retriever/retriever_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@ func TestGetMCPServer_WithGroup(t *testing.T) {
3333
}
3434
}
3535

36-
if testGroupName == "" {
36+
if testGroupName == "" || group == nil {
3737
t.Skip("No groups found in registry, skipping group tests")
3838
}
39-
if group == nil {
40-
t.Skip("Test group is nil, skipping")
41-
}
4239

4340
// Find a server in the group to test with
4441
var testServerName string

0 commit comments

Comments
 (0)