Skip to content

Commit 8d81f35

Browse files
committed
test: add the e2e test leverage on docker-compose
1 parent a72ebc5 commit 8d81f35

File tree

6 files changed

+375
-0
lines changed

6 files changed

+375
-0
lines changed

.github/workflows/e2e-testing.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: E2E Testing
19+
on:
20+
- pull_request
21+
22+
jobs:
23+
e2e-test:
24+
name: Run E2E Test
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
- name: Test
30+
run: |
31+
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
32+
sudo chmod u+x /usr/local/bin/docker-compose
33+
make test-e2e

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ generate:
2828
@$(GO) generate ./...
2929
@$(GO) mod tidy
3030

31+
image:
32+
@$(DOCKER_CMD) build . -t answerdev/answer:latest
33+
3134
test:
3235
@$(GO) test ./internal/repo/repo_test
36+
test-e2e: image
37+
cd e2e && ./start.sh
3338

3439
# clean all build result
3540
clean:

e2e/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
FROM docker.io/linuxsuren/api-testing:v0.0.14
19+
20+
WORKDIR /workspace
21+
COPY testsuite.yaml .
22+
23+
CMD [ "atest", "run", "-p", "testsuite.yaml"]

e2e/compose.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
version: "3.9"
19+
20+
services:
21+
testing:
22+
build: .
23+
depends_on:
24+
answer:
25+
condition: service_healthy
26+
27+
answer:
28+
image: "answerdev/answer:latest" # this is should be a local image, do not need to change it
29+
environment:
30+
- AUTO_INSTALL=true
31+
- DB_TYPE=mysql
32+
- DB_USERNAME=root
33+
- DB_PASSWORD=password
34+
- DB_HOST=mysql:3306
35+
- DB_NAME=answer
36+
- LANGUAGE=en_US
37+
- SITE_NAME=answer-test
38+
- SITE_URL=http://localhost
39+
- CONTACT_EMAIL=test@answer.com
40+
- ADMIN_NAME=admin123
41+
- ADMIN_PASSWORD=admin123
42+
- ADMIN_EMAIL=admin123@admin.com
43+
volumes:
44+
- answer-data:/data
45+
healthcheck:
46+
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/80"]
47+
interval: 3s
48+
timeout: 30s
49+
retries: 10
50+
start_period: 3s
51+
ports:
52+
- 8080:80
53+
depends_on:
54+
mysql:
55+
condition: service_healthy
56+
links:
57+
- mysql
58+
deploy:
59+
resources:
60+
limits:
61+
memory: 4000M
62+
63+
mysql:
64+
image: mysql:8.2.0
65+
environment:
66+
- MYSQL_DATABASE=answer
67+
- MYSQL_ROOT_PASSWORD=password
68+
- MYSQL_USER=mysql
69+
- MYSQL_PASSWORD=mysql
70+
healthcheck:
71+
test: [ "CMD", "mysqladmin" ,"ping", "-uroot", "-ppassword" ]
72+
timeout: 20s
73+
retries: 10
74+
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--skip-character-set-client-handshake']
75+
volumes:
76+
- sql_data:/var/lib/mysql
77+
deploy:
78+
resources:
79+
limits:
80+
memory: 500M
81+
82+
volumes:
83+
answer-data:
84+
sql_data:

e2e/start.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
file=$1
20+
if [ "$file" == "" ]
21+
then
22+
file=compose.yaml
23+
fi
24+
25+
docker-compose version
26+
docker-compose -f "$file" up --build -d
27+
28+
while true
29+
do
30+
docker-compose -f "$file" ps | grep testing
31+
if [ $? -eq 1 ]
32+
then
33+
code=-1
34+
docker-compose -f "$file" logs | grep e2e-testing
35+
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
36+
if [ $? -eq 1 ]
37+
then
38+
code=0
39+
echo "successed"
40+
fi
41+
42+
docker-compose -f "$file" down
43+
set -e
44+
exit $code
45+
fi
46+
sleep 1
47+
done

