forked from cert-manager/webhook-example
-
Notifications
You must be signed in to change notification settings - Fork 25
80 lines (65 loc) · 2.14 KB
/
test-go.yaml
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
name: Run code tests
on:
push:
paths:
- '.github/workflows/**'
- 'src/**'
workflow_call:
secrets:
DNSIMPLE_API_TOKEN:
required: true
DNSIMPLE_ZONE_NAME:
required: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: src/go.mod
cache-dependency-path: src/go.sum
- name: Install kubebuilder fixtures
id: kubebuilder
run: |
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
echo "BIN_DIR=$(setup-envtest use -p path)" >> $GITHUB_OUTPUT
- name: Run tests
env:
DNSIMPLE_API_TOKEN: ${{ secrets.DNSIMPLE_API_TOKEN }}
DNSIMPLE_ZONE_NAME: ${{ secrets.DNSIMPLE_ZONE_NAME }}
shell: 'script -q -e -c "bash {0}"'
timeout-minutes: 15
run: |
export TEST_ASSET_KUBE_APISERVER=${{ steps.kubebuilder.outputs.BIN_DIR }}/kube-apiserver
export TEST_ASSET_ETCD=${{ steps.kubebuilder.outputs.BIN_DIR }}/etcd
export TEST_ASSET_KUBECTL=${{ steps.kubebuilder.outputs.BIN_DIR }}/kubectl
export TEST_ZONE_NAME="${DNSIMPLE_ZONE_NAME}." # add trailing dot
YLW='\033[1;33m'
NC='\033[0m'
echo """apiVersion: v1
kind: Secret
metadata:
name: dnsimple-token
type: Opaque
stringData:
token: $DNSIMPLE_API_TOKEN
""" > testdata/dnsimple-token.yaml
cd src
# Occasionally, transient network errors can make tests fail
attempt=0
max_attempts=3
test_exit_code=0
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt+1))
output=$(go test -v . 2>&1 | tee /dev/tty)
test_exit_code=$?
if echo "$output" | grep -q -e "Temporary failure in name resolution" -e "connection reset by peer" -e "i/o timeout"; then
echo -e "${YLW}Detected transient network error. Retrying... ($attempt/$max_attempts)${NC}"
else
break
fi
done
exit $test_exit_code