Skip to content

Commit 92d517f

Browse files
authored
e2e: add e2e tests for code generators (#458)
* e2e: add e2e tests for code generators * improve the verifying of java code generating --------- Co-authored-by: rick <[email protected]>
1 parent 1765d13 commit 92d517f

File tree

17 files changed

+191
-11
lines changed

17 files changed

+191
-11
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Making sure that your local build is OK before committing will help you reduce d
44
and make it easier for maintainers to review.
55
-->
66

7-
> We highly recommend you read [the contributor's documentation](https://github.com/LinuxSuRen/api-testing/blob/master/CONTRIBUTION.md) before starting the review process especially since this is your first contribution to this project.
7+
> We highly recommend you read [the contributor's documentation](https://github.com/LinuxSuRen/api-testing/blob/master/CONTRIBUTING.md) before starting the review process especially since this is your first contribution to this project.
88
>
99
> It was updated on 2024/5/27
1010

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ jobs:
105105
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
106106
sudo chmod u+x /usr/local/bin/docker-compose
107107
make test-e2e
108-
# - name: Operator Image
109-
# run: cd operator && make docker-build
108+
- name: Code Generator Test
109+
run: cd e2e/code-generator && ./start.sh
110110

111111
BuildEmbedUI:
112112
runs-on: ubuntu-latest

e2e/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
You can build the image locally in the repository root directory:
2+
3+
```shell
4+
REGISTRY=ghcr.io TAG=master make image
5+
```

e2e/code-generator/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG LAN_ENV=docker.io/library/golang:1.21
2+
3+
FROM ghcr.io/linuxsuren/api-testing:master AS atest
4+
FROM docker.io/stedolan/jq AS jq
5+
FROM $LAN_ENV
6+
7+
WORKDIR /workspace
8+
COPY . .
9+
COPY --from=jq /usr/local/bin/jq /usr/local/bin/jq
10+
COPY --from=atest /usr/local/bin/atest /usr/local/bin/atest
11+
12+
CMD [ "/workspace/entrypoint.sh" ]

e2e/code-generator/JavaScript.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export sourcefile=$1
5+
# exit if no source file is specified
6+
if [ -z "$sourcefile" ]
7+
then
8+
echo "no source file is specified"
9+
exit 1
10+
fi
11+
12+
mv ${sourcefile} main.js
13+
node main.js

e2e/code-generator/compose.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
golang:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
args:
7+
- LAN_ENV=docker.io/library/golang:1.21
8+
command:
9+
- /workspace/entrypoint.sh
10+
- golang
11+
java:
12+
build:
13+
context: .
14+
dockerfile: Dockerfile
15+
args:
16+
- LAN_ENV=docker.io/library/openjdk:23
17+
command:
18+
- /workspace/entrypoint.sh
19+
- java
20+
python:
21+
build:
22+
context: .
23+
dockerfile: Dockerfile
24+
args:
25+
- LAN_ENV=docker.io/library/python:3.8
26+
command:
27+
- /workspace/entrypoint.sh
28+
- python
29+
javascript:
30+
build:
31+
context: .
32+
dockerfile: Dockerfile
33+
args:
34+
- LAN_ENV=docker.io/library/node:22
35+
command:
36+
- /workspace/entrypoint.sh
37+
- JavaScript
38+
curl:
39+
build:
40+
context: .
41+
dockerfile: Dockerfile
42+
args:
43+
- LAN_ENV=docker.io/library/openjdk:23
44+
command:
45+
- /workspace/entrypoint.sh
46+
- curl

e2e/code-generator/curl.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export sourcefile=$1
5+
# exit if no source file is specified
6+
if [ -z "$sourcefile" ]
7+
then
8+
echo "no source file is specified"
9+
exit 1
10+
fi
11+
12+
mv ${sourcefile} main.sh
13+
sh main.sh

e2e/code-generator/entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export lang=$1
5+
# exit if no language is specified
6+
if [ -z "$lang" ]
7+
then
8+
echo "no language is specified"
9+
exit 1
10+
fi
11+
12+
mkdir -p /root/.config/atest
13+
mkdir -p /var/data
14+
15+
nohup atest server --local-storage '/workspace/test-suites/*.yaml'&
16+
sleep 1
17+
18+
curl http://localhost:8080/server.Runner/GenerateCode -X POST \
19+
-d '{"TestSuite": "test", "TestCase": "requestWithHeader", "Generator": "'"$lang"'"}' > code.json
20+
21+
cat code.json | jq .message -r | sed 's/\\n/\n/g' | sed 's/\\t/\t/g' | sed 's/\\\"/"/g' > code.txt
22+
cat code.txt
23+
24+
sh /workspace/${lang}.sh code.txt
25+
26+
exit 0

e2e/code-generator/golang.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export sourcefile=$1
5+
# exit if no source file is specified
6+
if [ -z "$sourcefile" ]
7+
then
8+
echo "no source file is specified"
9+
exit 1
10+
fi
11+
12+
mv ${sourcefile} main.go
13+
go run main.go

e2e/code-generator/java.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
export sourcefile=$1
5+
# exit if no source file is specified
6+
if [ -z "$sourcefile" ]
7+
then
8+
echo "no source file is specified"
9+
exit 1
10+
fi
11+
12+
mv ${sourcefile} Main.java
13+
java Main.java

0 commit comments

Comments
 (0)