Skip to content

Commit

Permalink
bats now tests all glyphs. Adding ci job for github
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmosco committed May 20, 2024
1 parent 3f09d1a commit 8a24c36
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "CI"
on: [push, pull_request]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:

- name: Setup BATS
uses: mig4/setup-bats@v1
with:
bats-version: 1.2.1

- name: Check out code
uses: actions/checkout@v1

- name: kube-ps1 test
run: bats tests/kube-ps1.bats
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* The arguments to customize the symbol now include `k8s`, `oc`, and `img`. The default is ``.
* cleanup of the codebase to reduce environment variable clutter
* Some README cleanups.
* Start of a testing framework
* Implemented testing with bats

## 0.8.0 (11/22/22)

Expand Down
4 changes: 1 addition & 3 deletions test/common.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env bats

load '../../../node_modules/bats-support/load'
load '../../../node_modules/bats-assert/load'

setup() {
source "${BATS_TEST_DIRNAME}/../kube-ps1.sh" >/dev/null 2>/dev/null
export _KUBE_PS1_DISABLE_PATH="/tmp/kube_ps1_disable"
Expand All @@ -18,6 +15,7 @@ teardown() {
unset KUBE_PS1_CONTEXT
unset KUBE_PS1_NAMESPACE
unset KUBE_PS1_SYBBOL_COLOR
unset KUBE_PS1_SYMBOL_CUSTOM
rm -rf /tmp/kube-ps1
rm -f /tmp/kubeconfig
}
44 changes: 38 additions & 6 deletions test/kube-ps1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ load common
[ ! -f "$_KUBE_PS1_DISABLE_PATH" ]
}

@test "kubeon with invalid flag" {
run kubeon --invalid
[ "$status" -eq 0 ]
[[ "$output" == *"error: unrecognized flag --invalid"* ]]
}

@test "kubeoff with no arguments" {
run bash -c 'kubeooff; echo "$KUBE_PS1_ENABLED"'
[ "$status" -eq 0 ]
Expand All @@ -40,11 +46,11 @@ load common
[ -f "$_KUBE_PS1_DISABLE_PATH" ]
}

# @test "kubeoff with invalid flag" {
# run kubeoff --invalid
# [ "$status" -ne 0 ]
# [[ "$output" == *"error: unrecognized flag --invalid"* ]]
# }
@test "kubeoff with invalid flag" {
run kubeoff --invalid
[ "$status" -eq 0 ]
[[ "$output" == *"error: unrecognized flag --invalid"* ]]
}

@test "kube_ps1_shell_type returns correct shell type" {
# Simulate bash
Expand Down Expand Up @@ -73,7 +79,33 @@ load common

@test "_kube_ps1_symbol returns the default symbol" {
run _kube_ps1_symbol
assert_output --regexp ''
[ "$status" -eq 0 ]
echo "$output"
[[ "$output" == *""* ]]
}

@test "export KUBE_PS1_SYMBOL=k8s returns 󱃾" {
export KUBE_PS1_SYMBOL_CUSTOM=k8s
run _kube_ps1_symbol
[ "$status" -eq 0 ]
echo "$output"
[[ "$output" == *"󱃾"* ]]
}

@test "export KUBE_PS1_SYMBOL=img returns ☸️" {
export KUBE_PS1_SYMBOL_CUSTOM=img
run _kube_ps1_symbol
[ "$status" -eq 0 ]
echo "$output"
[[ "$output" == *"☸️"* ]]
}

@test "export KUBE_PS1_SYMBOL=oc returns " {
export KUBE_PS1_SYMBOL_CUSTOM=oc
run _kube_ps1_symbol
[ "$status" -eq 0 ]
echo "$output"
[[ "$output" == *""* ]]
}

@test "kube_ps1 returns correct prompt when enabled" {
Expand Down

0 comments on commit 8a24c36

Please sign in to comment.