Skip to content

Commit

Permalink
fix: the suggested apis query is missing (#514)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Jul 15, 2024
1 parent 6ce9363 commit 1d5f54f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/runner/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st
},
}

for _, param := range swagger.Parameters {
switch param.In {
case "query":
// TODO should have a better way to provide the initial value
testcase.Request.Query[param.Name] = "todo"
switch testcase.Request.Method {
case http.MethodGet:
for _, param := range swagger.Paths.Paths[api].Get.Parameters {
switch param.In {
case "query":
// TODO should have a better way to provide the initial value
(&(testcase.Request)).Query[param.Name] = "todo"
}
}
}
result = append(result, testcase)
Expand Down
4 changes: 3 additions & 1 deletion pkg/runner/http_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 API Testing Authors.
Copyright 2023-2024 API Testing Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -539,6 +539,7 @@ func TestBodyFiledsVerify(t *testing.T) {

func TestGetSuggestedAPIs(t *testing.T) {
runner := NewSimpleTestCaseRunner()
runner.WithSuite(nil)
// not a swagger
result, err := runner.GetSuggestedAPIs(&atest.TestSuite{}, "")
assert.NoError(t, err, err)
Expand All @@ -557,6 +558,7 @@ func TestGetSuggestedAPIs(t *testing.T) {
assert.NotEmpty(t, result)
method := result[0].Request.Method
assert.Equal(t, strings.ToUpper(method), method)
assert.Equal(t, "todo", result[0].Request.Query["text"])
}

func TestIsStructContent(t *testing.T) {
Expand Down
29 changes: 28 additions & 1 deletion pkg/runner/testdata/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@
},
"post": {
"summary": "summary",
"operationId": "createUser"
"operationId": "createUser",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
},
"/api/v1/users/{user}": {
Expand All @@ -49,5 +58,23 @@
"operationId": "updateUser"
}
}
},
"components": {
"schemas": {
"User": {
"title": "User",
"type": "object",
"properties": {
"username": {
"type": "string",
"description": "username"
},
"age": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}

0 comments on commit 1d5f54f

Please sign in to comment.