Skip to content

Commit 554cdfd

Browse files
committed
fix tests
1 parent 3a76322 commit 554cdfd

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

tests/bigquery/bigquery_mcp_test.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,46 @@ func invokeMCPToolForTest(t *testing.T, info ToolTestInfo) (string, bool) {
171171
t.Fatalf("native error executing %s: %s", toolName, err)
172172
}
173173

174+
var blocks []string
175+
for _, content := range mcpResp.Result.Content {
176+
if content.Type == "text" {
177+
blocks = append(blocks, strings.TrimSpace(content.Text))
178+
}
179+
}
180+
181+
got := strings.Join(blocks, "")
182+
183+
isActualErr := statusCode != http.StatusOK || (mcpResp != nil && (mcpResp.Result.IsError || mcpResp.Error != nil))
184+
174185
if info.IsErr {
175-
if statusCode != http.StatusOK || mcpResp.Result.IsError {
176-
return "", true
186+
if isActualErr {
187+
// Extract error message for comparison
188+
errMsg := got
189+
if mcpResp != nil && mcpResp.Error != nil {
190+
errMsg = mcpResp.Error.Message
191+
}
192+
if info.Want == "" || strings.Contains(errMsg, info.Want) {
193+
return errMsg, true
194+
}
177195
}
178-
t.Fatal("expected error result but got success")
179-
return "", false
196+
t.Fatalf("expected error result containing %q but got success or non-matching error. Status: %d, Result.IsError: %v, Error: %+v", info.Want, statusCode, mcpResp.Result.IsError, mcpResp.Error)
197+
return got, false
180198
}
181199

182200
if statusCode != http.StatusOK {
183201
t.Fatalf("expected status 200, got %d", statusCode)
184202
}
185203

186-
if mcpResp.Result.IsError {
187-
t.Fatalf("%s returned error result: %v", toolName, mcpResp.Result)
204+
if mcpResp != nil && mcpResp.Result.IsError {
205+
t.Fatalf("%s returned error result: %v. Response: %s", toolName, mcpResp.Result, got)
188206
}
189207

190-
var blocks []string
191-
for _, content := range mcpResp.Result.Content {
192-
if content.Type == "text" {
193-
blocks = append(blocks, strings.TrimSpace(content.Text))
194-
}
208+
result := strings.Join(blocks, ",")
209+
if strings.HasPrefix(info.Want, "[") && !strings.HasPrefix(result, "[") {
210+
result = "[" + result + "]"
195211
}
196212

197-
return strings.Join(blocks, ""), false
213+
return result, false
198214
}
199215

200216
func runBigQueryExecuteSqlToolInvokeTestMCP(t *testing.T, select1Want, invokeParamWant, tableNameParam, ddlWant string) {

0 commit comments

Comments
 (0)