Skip to content

Commit 6e0c70e

Browse files
authored
feat: support session scope store (#517)
* chore: stop using the image from docker hub * feat: support session scope store * support to set the suggested api cout limit * add more unit tests --------- Co-authored-by: rick <[email protected]>
1 parent 62383ba commit 6e0c70e

File tree

16 files changed

+223
-41
lines changed

16 files changed

+223
-41
lines changed

console/atest-ui/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ API.GetVersion((d) => {
4646
})
4747
4848
const sideWidth = ref("width: 200px; display: flex;flex-direction: column;")
49-
const isCollapse = ref(false)
49+
const isCollapse = ref(true)
5050
watch(isCollapse, (e) => {
5151
if (e) {
5252
sideWidth.value = "width: 80px; display: flex;flex-direction: column;"

console/atest-ui/src/views/TestCase.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ function formChange() {
437437
}
438438
}
439439
440-
const bodyType = ref(5)
440+
const bodyType = ref(1)
441441
function bodyTypeChange(e: number) {
442442
let contentType = ""
443443
switch (e) {

e2e/compose.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ services:
3333
# - minio
3434
- postgres
3535
etcd:
36-
image: "bitnami/etcd:3.5.10"
36+
image: "ghcr.io/linuxsuren/bitnami/etcd:3.5.10"
3737
expose:
3838
- "2379"
3939
environment:
@@ -45,7 +45,7 @@ services:
4545
retries: 10
4646
start_period: 3s
4747
mysql:
48-
image: mysql:8.2.0
48+
image: ghcr.io/linuxsuren/library/mysql:8.2.0
4949
command: --default-authentication-plugin=mysql_native_password
5050
environment:
5151
MYSQL_ROOT_PASSWORD: root
@@ -57,7 +57,7 @@ services:
5757
retries: 10
5858
start_period: 3s
5959
mariadb:
60-
image: mariadb:11.0
60+
image: ghcr.io/linuxsuren/library/mariadb:11.0
6161
environment:
6262
MARIADB_ROOT_PASSWORD: root
6363
MARIADB_DATABASE: atest
@@ -68,14 +68,14 @@ services:
6868
retries: 10
6969
start_period: 3s
7070
minio:
71-
image: bitnami/minio:2023.11.6
71+
image: ghcr.io/linuxsuren/bitnami/minio:2023.11.6
7272
environment:
7373
MINIO_ROOT_USER: root
7474
MINIO_ROOT_PASSWORD: root
7575
MINIO_SERVER_HOST: minio
7676
MINIO_DEFAULT_BUCKETS: bucket
7777
mongo:
78-
image: mongo
78+
image: ghcr.io/linuxsuren/library/mongo:7.0.12
7979
healthcheck:
8080
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/27017"]
8181
interval: 3s
@@ -86,7 +86,7 @@ services:
8686
MONGO_INITDB_ROOT_USERNAME: root
8787
MONGO_INITDB_ROOT_PASSWORD: root
8888
postgres:
89-
image: postgres:16.0
89+
image: ghcr.io/linuxsuren/library/postgres:16.0
9090
environment:
9191
POSTGRES_USER: root
9292
POSTGRES_PASSWORD: root

pkg/runner/http.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ func (r ReportResultSlice) Swap(i, j int) {
7272

7373
type simpleTestCaseRunner struct {
7474
UnimplementedRunner
75-
simpleResponse SimpleResponse
76-
cookies []*http.Cookie
75+
simpleResponse SimpleResponse
76+
cookies []*http.Cookie
77+
apiSuggestLimit int
7778
}
7879

7980
// NewSimpleTestCaseRunner creates the instance of the simple test case runner
@@ -82,6 +83,7 @@ func NewSimpleTestCaseRunner() TestCaseRunner {
8283
UnimplementedRunner: NewDefaultUnimplementedRunner(),
8384
simpleResponse: SimpleResponse{},
8485
cookies: []*http.Cookie{},
86+
apiSuggestLimit: 10,
8587
}
8688
return runner
8789
}
@@ -234,7 +236,6 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st
234236

235237
var swagger *spec.Swagger
236238
if swagger, err = apispec.ParseURLToSwagger(suite.Spec.URL); err == nil && swagger != nil {
237-
result = []*testing.TestCase{}
238239
swaggerAPI := apispec.NewSwaggerAPI(swagger)
239240
for api, methods := range swaggerAPI.ApiMap {
240241
for _, method := range methods {
@@ -267,6 +268,9 @@ func (r *simpleTestCaseRunner) GetSuggestedAPIs(suite *testing.TestSuite, api st
267268
testcase.Name = swagger.Paths.Paths[api].Patch.ID
268269
}
269270
result = append(result, testcase)
271+
if len(result) >= r.apiSuggestLimit {
272+
return
273+
}
270274
}
271275
}
272276
}
@@ -303,8 +307,9 @@ func (r *simpleTestCaseRunner) withResponseRecord(resp *http.Response) (response
303307
func (r *simpleTestCaseRunner) GetResponseRecord() SimpleResponse {
304308
return r.simpleResponse
305309
}
306-
func (s *simpleTestCaseRunner) WithSuite(suite *testing.TestSuite) {
307-
// not need this parameter
310+
311+
func (r *simpleTestCaseRunner) WithAPISuggestLimit(limit int) {
312+
r.apiSuggestLimit = limit
308313
}
309314

310315
func expectInt(name string, expect, actual int) (err error) {

pkg/runner/http_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ func TestBodyFiledsVerify(t *testing.T) {
541541
func TestGetSuggestedAPIs(t *testing.T) {
542542
runner := NewSimpleTestCaseRunner()
543543
runner.WithSuite(nil)
544+
runner.WithAPISuggestLimit(6)
544545
// not a swagger
545546
result, err := runner.GetSuggestedAPIs(&atest.TestSuite{}, "")
546547
assert.NoError(t, err, err)

pkg/runner/runner.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type TestCaseRunner interface {
3535
WithTestReporter(TestReporter)
3636
WithExecer(fakeruntime.Execer)
3737
WithSuite(*testing.TestSuite)
38+
WithAPISuggestLimit(int)
3839
}
3940

4041
// HTTPResponseRecord represents a http response record
@@ -107,3 +108,11 @@ func (r *UnimplementedRunner) GetSuggestedAPIs(suite *testing.TestSuite, api str
107108
// empty implement
108109
return
109110
}
111+
112+
func (r *UnimplementedRunner) WithAPISuggestLimit(int) {
113+
// empty implement
114+
}
115+
116+
func (s *UnimplementedRunner) WithSuite(suite *testing.TestSuite) {
117+
// empty implement
118+
}

pkg/runner/runner_test.go

Lines changed: 18 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.
@@ -30,3 +30,20 @@ func TestRunnerFactory(t *testing.T) {
3030
runner = GetTestSuiteRunner(&atest.TestSuite{Spec: atest.APISpec{Kind: "grpc", RPC: &atest.RPCDesc{}}})
3131
assert.IsType(t, NewGRPCTestCaseRunner("", atest.RPCDesc{}), runner)
3232
}
33+
34+
func TestUnimplementedRunner(t *testing.T) {
35+
runner := NewDefaultUnimplementedRunner()
36+
output, err := runner.RunTestCase(&atest.TestCase{}, nil, nil)
37+
assert.Nil(t, output)
38+
assert.Error(t, err)
39+
40+
runner.WithWriteLevel("debug")
41+
runner.WithTestReporter(nil)
42+
43+
var results []*atest.TestCase
44+
results, err = runner.GetSuggestedAPIs(nil, "")
45+
assert.Nil(t, results)
46+
assert.NoError(t, err)
47+
48+
runner.WithAPISuggestLimit(0)
49+
}

pkg/runner/testdata/swagger.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
"summary": "summary",
6262
"operationId": "patchUser"
6363
}
64+
},
65+
"/api/v1/groups/{group}": {
66+
"get": {
67+
"summary": "summary",
68+
"operationId": "getGroup"
69+
}
6470
}
6571
},
6672
"components": {

pkg/server/remote_runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func (s *remoteRunnerAdapter) WithExecer(fakeruntime.Execer) {
6666
func (s *remoteRunnerAdapter) WithSuite(suite *testing.TestSuite) {
6767
s.suite = suite
6868
}
69+
func (s *remoteRunnerAdapter) WithAPISuggestLimit(limit int) {
70+
}
6971

7072
func init() {
7173
env := os.Environ()

pkg/server/remote_server_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,20 @@ func TestFakeSecretServer(t *testing.T) {
919919
assert.Error(t, err)
920920
}
921921

922+
func TestRemoteRunnerAdapter(t *testing.T) {
923+
runner := &remoteRunnerAdapter{}
924+
runner.GetSuggestedAPIs(nil, "")
925+
runner.WithSecure(nil)
926+
runner.WithOutputWriter(nil)
927+
runner.WithWriteLevel("debug")
928+
runner.WithTestReporter(nil)
929+
runner.WithExecer(nil)
930+
runner.WithSuite(nil)
931+
runner.WithAPISuggestLimit(0)
932+
_, err := runner.RunTestCase(nil, nil, nil)
933+
assert.Error(t, err)
934+
}
935+
922936
func getRemoteServerInTempDir() (server RunnerServer, call func()) {
923937
dir, _ := os.MkdirTemp(os.TempDir(), "remote-server-test")
924938
call = func() { os.RemoveAll(dir) }

0 commit comments

Comments
 (0)