forked from X1011/git-directory-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharg-parsing-test.bats
78 lines (62 loc) · 1.48 KB
/
arg-parsing-test.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bats
source lib/assert.bash
source deploy.sh --source-only
setup() {
run mktemp -dt deploy_test.XXXX
assert_success
tmp=$output
pushd "$tmp" >/dev/null
}
teardown() {
popd >/dev/null
rm -rf "$tmp"
}
set_env_vars() {
# Set environment variables.
export GIT_DEPLOY_APPEND_HASH=env-var
}
write_env_file() {
# Write a '.env' file to override environment variables.
cat <<-EOF > .env
GIT_DEPLOY_APPEND_HASH=env-file
EOF
}
write_conf_file() {
# Write a config-file to override '.env'.
cat <<-EOF > conf
GIT_DEPLOY_APPEND_HASH=conf-file
EOF
}
@test 'Arg-parsing defaults to in-script values.' {
parse_args
assert that "$append_hash" = "true"
}
@test ' overrides script defaults with environment variables.' {
set_env_vars
parse_args
assert that "$append_hash" = "env-var"
}
@test ' overrides environment variables with .env file.' {
set_env_vars
write_env_file
parse_args
assert that "$append_hash" = "env-file"
}
@test ' overrides .env with a file specified on the command-line.' {
set_env_vars
write_env_file
write_conf_file
parse_args --config-file conf
assert that "$append_hash" = "conf-file"
}
@test ' overrides everything with a command-line option.' {
set_env_vars
write_env_file
write_conf_file
parse_args --config-file conf --no-hash
assert that "$append_hash" = "false"
}
@test ' sets a commit message with spaces in it.' {
parse_args --message "a message"
assert that "$commit_message" = "a message"
}