-
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.
Merge pull request #4 from predatorray/0.0.x
Added option `detach` and unit tests
- Loading branch information
Showing
6 changed files
with
125 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
language: bash | ||
sudo: required | ||
|
||
env: | ||
global: | ||
- CHANGE_MINIKUBE_NONE_USER=true | ||
- MINIKUBE_WANTUPDATENOTIFICATION=false | ||
- MINIKUBE_WANTREPORTERRORPROMPT=false | ||
- MINIKUBE_HOME=$HOME | ||
- CHANGE_MINIKUBE_NONE_USER=true | ||
- KUBECONFIG=$HOME/.kube/config | ||
|
||
before_script: | ||
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ | ||
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/v1.4.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ | ||
- mkdir -p $HOME/.kube $HOME/.minikube | ||
- touch $KUBECONFIG | ||
- sudo minikube start --vm-driver=none --kubernetes-version=v1.16.0 | ||
- "sudo chown -R travis: /home/travis/.minikube/" | ||
|
||
script: | ||
- make | ||
- export PATH="$(pwd)/bin:$PATH" | ||
- make |
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 | ||
} |