Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve the robustness of e2e test local execution #763

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ variables*.yaml
variables*.yaml.bak
tools*.yaml
tools*.yaml.bak
e2e-test-local.yaml

# IDE
.idea/
Expand Down
47 changes: 25 additions & 22 deletions hack/e2e/e2e-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ 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() {
function check() {
if [ ! -f "${ROOT_DIR}/dtm" ]; then
echo "Binary dtm not found. Maybe you forgot to 'make build' first?"
exit 1
fi

if [ -z ${GITHUB_USER} ]; then
echo "You have to set environment variable 'GITHUB_USER' first!"
Expand Down Expand Up @@ -38,7 +39,9 @@ function check_variables() {
}

# setup k8s cluster and setup config yaml files
function init() {
function set_up() {
check

set -u
echo "[dtm e2e test script] Create k8s cluster by kind!"
bash ${SCRIPT_DIR}/e2e-down.sh
Expand All @@ -51,13 +54,13 @@ function init() {
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}

# modify 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}.tmp
sed -e "s/DOCKERUSERNAME/${DOCKERHUB_USERNAME}/g" ${ROOT_DIR}/${CONFIG_FILENAME}.tmp >${ROOT_DIR}/${CONFIG_FILENAME}
}

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

Expand All @@ -74,14 +77,14 @@ function check_status() {
set -u
pod_ready=1
time=0
timeout=120
timeout=600
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
while [ "$(kubectl get pods -l app=dtm-e2e-test-golang -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}')" != "True" ]; do
echo "pod not ready yet..."
sleep 5
time=$((time + 5))
sleep 10
time=$((time + 10))
if [ ${time} -ge ${timeout} ]; then
${pod_ready}=0
pod_ready=0
break
fi
done
Expand All @@ -91,19 +94,19 @@ function check_status() {
else
echo "[dtm e2e test script] Pod is not ready!"
echo "[dtm e2e test script] E2E test failed!"
clean
clean_up
exit 1
fi
}

function clean() {
function clean_up() {
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!"
rm -f ${ROOT_DIR}/${CONFIG_FILENAME}
rm -f ${ROOT_DIR}/${CONFIG_FILENAME}.tmp
}

function usage() {
Expand All @@ -115,7 +118,7 @@ function usage() {
- 'DOCKERHUB_TOKEN'."
}

check_variables
init
dtm_test
clean
set_up
run_test
clean_up
echo "[dtm e2e test script] E2E test success!"
1 change: 0 additions & 1 deletion test/e2e/suites.go

This file was deleted.

122 changes: 58 additions & 64 deletions test/e2e/yaml/e2e-test-local.yaml
Original file line number Diff line number Diff line change
@@ -1,78 +1,72 @@
---
# 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
repoName: dtm-e2e-test-golang
dockerRegistryUserName: DOCKERUSERNAME
argocdNameSpace: argocd-e2e-test
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:
- 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
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}}
docker:
enable: True
registry:
type: dockerhub
username: [[ dockerRegistryUserName ]]
- 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}}