Simplify test with setUp
This commit is contained in:
parent
9b11316463
commit
d2322c0e5e
19
test/runner
19
test/runner
@ -1,5 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
preserve-suite-bookend-functions() {
|
||||
if type setUp &>/dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
eval "_suite_$(typeset -f setUp)"
|
||||
else
|
||||
_suite_setUp() { :; }
|
||||
fi
|
||||
if type tearDown &>/dev/null; then
|
||||
# shellcheck disable=SC2034
|
||||
eval "_suite_$(typeset -f tearDown)"
|
||||
else
|
||||
_suite_tearDown() { :; }
|
||||
fi
|
||||
}
|
||||
|
||||
preserve-suite-bookend-functions
|
||||
|
||||
try() {
|
||||
output=$(mktemp -d)
|
||||
PATH="$fake_path:$PATH" "$@" > "$output/stdout" 2> "$output/stderr"
|
||||
@ -15,9 +32,11 @@ setUp() {
|
||||
export-repo-root
|
||||
move-to-working-directory
|
||||
create-fake-path
|
||||
_suite_setUp
|
||||
}
|
||||
|
||||
tearDown() {
|
||||
_suite_tearDown
|
||||
[ "${_shunit_test_:=}" = '' ] && return 0
|
||||
|
||||
clean-up-working-directory
|
||||
|
@ -1,46 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
setUp() {
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-n something \
|
||||
-v 1337 \
|
||||
-l http://something/VERSION/linux \
|
||||
-d http://something/VERSION/darwin \
|
||||
-- \
|
||||
"$@"
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
}
|
||||
|
||||
testWrapperDownloadsFromLinuxUrlOnLinux() {
|
||||
mock curl
|
||||
mock uname Linux
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-l http://something/linux
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
|
||||
assertCalledWithArguments curl http://something/linux
|
||||
assertCalledWithArguments curl linux
|
||||
}
|
||||
|
||||
testWrapperHasCurlFollowLocationHeader() {
|
||||
mock curl
|
||||
mock uname Linux
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-l http://something/linux
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
|
||||
assertCalledWithArguments curl --location
|
||||
@ -51,43 +44,14 @@ testWrapperDownloadsFromDarwinUrlOnDarwin() {
|
||||
mock curl
|
||||
mock uname Darwin
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-d http://something/darwin
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
assertCalledWithArguments curl http://something/darwin
|
||||
assertCalledWithArguments curl darwin
|
||||
}
|
||||
|
||||
testWrapperSubstitutesVERSIONInUrl() {
|
||||
mock curl
|
||||
mock uname Darwin
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-v 1337 \
|
||||
-d http://something/VERSION/darwin
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
assertCalledWithArguments curl http://something/1337/darwin
|
||||
}
|
||||
@ -99,21 +63,6 @@ testWrapperRunsDownloadedBinary() {
|
||||
'
|
||||
mock uname Darwin
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-d http://something/darwin
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
|
||||
try ./go hello
|
||||
assertContains "$STDOUT" "Hello friend"
|
||||
}
|
||||
@ -124,22 +73,6 @@ testWrapperPersistsBinaryInLocationBasedOnNameAndVersion() {
|
||||
'
|
||||
mock uname Darwin
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-n something \
|
||||
-v 1337 \
|
||||
-d http://something/darwin
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
try ./go hello
|
||||
assertContains "$(<.generated/wrapper/something/1337/bin)" potato
|
||||
}
|
||||
@ -148,22 +81,6 @@ testWrapperDoesNotRedownloadBinaryIfPresent() {
|
||||
mock curl 'whatever'
|
||||
mock uname Darwin
|
||||
|
||||
echo '
|
||||
#!/usr/bin/env bash
|
||||
|
||||
somethingw() {
|
||||
_wrapper \
|
||||
-n something \
|
||||
-v 1337 \
|
||||
-d http://something/darwin
|
||||
}
|
||||
|
||||
⚡hello() { somethingw ; }
|
||||
' > go
|
||||
|
||||
echo "source $REPO_ROOT/⚡" >> go
|
||||
chmod +x go
|
||||
|
||||
mkdir -p .generated/wrapper/something/1337/
|
||||
touch .generated/wrapper/something/1337/bin
|
||||
try ./go hello
|
||||
|
Loading…
Reference in New Issue
Block a user