This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.bats
More file actions
177 lines (144 loc) · 7.33 KB
/
tests.bats
File metadata and controls
177 lines (144 loc) · 7.33 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
JS_NAMESPACE="${JS_NAMESPACE:-jumpstarter-lab}"
setup() {
bats_load_library bats-support
bats_load_library bats-assert
bats_require_minimum_version 1.5.0
}
wait_for_exporter() {
# After a lease operation the exporter is disconnecting from controller and reconnecting.
# The disconnect can take a short while so let's avoid catching the pre-disconnect state and early return
sleep 2
kubectl -n "${JS_NAMESPACE}" wait --timeout 20m --for=condition=Online --for=condition=Registered \
exporters.jumpstarter.dev/test-exporter-oidc
kubectl -n "${JS_NAMESPACE}" wait --timeout 20m --for=condition=Online --for=condition=Registered \
exporters.jumpstarter.dev/test-exporter-sa
kubectl -n "${JS_NAMESPACE}" wait --timeout 20m --for=condition=Online --for=condition=Registered \
exporters.jumpstarter.dev/test-exporter-legacy
}
@test "can create clients with admin cli" {
jmp admin create client -n "${JS_NAMESPACE}" test-client-oidc --unsafe --out /dev/null \
--oidc-username dex:test-client-oidc
jmp admin create client -n "${JS_NAMESPACE}" test-client-sa --unsafe --out /dev/null \
--oidc-username dex:system:serviceaccount:"${JS_NAMESPACE}":test-client-sa
jmp admin create client -n "${JS_NAMESPACE}" test-client-legacy --unsafe --save
}
@test "can create exporters with admin cli" {
jmp admin create exporter -n "${JS_NAMESPACE}" test-exporter-oidc --out /dev/null \
--oidc-username dex:test-exporter-oidc \
--label example.com/board=oidc
jmp admin create exporter -n "${JS_NAMESPACE}" test-exporter-sa --out /dev/null \
--oidc-username dex:system:serviceaccount:"${JS_NAMESPACE}":test-exporter-sa \
--label example.com/board=sa
jmp admin create exporter -n "${JS_NAMESPACE}" test-exporter-legacy --save \
--label example.com/board=legacy
}
@test "can login with oidc" {
jmp config client list
jmp config exporter list
jmp login --client test-client-oidc \
--endpoint "$ENDPOINT" --namespace "${JS_NAMESPACE}" --name test-client-oidc \
--issuer https://dex.dex.svc.cluster.local:5556 \
--username test-client-oidc@example.com --password password --unsafe
jmp login --client test-client-oidc-provisioning \
--endpoint "$ENDPOINT" --namespace "${JS_NAMESPACE}" --name "" \
--issuer https://dex.dex.svc.cluster.local:5556 \
--username test-client-oidc-provisioning@example.com --password password --unsafe
jmp login --client test-client-sa \
--endpoint "$ENDPOINT" --namespace "${JS_NAMESPACE}" --name test-client-sa \
--issuer https://dex.dex.svc.cluster.local:5556 \
--connector-id kubernetes \
--token $(kubectl create -n "${JS_NAMESPACE}" token test-client-sa) --unsafe
jmp login --exporter test-exporter-oidc \
--endpoint "$ENDPOINT" --namespace "${JS_NAMESPACE}" --name test-exporter-oidc \
--issuer https://dex.dex.svc.cluster.local:5556 \
--username test-exporter-oidc@example.com --password password
jmp login --exporter test-exporter-sa \
--endpoint "$ENDPOINT" --namespace "${JS_NAMESPACE}" --name test-exporter-sa \
--issuer https://dex.dex.svc.cluster.local:5556 \
--connector-id kubernetes \
--token $(kubectl create -n "${JS_NAMESPACE}" token test-exporter-sa)
go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \
/etc/jumpstarter/exporters/test-exporter-oidc.yaml
go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \
/etc/jumpstarter/exporters/test-exporter-sa.yaml
go run github.com/mikefarah/yq/v4@latest -i ". * load(\"$GITHUB_ACTION_PATH/exporter.yaml\")" \
/etc/jumpstarter/exporters/test-exporter-legacy.yaml
jmp config client list
jmp config exporter list
}
@test "can run exporters" {
cat <<EOF | bash 3>&- &
while true; do
jmp run --exporter test-exporter-oidc
done
EOF
cat <<EOF | bash 3>&- &
while true; do
jmp run --exporter test-exporter-sa
done
EOF
cat <<EOF | bash 3>&- &
while true; do
jmp run --exporter test-exporter-legacy
done
EOF
wait_for_exporter
}
@test "can specify client config only using environment variables" {
wait_for_exporter
# we feed the namespace into JMP_NAMESPACE along with all the other client details
# to verify that the client can operate without a config file
JMP_NAMESPACE="${JS_NAMESPACE}" \
JMP_DRIVERS_ALLOW="*" \
JMP_NAME=test-exporter-legacy \
JMP_ENDPOINT=$(kubectl get clients.jumpstarter.dev -n "${JS_NAMESPACE}" test-client-legacy -o 'jsonpath={.status.endpoint}') \
JMP_TOKEN=$(kubectl get secrets -n "${JS_NAMESPACE}" test-client-legacy-client -o 'jsonpath={.data.token}' | base64 -d) \
jmp shell --selector example.com/board=oidc j power on
}
@test "can operate on leases" {
wait_for_exporter
jmp config client use test-client-oidc
jmp create lease --selector example.com/board=oidc --duration 1d
jmp get leases
jmp get exporters
jmp delete leases --all
}
@test "can lease and connect to exporters" {
wait_for_exporter
jmp shell --client test-client-oidc --selector example.com/board=oidc j power on
jmp shell --client test-client-sa --selector example.com/board=sa j power on
jmp shell --client test-client-legacy --selector example.com/board=legacy j power on
wait_for_exporter
jmp shell --client test-client-oidc-provisioning --selector example.com/board=oidc j power on
}
@test "can get crds with admin cli" {
jmp admin get client --namespace "${JS_NAMESPACE}"
jmp admin get exporter --namespace "${JS_NAMESPACE}"
jmp admin get lease --namespace "${JS_NAMESPACE}"
}
@test "can delete clients with admin cli" {
kubectl -n "${JS_NAMESPACE}" get secret test-client-oidc-client
kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-oidc
kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-sa
kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-legacy
jmp admin delete client --namespace "${JS_NAMESPACE}" test-client-oidc --delete
jmp admin delete client --namespace "${JS_NAMESPACE}" test-client-sa --delete
jmp admin delete client --namespace "${JS_NAMESPACE}" test-client-legacy --delete
run ! kubectl -n "${JS_NAMESPACE}" get secret test-client-oidc-client
run ! kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-oidc
run ! kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-sa
run ! kubectl -n "${JS_NAMESPACE}" get clients.jumpstarter.dev/test-client-legacy
}
@test "can delete exporters with admin cli" {
kubectl -n "${JS_NAMESPACE}" get secret test-exporter-oidc-exporter
kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-oidc
kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-sa
kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-legacy
jmp admin delete exporter --namespace "${JS_NAMESPACE}" test-exporter-oidc --delete
jmp admin delete exporter --namespace "${JS_NAMESPACE}" test-exporter-sa --delete
jmp admin delete exporter --namespace "${JS_NAMESPACE}" test-exporter-legacy --delete
run ! kubectl -n "${JS_NAMESPACE}" get secret test-exporter-oidc-exporter
run ! kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-oidc
run ! kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-sa
run ! kubectl -n "${JS_NAMESPACE}" get exporters.jumpstarter.dev/test-exporter-legacy
}