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 <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
Rick 2024-05-28 17:46:38 +08:00 committed by GitHub
parent 1765d139c0
commit 92d517f7b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 191 additions and 11 deletions

View File

@ -4,7 +4,7 @@ Making sure that your local build is OK before committing will help you reduce d
and make it easier for maintainers to review.
-->
> 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.
> 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.
>
> It was updated on 2024/5/27

View File

@ -105,8 +105,8 @@ jobs:
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
make test-e2e
# - name: Operator Image
# run: cd operator && make docker-build
- name: Code Generator Test
run: cd e2e/code-generator && ./start.sh
BuildEmbedUI:
runs-on: ubuntu-latest

5
e2e/README.md Normal file
View File

@ -0,0 +1,5 @@
You can build the image locally in the repository root directory:
```shell
REGISTRY=ghcr.io TAG=master make image
```

View File

@ -0,0 +1,12 @@
ARG LAN_ENV=docker.io/library/golang:1.21
FROM ghcr.io/linuxsuren/api-testing:master AS atest
FROM docker.io/stedolan/jq AS jq
FROM $LAN_ENV
WORKDIR /workspace
COPY . .
COPY --from=jq /usr/local/bin/jq /usr/local/bin/jq
COPY --from=atest /usr/local/bin/atest /usr/local/bin/atest
CMD [ "/workspace/entrypoint.sh" ]

View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
export sourcefile=$1
# exit if no source file is specified
if [ -z "$sourcefile" ]
then
echo "no source file is specified"
exit 1
fi
mv ${sourcefile} main.js
node main.js

View File

@ -0,0 +1,46 @@
services:
golang:
build:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/golang:1.21
command:
- /workspace/entrypoint.sh
- golang
java:
build:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/openjdk:23
command:
- /workspace/entrypoint.sh
- java
python:
build:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/python:3.8
command:
- /workspace/entrypoint.sh
- python
javascript:
build:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/node:22
command:
- /workspace/entrypoint.sh
- JavaScript
curl:
build:
context: .
dockerfile: Dockerfile
args:
- LAN_ENV=docker.io/library/openjdk:23
command:
- /workspace/entrypoint.sh
- curl

13
e2e/code-generator/curl.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
export sourcefile=$1
# exit if no source file is specified
if [ -z "$sourcefile" ]
then
echo "no source file is specified"
exit 1
fi
mv ${sourcefile} main.sh
sh main.sh

View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
export lang=$1
# exit if no language is specified
if [ -z "$lang" ]
then
echo "no language is specified"
exit 1
fi
mkdir -p /root/.config/atest
mkdir -p /var/data
nohup atest server --local-storage '/workspace/test-suites/*.yaml'&
sleep 1
curl http://localhost:8080/server.Runner/GenerateCode -X POST \
-d '{"TestSuite": "test", "TestCase": "requestWithHeader", "Generator": "'"$lang"'"}' > code.json
cat code.json | jq .message -r | sed 's/\\n/\n/g' | sed 's/\\t/\t/g' | sed 's/\\\"/"/g' > code.txt
cat code.txt
sh /workspace/${lang}.sh code.txt
exit 0

13
e2e/code-generator/golang.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
export sourcefile=$1
# exit if no source file is specified
if [ -z "$sourcefile" ]
then
echo "no source file is specified"
exit 1
fi
mv ${sourcefile} main.go
go run main.go

View File

@ -0,0 +1,13 @@
#!/bin/bash
set -e
export sourcefile=$1
# exit if no source file is specified
if [ -z "$sourcefile" ]
then
echo "no source file is specified"
exit 1
fi
mv ${sourcefile} Main.java
java Main.java

View File

@ -0,0 +1,14 @@
#!/bin/bash
set -e
export sourcefile=$1
# exit if no source file is specified
if [ -z "$sourcefile" ]
then
echo "no source file is specified"
exit 1
fi
mv ${sourcefile} main.py
pip install requests
python main.py

10
e2e/code-generator/start.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
docker-compose version
targets=(golang java python javascript curl)
for target in "${targets[@]}"
do
docker-compose down
docker-compose up --build $target
done

View File

@ -0,0 +1,15 @@
#!api-testing
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
# https://docs.gitlab.com/ee/api/api_resources.html
name: test
api: http://localhost:8080/server.Runner
param:
suiteName: test
caseName: test
items:
- name: requestWithHeader
request:
api: /GetSuites
method: POST
header:
auth: fake

View File

@ -1,4 +1,4 @@
/*
'''
Copyright 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.
@ -9,7 +9,7 @@ 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.
*/
'''
import io
import requests
from urllib.parse import urlencode

View File

@ -1,4 +1,4 @@
/*
'''
Copyright 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.
@ -9,7 +9,7 @@ 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.
*/
'''
import io
import requests
from urllib.parse import urlencode

View File

@ -1,4 +1,4 @@
/*
'''
Copyright 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.
@ -9,7 +9,7 @@ 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.
*/
'''
import io
import requests
from urllib.parse import urlencode

View File

@ -1,4 +1,4 @@
/*
'''
Copyright 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.
@ -9,7 +9,7 @@ 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.
*/
'''
import io
import requests
from urllib.parse import urlencode