-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5351895
commit 2c8770b
Showing
5 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "Print usage" { | ||
bin/kubectl-tmux_exec --help | ||
[ $? -eq 0 ] | ||
} | ||
|
||
@test "Use as a plugin" { | ||
kubectl tmux-exec --help | ||
[ $? -eq 0 ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test-helper | ||
|
||
readonly POD_NAME='alpine' | ||
readonly POD_APP_LABEL='alpine' | ||
|
||
function setup() { | ||
kubectl apply -f - << EOF | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: ${POD_NAME} | ||
labels: | ||
app: ${POD_APP_LABEL} | ||
spec: | ||
containers: | ||
- name: alpine | ||
image: alpine | ||
command: | ||
- sleep | ||
- infinite | ||
EOF | ||
local pod_status='' | ||
local retries=30 | ||
while [[ "${pod_status}" != 'Running' ]]; do | ||
sleep 1 | ||
pod_status="$(kubectl get pods "${POD_NAME}" -o custom-columns=':status.phase' --no-headers)" | ||
echo "The pod status is ${pod_status}." | ||
(( --retries )) || { | ||
echo 'Timed out.' | ||
exit 1 | ||
} | ||
done | ||
} | ||
|
||
function teardown() { | ||
kubectl delete pod "${POD_NAME}" | ||
sleep 1 | ||
} | ||
|
||
@test "Exec one pod by label" { | ||
local written='foobar-label' | ||
bin/kubectl-tmux_exec -d -l app="${POD_APP_LABEL}" -- sh -c "echo ${written} > /tmp/foobar" | ||
|
||
wait_until_no_sessions | ||
|
||
local file_content= | ||
file_content="$(kubectl exec "${POD_NAME}" cat /tmp/foobar)" | ||
|
||
[ "${file_content}" == "${written}" ] | ||
} | ||
|
||
@test "Exec one pod by file" { | ||
# set -x | ||
local written='foobar-file' | ||
bin/kubectl-tmux_exec -d -f - -- sh -c "echo ${written} > /tmp/foobar" <<< "${POD_NAME}" | ||
|
||
wait_until_no_sessions | ||
|
||
local file_content | ||
file_content="$(kubectl exec "${POD_NAME}" cat /tmp/foobar)" | ||
|
||
[ "${file_content}" == "${written}" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
function wait_until_no_sessions() { | ||
local retries=30 | ||
while tmux ls 2>&1 >/dev/null; do | ||
(( --retries )) || { | ||
echo 'Timed out.' | ||
return 1 | ||
} | ||
sleep 1 | ||
done | ||
} |