Skip to content

Commit

Permalink
Merge pull request #689 from hxcGit/feat-e2e-test-local
Browse files Browse the repository at this point in the history
feat: run e2e test locally
  • Loading branch information
daniel-hutao authored Jun 22, 2022
2 parents a4d6d8f + abf6165 commit 6d2c54a
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 0 deletions.
121 changes: 121 additions & 0 deletions hack/e2e/e2e-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

set -o pipefail

ROOT_DIR=$(dirname "${BASH_SOURCE[0]}")/../..
SCRIPT_DIR=${ROOT_DIR}/hack/e2e
CONFIG_DIR=${ROOT_DIR}/test/e2e/yaml
CONFIG_FILENAME=e2e-test-local.yaml
# CONFIG_FILENAME=e2e-config.yaml
# TOOLS_FILENAME=e2e-tools.yaml
# VARIABLES_FILENAME=e2e-variables.yaml

function check_variables() {

if [ -z ${GITHUB_USER} ]; then
echo "You have to set environment variable 'GITHUB_USER' first!"
usage
exit 1
fi

if [ -z ${GITHUB_TOKEN} ]; then
echo "You have to set environment variable 'GITHUB_TOKEN' first!"
usage
exit 1
fi

if [ -z ${DOCKERHUB_USERNAME} ]; then
echo "You have to set environment variable 'DOCKERHUB_USERNAME' first!"
usage
exit 1
fi

if [ -z ${DOCKERHUB_TOKEN} ]; then
echo "You have to set environment variable 'DOCKERHUB_TOKEN' first!"
usage
exit 1
fi
}

# setup k8s cluster and setup config yaml files
function init() {
set -u
echo "[dtm e2e test script] Create k8s cluster by kind!"
bash ${SCRIPT_DIR}/e2e-down.sh
bash ${SCRIPT_DIR}/e2e-up.sh

gen_config
}

# generate temporary config files
function gen_config() {
set -u

# modify user's github name in e2e-test template config file and generate temporary config file in devstream root path
sed -e "s/GITHUBUSERNAME/${GITHUB_USER}/g" ${CONFIG_DIR}/${CONFIG_FILENAME} >${ROOT_DIR}/${CONFIG_FILENAME}

}

# dtm e2e test
function dtm_test() {
set -u
cd ${ROOT_DIR}

echo "[dtm e2e test script] Start dtm e2e test locally!"
./dtm apply -f ${CONFIG_FILENAME} -y
check_status

./dtm verify -f ${CONFIG_FILENAME}
./dtm delete -f ${CONFIG_FILENAME} -y
cd -
}

function check_status() {
set -u
pod_ready=1
time=0
timeout=120
echo "[dtm e2e test script] Start check pod status!"
while [ "$(kubectl get pods -l app=dtm-e2e-go -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}')" != "True" ]; do
echo "pod not ready yet..."
sleep 5
time=$((time + 5))
if [ ${time} -ge ${timeout} ]; then
${pod_ready}=0
break
fi
done

if [ ${pod_ready} -eq 1 ]; then
echo "[dtm e2e test script] Pod is ready!"
else
echo "[dtm e2e test script] Pod is not ready!"
echo "[dtm e2e test script] E2E test failed!"
clean
exit 1
fi
}

function clean() {
echo "[dtm e2e test script] Start to clean test environment and configuration files!"
echo "[dtm e2e test script] Remove k8s cluster!"
bash ${SCRIPT_DIR}/e2e-down.sh

echo "[dtm e2e test script] Remove yaml files!"
rm -rf ${ROOT_DIR}/${CONFIG_FILENAME}
echo "[dtm e2e test script] E2E test success!"
}

function usage() {
echo "Usage: bash $0.
Before start e2e test locally, you have to set some environment variables, including:
- 'GITHUB_USER'
- 'GITHUB_TOKEN'
- 'DOCKERHUB_USERNAME'
- 'DOCKERHUB_TOKEN'."
}

check_variables
init
dtm_test
clean
78 changes: 78 additions & 0 deletions test/e2e/yaml/e2e-test-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
# core config
varFile: ""
toolFile: ""
state:
backend: local
options:
stateFile: devstream.state

---
# variables config
defaultBranch: main
githubUsername: GITHUBUSERNAME
repoName: dtm-e2e-go
dockerRegistryUserName: dtme2etest
argocdNameSpace: argocd
argocdDeployTimeout: 10m
kanbanBoardName: dtmKanbanTest

---
# plugins config
tools:
- name: github-repo-scaffolding-golang
instanceID: default
options:
owner: [[ githubUsername ]]
repo: [[ repoName ]]
branch: [[ defaultBranch ]]
image_repo: [[ dockerRegistryUserName ]]/[[ repoName ]]
- name: githubactions-golang
instanceID: default
dependsOn: ["github-repo-scaffolding-golang.default"]
options:
owner: ${{github-repo-scaffolding-golang.default.outputs.owner}}
repo: ${{github-repo-scaffolding-golang.default.outputs.repo}}
language:
name: go
version: "1.17"
branch: [[ defaultBranch ]]
build:
enable: True
test:
enable: True
coverage:
enable: True
docker:
enable: True
registry:
type: dockerhub
username: dtme2etest
- name: argocd
instanceID: default
options:
create_namespace: true
repo:
name: argo
url: https://argoproj.github.io/argo-helm
chart:
chart_name: argo/argo-cd
release_name: argocd
namespace: [[ argocdNameSpace ]]
wait: true
timeout: [[ argocdDeployTimeout ]]
upgradeCRDs: true
- name: argocdapp
instanceID: default
dependsOn: ["argocd.default", "github-repo-scaffolding-golang.default"]
options:
app:
name: ${{github-repo-scaffolding-golang.default.outputs.repo}}
namespace: [[ argocdNameSpace ]]
destination:
server: https://kubernetes.default.svc
namespace: default
source:
valuefile: values.yaml
path: helm/${{github-repo-scaffolding-golang.default.outputs.repo}}
repoURL: ${{github-repo-scaffolding-golang.default.outputs.repoURL}}

0 comments on commit 6d2c54a

Please sign in to comment.