fix: the suggested apis query is missing (#514)

Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
Rick 2024-07-15 17:54:47 +08:00 committed by GitHub
parent 6ce9363d5a
commit 1d5f54f0b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 7 deletions

View File

@ -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)

View File

@ -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.
@ -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)
@ -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) {

View File

@ -32,7 +32,16 @@
},
"post": {
"summary": "summary",
"operationId": "createUser"
"operationId": "createUser",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
},
"/api/v1/users/{user}": {
@ -49,5 +58,23 @@
"operationId": "updateUser"
}
}
},
"components": {
"schemas": {
"User": {
"title": "User",
"type": "object",
"properties": {
"username": {
"type": "string",
"description": "username"
},
"age": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}