Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023-2024 API Testing Authors.
Copyright 2023-2025 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
2 changes: 2 additions & 0 deletions e2e/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ kind=orm target=greptimedb:4002 driver=greptime dbname=public atest run -p testi
kind=orm target=tdengine:6041 driver=tdengine password=taosdata dbname=information_schema atest run -p testing-data-query.yaml
kind=orm target=postgres driver=postgres atest run -p testing-data-query.yaml

kind=orm target=mysql driver=mysql atest run -p testing-data-query-mysql.yaml

cat /root/.config/atest/stores.yaml
3 changes: 2 additions & 1 deletion e2e/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fi

docker compose version
docker compose -f "$file" down
docker compose -f "$file" up --build testing --exit-code-from testing --remove-orphans
docker compose -f "$file" build extension
docker compose -f "$file" up --exit-code-from testing --remove-orphans
75 changes: 75 additions & 0 deletions e2e/testing-data-query-mysql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!api-testing
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
name: atest
api: |
{{default "http://localhost:8080" (env "SERVER")}}/api/v1
param:
store: "{{randAlpha 3}}"
server: |
{{default "http://localhost:8080" (env "SERVER")}}
items:
- name: CreateStore
before:
items:
- httpReady("{{.param.server}}/healthz", 2400)
request:
api: /stores
method: POST
body: |
{
"name": "{{.param.store}}",
"url": "{{env "target"}}",
"username": "{{default "root" (env "username")}}",
"password": "{{default "root" (env "password")}}",
"kind": {
"name": "atest-store-{{env "kind"}}"
},
"properties": [{
"key": "driver",
"value": "{{default "mysql" (env "driver")}}"
}, {
"key": "database",
"value": "{{default "atest" (env "dbname")}}"
}, {
"key": "bucket",
"value": "bucket"
}, {
"key": "region",
"value": "cn"
}, {
"key": "disablessl",
"value": "true"
}, {
"key": "targetPath",
"value": "api-testing"
}]
}
- name: query
before:
items:
- sleep(3)
request:
api: /data/query
method: POST
header:
X-Store-Name: "{{.param.store}}"
body: |
{
"sql": "",
"key": ""
}
- name: invalid-sql
request:
api: /data/query
method: POST
header:
X-Store-Name: "{{.param.store}}"
body: |
{
"sql": "selec * from user where id <> 1",
"key": ""
}
expect:
statusCode: 500
bodyFieldsExpect:
code: 2
29 changes: 10 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
/*
*
MIT License
Copyright 2023 API Testing Authors.

Copyright (c) 2023 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.
You may obtain a copy of the License at

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
http://www.apache.org/licenses/LICENSE-2.0

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main
Expand Down
20 changes: 13 additions & 7 deletions pkg/data_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result *
go func() {
defer wg.Done()
// query database and tables
if result.Meta.Databases, err = dbQuery.GetDatabases(ctx); err != nil {
log.Printf("failed to query databases: %v\n", err)
var innerErr error
if result.Meta.Databases, innerErr = dbQuery.GetDatabases(ctx); innerErr != nil {
log.Printf("failed to query databases: %v\n", innerErr)
}
}()

wg.Add(1)
go func() {
defer wg.Done()
if result.Meta.CurrentDatabase = query.Key; query.Key == "" {
if result.Meta.CurrentDatabase, err = dbQuery.GetCurrentDatabase(); err != nil {
log.Printf("failed to query current database: %v\n", err)
var queryDBErr error
if result.Meta.CurrentDatabase, queryDBErr = dbQuery.GetCurrentDatabase(); queryDBErr != nil {
log.Printf("failed to query current database: %v\n", queryDBErr)
}
}

if result.Meta.Tables, err = dbQuery.GetTables(ctx, result.Meta.CurrentDatabase); err != nil {
log.Printf("failed to query tables: %v\n", err)
var queryTableErr error
if result.Meta.Tables, queryTableErr = dbQuery.GetTables(ctx, result.Meta.CurrentDatabase); err != nil {
log.Printf("failed to query tables: %v\n", queryTableErr)
}
}()

Expand Down Expand Up @@ -97,6 +100,8 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result *

wg.Wait()
result.Meta.Labels = append(result.Meta.Labels, dataResult.Meta.Labels...)
} else {
wg.Wait()
}
return
}
Expand Down Expand Up @@ -140,7 +145,8 @@ func sqlQuery(ctx context.Context, sqlText string, db *gorm.DB) (result *server.
}
}

columns, err := rows.Columns()
var columns []string
columns, err = rows.Columns()
if err != nil {
return
}
Expand Down
Loading