Skip to content

Commit

Permalink
feat: implement 'view' command
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Bouyoud <jBouyoud@users.noreply.github.com>
  • Loading branch information
jBouyoud committed Nov 11, 2020
1 parent 396136f commit 9402099
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
26 changes: 26 additions & 0 deletions scripts/commands/view.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env sh

set -eu

view_usage() {
cat <<EOF
helm config-scheme view NAME
View configured files uri in NAME configuration scheme
EOF
}

view() {
if [ $# -lt 1 ]; then
view_usage
exit 1
fi
scheme_name="${1}"

if ! repository_scheme_exists "${scheme_name}"; then
log_error "[view] Scheme '${scheme_name}' doesn't exists"
exit 2
fi

repository_view_scheme "${scheme_name}" | sed '=' | sed 'N; s/\n/ /'
}
56 changes: 54 additions & 2 deletions tests/unit/view.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,60 @@ load '../bats/extensions/bats-support/load'
load '../bats/extensions/bats-assert/load'
load '../bats/extensions/bats-file/load'

@test "view:" {
@test "view: show help" {
run helm config-scheme view

assert_failure 1
assert_output --partial 'helm config-scheme view NAME'
}

@test "view -h: show help" {
run helm config-scheme view -h

assert_success
assert_output --partial 'helm config-scheme view NAME'
}

@test "view --help: show help" {
run helm config-scheme view --help

assert_success
assert_output --partial 'helm config-scheme view NAME'
}

@test "view help: show help" {
run helm config-scheme view help

assert_success
assert_output --partial 'helm config-scheme view NAME'
}

@test "view scheme: show error if not exists" {
helm config-scheme add scheme1 a.yaml
helm config-scheme add scheme2 a.yaml b.yaml

run helm config-scheme view bob

assert_failure 2
assert_output --partial 'Error: Not yet implemented.'
assert_output --partial "[config-scheme][view] Scheme 'bob' doesn't exists"
}

@test "view scheme: show scheme detail for the file uri" {
helm config-scheme add scheme1 a.yaml
helm config-scheme add scheme2 a.yaml b.yaml

run helm config-scheme view scheme1

assert_success
assert_output --partial "1 a.yaml"
}

@test "view scheme: show scheme detail for many files uri" {
helm config-scheme add scheme1 a.yaml
helm config-scheme add scheme2 a.yaml b.yaml

run helm config-scheme view scheme2

assert_success
assert_output --partial $'1 a.yaml\n2 b.yaml'
}

0 comments on commit 9402099

Please sign in to comment.