mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-11 23:55:07 -05:00
fix http and serverless spark
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user