Skip to content

Commit

Permalink
tests/template: Remove unnecessary assertions
Browse files Browse the repository at this point in the history
The tests are more focused without these assertions, especially
`assert_go_core_unpacked`.
  • Loading branch information
mbland committed Sep 10, 2017
1 parent 73ac6fc commit 41daa0c
Showing 1 changed file with 12 additions and 52 deletions.
64 changes: 12 additions & 52 deletions tests/template.bats
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,13 @@ setup() {
create_forwarding_script 'cygpath'
create_forwarding_script 'git'

mkdir -p "$TEST_GO_ROOTDIR"
cp "$_GO_CORE_DIR/go-template" "$TEST_GO_ROOTDIR"
}

teardown() {
@go.remove_test_go_rootdir
}

assert_go_core_unpacked() {
set "$DISABLE_BATS_SHELL_OPTIONS"
local go_core="${1:-$TEST_GO_SCRIPTS_DIR/go-script-bash}/go-core.bash"
local result='0'

if [[ ! -f "$go_core" ]]; then
printf "Download did not unpack go-core.bash to: $go_core" >&2
result='1'
fi
restore_bats_shell_options "$result"
}

# This mimics the tarball provided by GitHub.
#
# This could probably become a general-purpose utility one day.
Expand Down Expand Up @@ -151,33 +138,24 @@ run_with_download_program() {
skip_if_none_present_on_system 'curl' 'fetch' 'wget'
skip_if_system_missing 'tar'
create_fake_tarball_if_not_using_real_url
run "$TEST_GO_ROOTDIR/go-template"

# Without a command argument, the script will print the top-level help and
# return an error, but the core repo should exist as expected.
assert_failure
run "$TEST_GO_ROOTDIR/go-template"
assert_output_matches "Downloading framework from '$EXPECTED_URL'\.\.\."
assert_output_matches "Download of '$EXPECTED_URL' successful."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Download of '$EXPECTED_URL' successful."
}

@test "$SUITE: download locally using curl" {
skip_if_system_missing 'tar'
run_with_download_program 'curl'
assert_output_matches "Downloading framework from '$NATIVE_LOCAL_URL'\.\.\."
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."
}

@test "$SUITE: download locally using fetch" {
skip_if_system_missing 'tar'
run_with_download_program 'fetch'
assert_output_matches "Downloading framework from '$NATIVE_LOCAL_URL'\.\.\."
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."
}

@test "$SUITE: download locally using cat" {
Expand All @@ -186,9 +164,7 @@ run_with_download_program() {
# HTTP, HTTPS, and FTP.
run_with_download_program 'cat'
assert_output_matches "Downloading framework from '$NATIVE_LOCAL_URL'\.\.\."
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."
}

@test "$SUITE: download locally using wget" {
Expand All @@ -197,9 +173,7 @@ run_with_download_program() {
# URLs, but we're simulating `wget` by pretending `cat` doesn't exist.
run_with_download_program 'wget'
assert_output_matches "Downloading framework from '$NATIVE_LOCAL_URL'\.\.\."
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Download of '$NATIVE_LOCAL_URL' successful."
}

@test "$SUITE: download into nonstandard GO_SCRIPTS_DIR" {
Expand All @@ -211,11 +185,7 @@ run_with_download_program() {
# Create a command script in the normal `TEST_GO_SCRIPTS_DIR`.
@go.create_test_command_script 'foo' 'printf "%s\n" "Hello, World!"'
GO_SCRIPT_BASH_CORE_DIR="$core_dir" run "$TEST_GO_ROOTDIR/go-template"

assert_failure
assert_output_matches "Download of '$EXPECTED_URL' successful."
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked "$core_dir"
}

@test "$SUITE: download uses existing GO_SCRIPTS_DIR" {
Expand All @@ -227,10 +197,7 @@ run_with_download_program() {
run "$TEST_GO_ROOTDIR/go-template"
restore_program_in_path 'mkdir'

assert_failure
assert_output_matches "Download of '$EXPECTED_URL' successful."
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
}

@test "$SUITE: fail to download a nonexistent repo" {
Expand All @@ -241,7 +208,7 @@ run_with_download_program() {
skip_if_system_missing 'git' 'tar'
GO_SCRIPT_BASH_DOWNLOAD_URL="$url" GO_SCRIPT_BASH_REPO_URL="$repo" \
run "$TEST_GO_ROOTDIR/go-template"
assert_failure

assert_output_matches "Downloading framework from '$url/$RELEASE_TARBALL'"
assert_output_matches "Failed to download from '$url/$RELEASE_TARBALL'"
assert_output_matches 'Using git clone as fallback'
Expand Down Expand Up @@ -278,10 +245,7 @@ run_with_download_program() {
assert_output_matches "Using git clone as fallback"
assert_output_matches "Cloning framework from '$GO_SCRIPT_BASH_REPO_URL'"
assert_output_matches "Cloning into '$CLONE_DIR'"
assert_output_matches \
"Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."$'\n\n'
assert_output_matches "Usage: $TEST_GO_ROOTDIR/go-template <command>"
assert_go_core_unpacked
assert_output_matches "Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."

cd "$TEST_GO_SCRIPTS_DIR/go-script-bash"
run git log --oneline -n 1
Expand All @@ -296,8 +260,7 @@ run_with_download_program() {
assert_output_matches "Failed to find cURL, wget, or fetch"
assert_output_matches "Cloning framework from '$GO_SCRIPT_BASH_REPO_URL'"
assert_output_matches "Cloning into '$CLONE_DIR'"
assert_output_matches \
"Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."$'\n\n'
assert_output_matches "Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."
}

@test "$SUITE: fail to find tar uses git clone" {
Expand All @@ -312,8 +275,7 @@ run_with_download_program() {
assert_output_matches "Using git clone as fallback"
assert_output_matches "Cloning framework from '$GO_SCRIPT_BASH_REPO_URL'"
assert_output_matches "Cloning into '$CLONE_DIR'"
assert_output_matches \
"Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."$'\n\n'
assert_output_matches "Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."
}

@test "$SUITE: tar failure uses git clone" {
Expand Down Expand Up @@ -354,8 +316,7 @@ run_with_download_program() {
assert_output_matches "Using git clone as fallback"
assert_output_matches "Cloning framework from '$GO_SCRIPT_BASH_REPO_URL'"
assert_output_matches "Cloning into '$CLONE_DIR'"
assert_output_matches \
"Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."$'\n\n'
assert_output_matches "Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."
}

@test "$SUITE: fail to move extracted directory uses git clone" {
Expand All @@ -373,6 +334,5 @@ run_with_download_program() {
assert_output_matches "Using git clone as fallback"
assert_output_matches "Cloning framework from '$GO_SCRIPT_BASH_REPO_URL'"
assert_output_matches "Cloning into '$CLONE_DIR'"
assert_output_matches \
"Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."$'\n\n'
assert_output_matches "Clone of '$GO_SCRIPT_BASH_REPO_URL' successful\."
}

0 comments on commit 41daa0c

Please sign in to comment.