Skip to content

Commit

Permalink
test: add e2e testing base on docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Nov 20, 2023
1 parent a628783 commit 705980a
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Testing

on:
- pull_request

jobs:
Test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Build Image
run: |
make autok3s
docker build . -t cnrancher/autok3s:dev
- name: Run e2e
run: |
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
./test/e2e/start.sh
6 changes: 6 additions & 0 deletions test/e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM docker.io/linuxsuren/api-testing:v0.0.14
WORKDIR /workspace
COPY testcase.yaml .
COPY data data
COPY entrypoint.sh entrypoint.sh
CMD [ "/workspace/entrypoint.sh" ]
65 changes: 65 additions & 0 deletions test/e2e/data/cluster-alibaba.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"cluster": false,
"datastore": "",
"datastore-cafile": "",
"datastore-cafile-content": "",
"datastore-certfile": "",
"datastore-certfile-content": "",
"datastore-keyfile": "",
"datastore-keyfile-content": "",
"docker-arg": "",
"docker-script": "https://get.docker.com",
"enable": null,
"k3s-channel": "stable",
"k3s-install-mirror": "INSTALL_K3S_MIRROR=cn",
"k3s-install-script": "https://rancher-mirror.rancher.cn/k3s/k3s-install.sh",
"k3s-version": "",
"manifests": "",
"master": "1",
"master-extra-args": "",
"name": "{{randAlpha 4}}",
"package-name": "",
"package-path": "",
"registry": "",
"registry-content": "",
"rollback": true,
"set": null,
"ssh-agent-auth": false,
"ssh-cert-path": "",
"ssh-key-name": "",
"ssh-key-passphrase": "",
"ssh-key-path": "",
"ssh-password": "",
"ssh-port": "22",
"ssh-user": "root",
"system-default-registry": "",
"tls-sans": null,
"token": "",
"worker": "0",
"worker-extra-args": "",
"ssh-key": "",
"ssh-cert": "",
"provider": "alibaba",
"options": {
"access-key": "cc",
"access-secret": "ccc",
"cloud-controller-manager": false,
"disk-category": "cloud_essd",
"disk-size": "40",
"eip": false,
"image": "ubuntu_22_04_x64_20G_alibase_20230613.vhd",
"instance-type": "ecs.c6.large",
"internet-max-bandwidth-out": "5",
"key-pair": "",
"region": "cn-hangzhou",
"security-group": "",
"spot-duration": 1,
"spot-price-limit": 0,
"spot-strategy": "NoSpot",
"tags": null,
"user-data-content": "",
"user-data-path": "",
"v-switch": "",
"zone": "cn-hangzhou-i"
}
}
31 changes: 31 additions & 0 deletions test/e2e/data/cluster-k3d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"datastore-cafile-content": "",
"datastore-certfile-content": "",
"datastore-keyfile-content": "",
"master": "1",
"master-extra-args": "",
"masters-memory": "",
"name": "{{randAlpha 4}}",
"network": "",
"registry": "",
"registry-content": "",
"token": "",
"worker": "0",
"worker-extra-args": "",
"workers-memory": "",
"rollback": true,
"provider": "k3d",
"options": {
"api-port": "0.0.0.0:0",
"envs": null,
"gpus": "",
"image": "docker.io/rancher/k3s:v1.27.6-k3s1",
"labels": null,
"masters-memory": "",
"no-image-volume": false,
"no-lb": false,
"ports": null,
"volumes": null,
"workers-memory": ""
}
}
46 changes: 46 additions & 0 deletions test/e2e/data/cluster-native.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"cluster": false,
"datastore": "",
"datastore-cafile": "",
"datastore-cafile-content": "",
"datastore-certfile": "",
"datastore-certfile-content": "",
"datastore-keyfile": "",
"datastore-keyfile-content": "",
"docker-arg": "",
"docker-script": "https://get.docker.com",
"enable": [],
"k3s-channel": "stable",
"k3s-install-mirror": "",
"k3s-install-script": "https://get.k3s.io",
"k3s-version": "",
"manifests": "",
"master-extra-args": "",
"name": "{{randAlpha 4}}",
"package-name": "",
"package-path": "",
"registry": "",
"registry-content": "",
"rollback": true,
"set": null,
"ssh-agent-auth": false,
"ssh-cert-path": "",
"ssh-key-name": "",
"ssh-key-passphrase": "",
"ssh-key-path": "",
"ssh-password": "",
"ssh-port": "22",
"ssh-user": "root",
"system-default-registry": "",
"tls-sans": null,
"token": "",
"worker-extra-args": "",
"ssh-key": "",
"ssh-cert": "",
"values": {},
"provider": "native",
"options": {
"master-ips": "0.0.0.0",
"worker-ips": ""
}
}
7 changes: 7 additions & 0 deletions test/e2e/data/credential-alibaba.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"provider": "alibaba",
"secrets": {
"access-key": "sdfsf",
"access-secret": "sdfsfd"
}
}
8 changes: 8 additions & 0 deletions test/e2e/data/credential-aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"provider": "aws",
"secrets": {
"access-key": "test",
"secret-key": "ttest",
"session-token": ""
}
}
7 changes: 7 additions & 0 deletions test/e2e/data/credential-google.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"provider": "google",
"secrets": {
"service-account": "ss",
"service-account-file": "ss"
}
}
7 changes: 7 additions & 0 deletions test/e2e/data/credential-tencent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"provider": "tencent",
"secrets": {
"secret-id": "sdfs",
"secret-key": "fsfds"
}
}
6 changes: 6 additions & 0 deletions test/e2e/data/sshkey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "{{randAlpha 4}}",
"generate-key": true,
"bits": 2048,
"ssh-passphrase": ""
}
16 changes: 16 additions & 0 deletions test/e2e/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
testing:
build: .
depends_on:
autok3s:
condition: service_healthy
links:
- autok3s
autok3s:
image: cnrancher/autok3s:dev
healthcheck:
test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/8080"]
interval: 3s
timeout: 60s
retries: 10
start_period: 3s
4 changes: 4 additions & 0 deletions test/e2e/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e

