forked from cnabio/cnab-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e-kind.sh
executable file
·84 lines (60 loc) · 1.67 KB
/
e2e-kind.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# Adapted from https://github.com/helm/chart-testing/blob/b8572749f073372c64323618ca13255677376e0d/e2e-kind.sh
set -o errexit
set -o nounset
set -o pipefail
CLUSTER_NAME=cnab-go-testing
readonly CLUSTER_NAME
K8S_VERSION=v1.21.1
readonly K8S_VERSION
KIND_KUBECONFIG="$PWD/kind-kubeconfig.yaml"
readonly KIND_KUBECONFIG
GO_TEST_COMMAND="go test -tags=integration -v -coverprofile=coverage.txt -covermode atomic ./..."
readonly GO_TEST_COMMAND
GO_TEST_LOG="go_test.log"
readonly GO_TEST_LOG
KIND_CONFIG_FILE="$PWD/kind.config.yaml"
readonly KIND_CONFIG_FILE
create_kind_cluster() {
kind create cluster \
--name "$CLUSTER_NAME" \
--image "kindest/node:$K8S_VERSION" \
--kubeconfig "$KIND_KUBECONFIG" \
--wait 300s \
--config "$KIND_CONFIG_FILE"
kubectl cluster-info --kubeconfig $KIND_KUBECONFIG
echo
kubectl wait --for=condition=Ready nodes --all --kubeconfig $KIND_KUBECONFIG
kubectl get nodes --kubeconfig $KIND_KUBECONFIG
echo
echo 'Cluster ready!'
echo
}
test_e2e() {
echo "Running $GO_TEST_COMMAND"
KUBECONFIG="$KIND_KUBECONFIG" $GO_TEST_COMMAND >"$GO_TEST_LOG" 2>&1
echo
}
print_versions() {
echo "kind version: $(kind version)"
echo "kubectl version: $(kubectl version --client)"
}
delete_kind_cluster() {
kind delete cluster --name "$CLUSTER_NAME"
}
cleanup() {
cat "$GO_TEST_LOG"
echo
cat "$GO_TEST_LOG" | go-junit-report > report.xml
gocov convert coverage.txt > coverage.json
gocov-xml < coverage.json > coverage.xml
delete_kind_cluster
echo 'Done!'
}
main() {
trap cleanup EXIT
print_versions
create_kind_cluster
test_e2e
}
"$@"