Skip to content

Commit 8e871ba

Browse files
Copilotlpcox
andauthored
test: improve testify assertion specificity in targeted tests
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/b3e143bf-9353-45dd-8d9b-80cebf30c68e Co-authored-by: lpcox <[email protected]>
1 parent 9ede77f commit 8e871ba

11 files changed

Lines changed: 15 additions & 20 deletions

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ port 3000
10891089
errMsg := err.Error()
10901090
assert.Contains(t, errMsg, "line", "Error should mention line number")
10911091
// Our improved format includes "column" explicitly when ParseError is detected
1092-
assert.True(t, strings.Contains(errMsg, "column") || strings.Contains(errMsg, "line 2"),
1092+
assert.Regexp(t, `column|line 2`, errMsg,
10931093
"Error should mention column or line position, got: %s", errMsg)
10941094
}
10951095

internal/config/expand_raw_json_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"strings"
54
"testing"
65

76
"github.com/stretchr/testify/assert"
@@ -566,7 +565,7 @@ func TestValidateMounts(t *testing.T) {
566565
if tt.shouldErr {
567566
require.Error(t, err, "Expected an error but got none")
568567
if tt.errMsg != "" {
569-
assert.True(t, strings.Contains(err.Error(), tt.errMsg),
568+
assert.Contains(t, err.Error(), tt.errMsg,
570569
"Error message %q should contain %q", err.Error(), tt.errMsg)
571570
}
572571
} else {

internal/config/fetch_and_fix_schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func TestFixSchemaBytes_AddRegistryAndGuardPoliciesToStdioConfig(t *testing.T) {
245245
require.True(t, hasGuardPolicies, "guard-policies field should be added to stdioServerConfig.properties")
246246
gpMap := guardPolicies.(map[string]interface{})
247247
assert.Equal(t, "object", gpMap["type"], "guard-policies.type should be 'object'")
248-
assert.Equal(t, true, gpMap["additionalProperties"], "guard-policies.additionalProperties should be true")
248+
assert.True(t, gpMap["additionalProperties"].(bool), "guard-policies.additionalProperties should be true")
249249
}
250250

251251
// TestFixSchemaBytes_AddRegistryAndGuardPoliciesToHttpConfig covers the injection

internal/difc/labels_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package difc
22

33
import (
4-
"strings"
54
"testing"
65

76
"github.com/stretchr/testify/assert"
@@ -590,11 +589,11 @@ func TestViolationError_Error(t *testing.T) {
590589
msg := tt.err.Error()
591590
assert.NotEmpty(t, msg)
592591
for _, want := range tt.wantContains {
593-
assert.True(t, strings.Contains(msg, want),
592+
assert.Contains(t, msg, want,
594593
"expected %q in error message %q", want, msg)
595594
}
596595
for _, absent := range tt.wantAbsent {
597-
assert.False(t, strings.Contains(msg, absent),
596+
assert.NotContains(t, msg, absent,
598597
"expected %q NOT to be in error message %q", absent, msg)
599598
}
600599
})
@@ -616,7 +615,7 @@ func TestViolationError_Detailed(t *testing.T) {
616615
base := err.Error()
617616

618617
// Detailed should contain the base error message
619-
assert.True(t, strings.Contains(detailed, base), "detailed should include base error")
618+
assert.Contains(t, detailed, base, "detailed should include base error")
620619

621620
// Detailed should include agent and resource tag context
622621
assert.Contains(t, detailed, "Agent")

internal/mcp/tool_result_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func TestParseToolArguments(t *testing.T) {
268268
require.NotNil(t, args)
269269
assert.Equal(t, "search term", args["query"])
270270
assert.Equal(t, float64(10), args["limit"])
271-
assert.Equal(t, true, args["active"])
271+
assert.True(t, args["active"].(bool))
272272
})
273273

274274
t.Run("nested object arguments are parsed correctly", func(t *testing.T) {

internal/mcp/unmarshal_params_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestUnmarshalParams(t *testing.T) {
153153
// JSON unmarshal converts numbers to float64 by default
154154
assert.Equal(t, float64(42), target["int_val"])
155155
assert.Equal(t, 3.14, target["float_val"])
156-
assert.Equal(t, true, target["bool_val"])
156+
assert.True(t, target["bool_val"].(bool))
157157
assert.Len(t, target["array_val"], 3)
158158
assert.NotNil(t, target["object_val"])
159159
assert.Nil(t, target["null_val"])

internal/middleware/jqschema_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func TestMiddlewareWithLargePayload(t *testing.T) {
195195
// Verify preview truncation in Content field (preview ends with ... when truncated)
196196
previewInContent := contentMap["payloadPreview"].(string)
197197
if strings.HasSuffix(previewInContent, "...") {
198-
assert.True(t, len(previewInContent) <= 503, "Preview in Content should be truncated")
198+
assert.LessOrEqual(t, len(previewInContent), 503, "Preview in Content should be truncated")
199199
}
200200

201201
// Also check data return value
@@ -204,7 +204,7 @@ func TestMiddlewareWithLargePayload(t *testing.T) {
204204
// Verify preview truncation (check if it ends with ...)
205205
preview := dataMap["payloadPreview"].(string)
206206
if strings.HasSuffix(preview, "...") {
207-
assert.True(t, len(preview) <= 503, "Preview should be truncated")
207+
assert.LessOrEqual(t, len(preview), 503, "Preview should be truncated")
208208
}
209209

210210
// Verify payload file has complete data

internal/proxy/proxy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ func TestRewrapSearchResponse(t *testing.T) {
682682
result := rewrapSearchResponse(original, filtered)
683683
m := result.(map[string]interface{})
684684
assert.Equal(t, float64(2), m["total_count"])
685-
assert.Equal(t, false, m["incomplete_results"])
685+
assert.False(t, m["incomplete_results"].(bool))
686686
assert.Len(t, m["items"].([]interface{}), 2)
687687
})
688688

internal/proxy/rest_backend_caller_tool_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net/http"
88
"net/http/httptest"
9-
"strings"
109
"testing"
1110

1211
"github.com/stretchr/testify/assert"
@@ -574,5 +573,5 @@ func TestRestBackendCaller_IssueRead_ResponseFormat(t *testing.T) {
574573

575574
text, ok := content[0]["text"].(string)
576575
require.True(t, ok)
577-
assert.True(t, strings.Contains(text, "Bug report"), "response text should contain the issue title")
576+
assert.Contains(t, text, "Bug report", "response text should contain the issue title")
578577
}

internal/server/call_backend_tool_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"net/http"
77
"net/http/httptest"
8-
"strings"
98
"testing"
109
"time"
1110

@@ -482,8 +481,8 @@ func TestCallBackendTool_AllowedToolsError_MessageFormat(t *testing.T) {
482481
require.True(result.IsError)
483482
require.Len(result.Content, 1)
484483
text := result.Content[0].(*sdk.TextContent).Text
485-
assert.True(t, strings.Contains(text, `"blocked"`), "error message should include tool name: %s", text)
486-
assert.True(t, strings.Contains(text, "allowed-tools"), "error message should mention allowed-tools: %s", text)
484+
assert.Contains(t, text, `"blocked"`, "error message should include tool name: %s", text)
485+
assert.Contains(t, text, "allowed-tools", "error message should mention allowed-tools: %s", text)
487486
}
488487

489488
// TestCallBackendTool_ToolTimeoutEnforcedViaContext verifies that the configured

0 commit comments

Comments
 (0)