From 8a24c36d4f0d9b57d59752abea61094961265279 Mon Sep 17 00:00:00 2001 From: Jon Mosco Date: Mon, 20 May 2024 08:30:24 -0400 Subject: [PATCH] bats now tests all glyphs. Adding ci job for github --- .github/workflows/ci.yml | 18 ++++++++++++++++ CHANGELOG.md | 2 +- test/common.bash | 4 +--- test/kube-ps1.bats | 44 ++++++++++++++++++++++++++++++++++------ 4 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..63a8820 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c8739..89daa0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/test/common.bash b/test/common.bash index cdde66b..37b8be7 100644 --- a/test/common.bash +++ b/test/common.bash @@ -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" @@ -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 } diff --git a/test/kube-ps1.bats b/test/kube-ps1.bats index 3751315..8579848 100644 --- a/test/kube-ps1.bats +++ b/test/kube-ps1.bats @@ -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 ] @@ -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 @@ -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" {