lightning-runner/test/test-wrapper

203 lines
3.2 KiB
Bash

#!/usr/bin/env bash
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
}
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
}
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
}
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
}
testWrapperRunsDownloadedBinary() {
mock curl '#!/usr/bin/env bash
printf "Hello "
printf "friend"
'
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"
}
testWrapperPersistsBinaryInLocationBasedOnNameAndVersion() {
mock curl '#!/usr/bin/env true
potato
'
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
}
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
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