Add checks for mandatory fields

This commit is contained in:
Lars Gohr
2019-08-23 00:49:32 +02:00
parent 075fcde19c
commit 7f8a8d4a00
2 changed files with 54 additions and 0 deletions

View File

@@ -1,5 +1,20 @@
#!/bin/sh #!/bin/sh
if [ -z "${INPUT_NAME}" ]; then
echo "Unable to find the repository name. Did you set with.name?"
exit 1
fi
if [ -z "${INPUT_USERNAME}" ]; then
echo "Unable to find the username. Did you set with.username?"
exit 1
fi
if [ -z "${INPUT_PASSWORD}" ]; then
echo "Unable to find the password. Did you set with.password?"
exit 1
fi
BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g") BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g")
if [ "${BRANCH}" == "master" ]; then if [ "${BRANCH}" == "master" ]; then

39
test.sh
View File

@@ -138,6 +138,42 @@ Called mock with: logout"
cleanEnvironment cleanEnvironment
} }
function itErrorsWhenNameWasNotSet() {
unset INPUT_NAME
local result=$(exec /entrypoint.sh)
local expected="Unable to find the repository name. Did you set with.name?"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
function itErrorsWhenUsernameWasNotSet() {
export INPUT_NAME='my/repository'
unset INPUT_USERNAME
local result=$(exec /entrypoint.sh)
local expected="Unable to find the username. Did you set with.username?"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
function itErrorsWhenPasswordWasNotSet() {
export INPUT_NAME='my/repository'
export INPUT_USERNAME='USERNAME'
unset INPUT_PASSWORD
local result=$(exec /entrypoint.sh)
local expected="Unable to find the password. Did you set with.password?"
if [ "$result" != "$expected" ]; then
echo "Expected: $expected
Got: $result"
exit 1
fi
}
itPushesMasterBranchToLatest itPushesMasterBranchToLatest
itPushesBranchAsNameOfTheBranch itPushesBranchAsNameOfTheBranch
itPushesReleasesToLatest itPushesReleasesToLatest
@@ -145,3 +181,6 @@ itPushesSpecificDockerfileReleasesToLatest
itPushesBranchByShaInAddition itPushesBranchByShaInAddition
itPushesBranchByShaInAdditionWithSpecificDockerfile itPushesBranchByShaInAdditionWithSpecificDockerfile
itLogsIntoAnotherRegistryIfConfigured itLogsIntoAnotherRegistryIfConfigured
itErrorsWhenNameWasNotSet
itErrorsWhenUsernameWasNotSet
itErrorsWhenPasswordWasNotSet