Skip to content

Commit 1d5f54f

Browse files
authored
fix: the suggested apis query is missing (#514)
Co-authored-by: rick <[email protected]>
1 parent 6ce9363 commit 1d5f54f

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

pkg/runner/http.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,14 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st
247247
},
248248
}
249249

250-
for _, param := range swagger.Parameters {
251-
switch param.In {
252-
case "query":
253-
// TODO should have a better way to provide the initial value
254-
testcase.Request.Query[param.Name] = "todo"
250+
switch testcase.Request.Method {
251+
case http.MethodGet:
252+
for _, param := range swagger.Paths.Paths[api].Get.Parameters {
253+
switch param.In {
254+
case "query":
255+
// TODO should have a better way to provide the initial value
256+
(&(testcase.Request)).Query[param.Name] = "todo"
257+
}
255258
}
256259
}
257260
result = append(result, testcase)

pkg/runner/http_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 API Testing Authors.
2+
Copyright 2023-2024 API Testing Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -539,6 +539,7 @@ func TestBodyFiledsVerify(t *testing.T) {
539539

540540
func TestGetSuggestedAPIs(t *testing.T) {
541541
runner := NewSimpleTestCaseRunner()
542+
runner.WithSuite(nil)
542543
// not a swagger
543544
result, err := runner.GetSuggestedAPIs(&atest.TestSuite{}, "")
544545
assert.NoError(t, err, err)
@@ -557,6 +558,7 @@ func TestGetSuggestedAPIs(t *testing.T) {
557558
assert.NotEmpty(t, result)
558559
method := result[0].Request.Method
559560
assert.Equal(t, strings.ToUpper(method), method)
561+
assert.Equal(t, "todo", result[0].Request.Query["text"])
560562
}
561563

562564
func TestIsStructContent(t *testing.T) {

pkg/runner/testdata/swagger.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@
3232
},
3333
"post": {
3434
"summary": "summary",
35-
"operationId": "createUser"
35+
"operationId": "createUser",
36+
"requestBody": {
37+
"content": {
38+
"application/json": {
39+
"schema": {
40+
"$ref": "#/components/schemas/User"
41+
}
42+
}
43+
}
44+
}
3645
}
3746
},
3847
"/api/v1/users/{user}": {
@@ -49,5 +58,23 @@
4958
"operationId": "updateUser"
5059
}
5160
}
61+
},
62+
"components": {
63+
"schemas": {
64+
"User": {
65+
"title": "User",
66+
"type": "object",
67+
"properties": {
68+
"username": {
69+
"type": "string",
70+
"description": "username"
71+
},
72+
"age": {
73+
"type": "integer",
74+
"format": "int32"
75+
}
76+
}
77+
}
78+
}
5279
}
5380
}

0 commit comments

Comments
 (0)