Skip to content

Commit

Permalink
Add checks for mandatory fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gohr committed Aug 22, 2019
1 parent 075fcde commit 7f8a8d4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/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")

if [ "${BRANCH}" == "master" ]; then
Expand Down
39 changes: 39 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,49 @@ Called mock with: logout"
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
itPushesBranchAsNameOfTheBranch
itPushesReleasesToLatest
itPushesSpecificDockerfileReleasesToLatest
itPushesBranchByShaInAddition
itPushesBranchByShaInAdditionWithSpecificDockerfile
itLogsIntoAnotherRegistryIfConfigured
itErrorsWhenNameWasNotSet
itErrorsWhenUsernameWasNotSet
itErrorsWhenPasswordWasNotSet

0 comments on commit 7f8a8d4

Please sign in to comment.