e2e/testsuite.yaml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: answer
19+
api: |
20+
{{default "http://answer" (env "SERVER")}}/answer/api/v1
21+
param:
22+
email: |
23+
{{default "admin123@admin.com" (env "EMAIL")}}
24+
pass: |
25+
{{default "admin123" (env "PASSWD")}}
26+
items:
27+
- name: login
28+
request:
29+
api: /user/login/email
30+
body: |-
31+
{
32+
"e_mail": "{{.param.email}}",
33+
"pass": "{{.param.pass}}"
34+
}
35+
header:
36+
Content-Type: application/json
37+
method: POST
38+
- name: status
39+
request:
40+
api: /notification/status
41+
header:
42+
Authorization: "{{.login.data.access_token}}"
43+
Content-Type: application/json
44+
method: GET
45+
- name: question
46+
request:
47+
api: /question
48+
body: |
49+
{
50+
"title": "{{randomKubernetesName}}",
51+
"content": "good-body",
52+
"tags": [
53+
{
54+
"slug_name": "test",
55+
"display_name": "test",
56+
"original_text": "",
57+
"parsed_text": ""
58+
}
59+
]
60+
}
61+
header:
62+
Authorization: '{{.login.data.access_token}}'
63+
Content-Type: application/json
64+
method: POST
65+
- name: questionList
66+
request:
67+
api: /question/page
68+
header:
69+
Authorization: '{{.login.data.access_token}}'
70+
- name: answer
71+
request:
72+
api: /answer
73+
body: |
74+
{
75+
"question_id": "{{(index .questionList.data.list 0).id}}",
76+
"content": "{{randomKubernetesName}}",
77+
"html": "<p>{{randomKubernetesName}}</p>\n"
78+
}
79+
header:
80+
Authorization: '{{.login.data.access_token}}'
81+
Content-Type: application/json
82+
method: POST
83+
- before:
84+
items:
85+
- sleep("1s")
86+
expect: {}
87+
name: acceptance
88+
request:
89+
api: /answer/acceptance
90+
body: |
91+
{
92+
"question_id": "{{.question.data.id}}",
93+
"answer_id": "{{.answer.data.info.id}}"
94+
}
95+
header:
96+
Authorization: '{{.login.data.access_token}}'
97+
Content-Type: application/json
98+
method: POST
99+
- expect: {}
100+
name: delAnswer
101+
request:
102+
api: /answer
103+
body: |
104+
{
105+
"id": "{{.answer.data.info.id}}"
106+
}
107+
header:
108+
Authorization: '{{.login.data.access_token}}'
109+
Content-Type: application/json
110+
method: DELETE
111+
- expect: {}
112+
name: delQuestion
113+
request:
114+
api: /question
115+
body: |
116+
{
117+
"id": "{{.question.data.id}}"
118+
}
119+
header:
120+
Authorization: '{{.login.data.access_token}}'
121+
Content-Type: application/json
122+
method: DELETE
123+
- expect:
124+
bodyFieldsExpect:
125+
msg: page must be 1 or greater
126+
statusCode: 400
127+
name: search-nagetive-page
128+
request:
129+
api: /search?q=abc&order=active&page={{randInt -10 0}}&size=20
130+
header:
131+
Authorization: '{{.login.data.access_token}}'
132+
Content-Type: application/json
133+
- expect:
134+
bodyFieldsExpect:
135+
msg: size must be 1 or greater
136+
statusCode: 400
137+
name: search-nagetive-size
138+
request:
139+
api: /search?q=abc&order=active&page=1&size={{randInt -10 0}}
140+
header:
141+
Authorization: '{{.login.data.access_token}}'
142+
Content-Type: application/json
143+
- expect:
144+
bodyFieldsExpect:
145+
msg: order must be one of [newest active score relevance]
146+
statusCode: 400
147+
name: search-wrong-order
148+
request:
149+
api: /search?q=abc&order={{randAlpha 6}}&page=1&size=10
150+
header:
151+
Authorization: '{{.login.data.access_token}}'
152+
Content-Type: application/json
153+
- name: search-not-found
154+
request:
155+
api: /search?q={{randAlpha 16}}&order={{index (list "newest" "active" "score"
156+
"relevance") (randInt 0 3)}}&page=1&size=10
157+
header:
158+
Authorization: '{{.login.data.access_token}}'
159+
Content-Type: application/json
160+
- name: tags
161+
request:
162+
api: /tags/page?page=1&page_size=20&query_cond={{index (list "newest" "popular"
163+
"name") (randInt 0 2)}}
164+
header:
165+
Authorization: '{{.login.data.access_token}}'
166+
Content-Type: application/json
167+
- expect:
168+
bodyFieldsExpect:
169+
msg: query_cond must be one of [popular name newest]
170+
statusCode: 400
171+
name: tags-invalid-cond
172+
request:
173+
api: /tags/page?page=1&page_size=20&query_cond={{randAlpha 16}}
174+
header:
175+
Authorization: '{{.login.data.access_token}}'
176+
Content-Type: application/json
177+
- expect: {}
178+
name: user-ranking
179+
request:
180+
api: /user/ranking
181+
header:
182+
Authorization: '{{.login.data.access_token}}'
183+
Content-Type: application/json

0 commit comments

Comments
 (0)