120 lines
2.0 KiB
Bash
120 lines
2.0 KiB
Bash
#!/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
|
|
|
|
try ./go hello
|
|
|
|
assertCalledWithArguments curl linux
|
|
}
|
|
|
|
testWrapperHasCurlFollowLocationHeader() {
|
|
mock curl
|
|
mock uname Linux
|
|
|
|
try ./go hello
|
|
|
|
assertCalledWithArguments curl --location
|
|
}
|
|
|
|
|
|
testWrapperDownloadsFromDarwinUrlOnDarwin() {
|
|
mock curl
|
|
mock uname Darwin
|
|
|
|
try ./go hello
|
|
assertCalledWithArguments curl darwin
|
|
}
|
|
|
|
testWrapperSubstitutesVERSIONInUrl() {
|
|
mock curl
|
|
mock uname Darwin
|
|
|
|
try ./go hello
|
|
assertCalledWithArguments curl http://something/1337/darwin
|
|
}
|
|
|
|
testWrapperRunsDownloadedBinary() {
|
|
mock curl '#!/usr/bin/env bash
|
|
printf "Hello "
|
|
printf "friend"
|
|
'
|
|
mock uname Darwin
|
|
|
|
try ./go hello
|
|
assertContains "$STDOUT" "Hello friend"
|
|
}
|
|
|
|
testWrapperPersistsBinaryInLocationBasedOnNameAndVersion() {
|
|
mock curl '#!/usr/bin/env true
|
|
potato
|
|
'
|
|
mock uname Darwin
|
|
|
|
try ./go hello
|
|
assertContains "$(<.generated/wrapper/something/1337/bin)" potato
|
|
}
|
|
|
|
testWrapperDoesNotRedownloadBinaryIfPresent() {
|
|
mock curl 'whatever'
|
|
mock uname Darwin
|
|
|
|
mkdir -p .generated/wrapper/something/1337/
|
|
touch .generated/wrapper/something/1337/bin
|
|
try ./go hello
|
|
assertNotCalled curl
|
|
assertNotContains "$(<.generated/wrapper/something/1337/bin)" potato
|
|
}
|
|
|
|
testWrapperPassesArgumentsToExecutedBinary() {
|
|
mock curl '#!/usr/bin/env bash
|
|
echo "$@"
|
|
'
|
|
mock uname Darwin
|
|
|
|
echo '
|
|
#!/usr/bin/env bash
|
|
|
|
somethingw() {
|
|
_wrapper \
|
|
-n something \
|
|
-v 1337 \
|
|
-d http://something/darwin \
|
|
-- \
|
|
"$@"
|
|
}
|
|
|
|
⚡hello() { somethingw Hello friend ; }
|
|
' > go
|
|
|
|
echo "source $REPO_ROOT/⚡" >> go
|
|
chmod +x go
|
|
|
|
try ./go hello
|
|
assertContains "$STDOUT" "Hello friend"
|
|
}
|
|
|
|
source $(dirname $0)/runner
|