Skip to content

Commit

Permalink
feat: add basics libraries
Browse files Browse the repository at this point in the history
- logging helper
- is_help

Signed-off-by: Julien Bouyoud <jBouyoud@users.noreply.github.com>
  • Loading branch information
jBouyoud committed Nov 11, 2020
1 parent a6faf95 commit 389ab60
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/lib/is_help.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env sh

set -eu

is_help() {
case "$1" in
-h | --help | help)
return 0
;;
*)
return 1
;;
esac
}
17 changes: 17 additions & 0 deletions scripts/lib/log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh

set -eu

# Output infos
QUIET="${HELM_CONFIG_SCHEME_QUIET:-false}"

log_info() {
if [ "${QUIET}" = "false" ]; then
printf "[config-scheme]%s\n" "$@" >&2
fi
}

log_error() {
echo
printf "[config-scheme]%s\n" "$@"
}
34 changes: 34 additions & 0 deletions tests/unit/quiet.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bats

load '../lib/helper'
load '../bats/extensions/bats-support/load'
load '../bats/extensions/bats-assert/load'
load '../bats/extensions/bats-file/load'

@test "quiet: default" {
run helm config-scheme add scheme1 test.yaml
assert_success
assert_output --partial "[config-scheme][registry] Creating 'scheme1'"
assert_output --partial "[config-scheme][registry] Add file uri 'test.yaml' to scheme 'scheme1'"
}

@test "quiet: -q" {
run helm config-scheme -q add scheme1 test.yaml
assert_success
refute_output --partial "[config-scheme][registry] Creating 'scheme1'"
refute_output --partial "[config-scheme][registry] Add file uri 'test.yaml' to scheme 'scheme1'"
}

@test "quiet: --quiet" {
run helm config-scheme --quiet add scheme1 test.yaml
assert_success
refute_output --partial "[config-scheme][registry] Creating 'scheme1'"
refute_output --partial "[config-scheme][registry] Add file uri 'test.yaml' to scheme 'scheme1'"
}

@test "quiet: env var" {
HELM_CONFIG_SCHEME_QUIET=true run helm config-scheme -q add scheme1 test.yaml
assert_success
refute_output --partial "[config-scheme][registry] Creating 'scheme1'"
refute_output --partial "[config-scheme][registry] Add file uri 'test.yaml' to scheme 'scheme1'"
}

0 comments on commit 389ab60

Please sign in to comment.