From ce51f8b22a4933ac41c6b6f25bfadcd8deb6dbd5 Mon Sep 17 00:00:00 2001 From: duwenxin Date: Mon, 9 Feb 2026 12:53:10 -0500 Subject: [PATCH] fix http and serverless spark --- tests/http/http_integration_test.go | 18 ++++++++++++++---- .../serverless_spark_integration_test.go | 18 +++++++++--------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tests/http/http_integration_test.go b/tests/http/http_integration_test.go index ef2cd3b2c7..757ce11445 100644 --- a/tests/http/http_integration_test.go +++ b/tests/http/http_integration_test.go @@ -410,7 +410,7 @@ func runAdvancedHTTPInvokeTest(t *testing.T) { name string api string requestHeader map[string]string - requestBody func() io.Reader // Use a func to avoid reader reuse issues + requestBody func() io.Reader want string isAgentErr bool }{ @@ -466,11 +466,21 @@ func runAdvancedHTTPInvokeTest(t *testing.T) { } if tc.isAgentErr { - // Look for the "error" key - gotErr, ok := body["error"].(string) + resStr, ok := body["result"].(string) if !ok { - t.Fatalf("expected 'error' field in response body, got: %v", body) + t.Fatalf("expected 'result' field as string in response body, got: %v", body) } + + var resMap map[string]any + if err := json.Unmarshal([]byte(resStr), &resMap); err != nil { + t.Fatalf("failed to unmarshal result string: %v", err) + } + + gotErr, ok := resMap["error"].(string) + if !ok { + t.Fatalf("expected 'error' field inside result, got: %v", resMap) + } + if !strings.Contains(gotErr, tc.want) { t.Fatalf("unexpected error message: got %q, want it to contain %q", gotErr, tc.want) } diff --git a/tests/serverlessspark/serverless_spark_integration_test.go b/tests/serverlessspark/serverless_spark_integration_test.go index 5ac8df1b1b..abe8c29f42 100644 --- a/tests/serverlessspark/serverless_spark_integration_test.go +++ b/tests/serverlessspark/serverless_spark_integration_test.go @@ -203,14 +203,14 @@ func TestServerlessSparkToolEndpoints(t *testing.T) { name: "zero page size", toolName: "list-batches", request: map[string]any{"pageSize": 0}, - wantCode: http.StatusBadRequest, + wantCode: http.StatusOK, wantMsg: "pageSize must be positive: 0", }, { name: "negative page size", toolName: "list-batches", request: map[string]any{"pageSize": -1}, - wantCode: http.StatusBadRequest, + wantCode: http.StatusOK, wantMsg: "pageSize must be positive: -1", }, } @@ -250,14 +250,14 @@ func TestServerlessSparkToolEndpoints(t *testing.T) { name: "missing batch", toolName: "get-batch", request: map[string]any{"name": "INVALID_BATCH"}, - wantCode: http.StatusBadRequest, - wantMsg: fmt.Sprintf("Not found: Batch projects/%s/locations/%s/batches/INVALID_BATCH", serverlessSparkProject, serverlessSparkLocation), + wantCode: http.StatusOK, + wantMsg: fmt.Sprintf("error processing GCP request: failed to get batch: rpc error: code = NotFound desc = Not found: Batch projects/%s/locations/%s/batches/INVALID_BATCH", serverlessSparkProject, serverlessSparkLocation), }, { name: "full batch name", toolName: "get-batch", request: map[string]any{"name": missingBatchFullName}, - wantCode: http.StatusBadRequest, + wantCode: http.StatusOK, wantMsg: fmt.Sprintf("name must be a short batch name without '/': %s", missingBatchFullName), }, } @@ -536,14 +536,14 @@ func TestServerlessSparkToolEndpoints(t *testing.T) { name: "nonexistent op", toolName: "cancel-batch", request: map[string]any{"operation": "INVALID_OPERATION"}, - wantCode: http.StatusBadRequest, - wantMsg: "Operation not found", + wantCode: http.StatusOK, + wantMsg: "error processing GCP request: failed to cancel operation: rpc error: code = NotFound desc = Operation not found", }, { name: "full op name", toolName: "cancel-batch", request: map[string]any{"operation": fullOpName}, - wantCode: http.StatusBadRequest, + wantCode: http.StatusOK, wantMsg: fmt.Sprintf("operation must be a short operation name without '/': %s", fullOpName), }, } @@ -556,7 +556,7 @@ func TestServerlessSparkToolEndpoints(t *testing.T) { }) t.Run("auth", func(t *testing.T) { t.Parallel() - runAuthTest(t, "cancel-batch-with-auth", map[string]any{"operation": "INVALID_OPERATION"}, http.StatusBadRequest) + runAuthTest(t, "cancel-batch-with-auth", map[string]any{"operation": "INVALID_OPERATION"}, http.StatusOK) }) }) })