2016-04-24 06:20:05 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-25 06:37:21 -07:00
|
|
|
# shellcheck disable=SC2164
|
2016-04-24 06:20:05 -07:00
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
load test_helpers
|
2016-04-24 06:20:05 -07:00
|
|
|
|
|
|
|
setup() {
|
2022-06-24 02:20:27 -07:00
|
|
|
cd "$BATS_TMPDIR"
|
|
|
|
ASDF_CONFIG_FILE="$BATS_TMPDIR/asdfrc"
|
|
|
|
cat >"$ASDF_CONFIG_FILE" <<-EOM
|
2016-04-24 06:20:05 -07:00
|
|
|
key1 = value1
|
|
|
|
legacy_version_file = yes
|
|
|
|
EOM
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
ASDF_CONFIG_DEFAULT_FILE="$BATS_TMPDIR/asdfrc_defaults"
|
|
|
|
cat >"$ASDF_CONFIG_DEFAULT_FILE" <<-EOM
|
2016-04-24 06:20:05 -07:00
|
|
|
# i have a comment, it's ok
|
|
|
|
key2 = value2
|
|
|
|
legacy_version_file = no
|
|
|
|
EOM
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2022-06-24 02:20:27 -07:00
|
|
|
rm "$ASDF_CONFIG_FILE"
|
|
|
|
rm "$ASDF_CONFIG_DEFAULT_FILE"
|
|
|
|
unset ASDF_CONFIG_DEFAULT_FILE
|
|
|
|
unset ASDF_CONFIG_FILE
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "get_config returns default when config file does not exist" {
|
2022-06-24 02:20:27 -07:00
|
|
|
result=$(ASDF_CONFIG_FILE="/some/fake/path" get_asdf_config_value "legacy_version_file")
|
|
|
|
[ "$result" = "no" ]
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "get_config returns default value when the key does not exist" {
|
2022-06-24 02:20:27 -07:00
|
|
|
[ "$(get_asdf_config_value "key2")" = "value2" ]
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "get_config returns config file value when key exists" {
|
2022-06-24 02:20:27 -07:00
|
|
|
[ "$(get_asdf_config_value "key1")" = "value1" ]
|
|
|
|
[ "$(get_asdf_config_value "legacy_version_file")" = "yes" ]
|
2016-04-24 06:20:05 -07:00
|
|
|
}
|
2021-12-15 01:29:08 -07:00
|
|
|
|
|
|
|
@test "get_config returns config file complete value including '=' symbols" {
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >>"$ASDF_CONFIG_FILE" <<-'EOM'
|
2021-12-15 01:29:08 -07:00
|
|
|
key3 = VAR=val
|
|
|
|
EOM
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
[ "$(get_asdf_config_value "key3")" = "VAR=val" ]
|
2021-12-15 01:29:08 -07:00
|
|
|
}
|