atest run -p testcase.yaml
31 changes: 31 additions & 0 deletions test/e2e/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

file=$1
if [ "$file" == "" ]
then
file=docker-compose.yaml
fi

docker-compose version
docker-compose -f "$file" up --build -d

while true
do
docker-compose -f "$file" ps | grep testing
if [ $? -eq 1 ]
then
code=-1
docker-compose -f "$file" logs | grep e2e-testing
docker-compose -f "$file" logs | grep e2e-testing | grep Usage
if [ $? -eq 1 ]
then
code=0
echo "successed"
fi

docker-compose -f "$file" down
set -e
exit $code
fi
sleep 1
done
100 changes: 100 additions & 0 deletions test/e2e/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: autok3s
param:
server: http://autok3s:8080
spec:
kind: HTTP
api: http://autok3s:8080/v1
items:
- name: createAlibabaCredential
request:
api: /credentials
method: POST
header:
Content-Type: application/json
bodyFromFile: data/credential-alibaba.json
expect:
statusCode: 201
- name: createAwsCredential
request:
api: /credentials
method: POST
bodyFromFile: data/credential-aws.json
expect:
statusCode: 201
- name: createGoogleCredential
request:
api: /credentials
method: POST
bodyFromFile: data/credential-google.json
expect:
statusCode: 201
- name: createTencentCredential
request:
api: /credentials
method: POST
bodyFromFile: data/credential-tencent.json
expect:
statusCode: 201

- expect:
statusCode: 201
name: createK3dCluster
request:
api: /clusters
bodyFromFile: data/cluster-k3d.json
method: POST
- expect:
statusCode: 201
name: createNativeCluster
request:
api: /clusters
bodyFromFile: data/cluster-native.json
method: POST
- name: createAlibabaCluster
request:
api: /clusters
bodyFromFile: data/cluster-alibaba.json
method: POST
expect:
statusCode: 422
- name: clusters
request:
api: /clusters
method: GET
expect:
verify:
- len(data.data) == 2
- name: getCluster
request:
api: /clusters/{{(index .clusters.data 0).id}}?link=nodes
method: GET
- name: deleteCluster
request:
api: /clusters/{{(index .clusters.data 0).id}}
method: DELETE

## ssh key related APIs
- name: generateSSHKey
request:
api: /sshKeys
method: POST
bodyFromFile: data/sshkey.json
expect:
statusCode: 201
- name: getSSHKeyList
request:
api: /sshKeys
expect:
verify:
- len(data.data) == 1
- name: deleteSSHKey
request:
api: /sshKeys/{{(index .getSSHKeyList.data 0).id}}

## addon related APIs
- name: getAdonList
request:
api: /addons
expect:
verify:
- len(data.data) == 1

0 comments on commit 705980a

Please sign in to comment.