Skip to content

Commit 2de4a1c

Browse files
author
Matt Pearson
committed
Replace swath of redundant tests with working arg-parse test.
1 parent 68a726c commit 2de4a1c

File tree

3 files changed

+78
-88
lines changed

3 files changed

+78
-88
lines changed

arg-parsing-test.bats

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bats
2+
3+
source lib/assert.bash
4+
source deploy.sh --source-only
5+
6+
setup() {
7+
run mktemp -dt deploy_test.XXXX
8+
assert_success
9+
tmp=$output
10+
pushd "$tmp" >/dev/null
11+
}
12+
13+
teardown() {
14+
popd >/dev/null
15+
rm -rf "$tmp"
16+
}
17+
18+
set_env_vars() {
19+
# Set environment variables.
20+
export GIT_DEPLOY_USERNAME=env-username
21+
export GIT_DEPLOY_EMAIL=env-email
22+
export GIT_DEPLOY_APPEND_HASH=env-var
23+
}
24+
25+
write_env_file() {
26+
# Write a '.env' file to override environment variables.
27+
cat <<-EOF > .env
28+
GIT_DEPLOY_EMAIL=dotenv-email
29+
GIT_DEPLOY_APPEND_HASH=env-file
30+
EOF
31+
}
32+
33+
write_conf_file() {
34+
# Write a config-file to override '.env'.
35+
cat <<-EOF > conf
36+
GIT_DEPLOY_EMAIL=conf-email
37+
GIT_DEPLOY_APPEND_HASH=conf-file
38+
EOF
39+
}
40+
41+
@test 'If not otherwise specified, use in-script default.' {
42+
parse_args
43+
assert that "$append_hash" = "true"
44+
}
45+
46+
@test ' Environment variable overrides in-script default.' {
47+
set_env_vars
48+
49+
parse_args
50+
assert that "$append_hash" = "env-var"
51+
}
52+
53+
@test ' .env file overrides environment variables.' {
54+
set_env_vars
55+
write_env_file
56+
57+
parse_args
58+
assert that "$append_hash" = "env-file"
59+
}
60+
61+
@test ' conf file overrides .env file.' {
62+
set_env_vars
63+
write_env_file
64+
write_conf_file
65+
66+
parse_args --config-file conf
67+
assert that "$append_hash" = "conf-file"
68+
}
69+
70+
@test ' command-line overrides conf file.' {
71+
set_env_vars
72+
write_env_file
73+
write_conf_file
74+
75+
parse_args --config-file conf --no-hash
76+
assert that "$append_hash" = "false"
77+
}
78+

tests/env-file.bats

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/env-vars.bats

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)