1
0
Fork 0

added shunit2 tests for parameter validation

master
Hanjo Meinhardt 7 years ago
parent 5571785ad1
commit 958b842e54

@ -1,9 +1,15 @@
pipeline: pipeline:
docker: test:
image: plugins/docker image: alpine
repo: bunix42/drone-sendxmpp commands:
tags: - cd test
- 0.0.1 - ./sendxmpp_parameter_test.sh
- latest
secrets: [ docker_username, docker_password ] # docker:
# image: plugins/docker
# repo: bunix42/drone-sendxmpp
# tags:
# - 0.0.1
# - latest
# secrets: [ docker_username, docker_password ]

@ -1,14 +1,14 @@
#!/bin/sh #!/bin/sh
# set username from secret if not supplied # set username from secret if not supplied
[ -z $PLUGIN_USERNAME ] && [ -n $SENDXMPP_USERNAME ] && PLUGIN_USERNAME="${SENDXMPP_USERNAME}" [ -z "$PLUGIN_USERNAME" ] && [ -n "$SENDXMPP_USERNAME" ] && PLUGIN_USERNAME="${SENDXMPP_USERNAME}"
[ -z $PLUGIN_PASSWORD ] && [ -n $SENDXMPP_PASSWORD ] && PLUGIN_PASSWORD="${SENDXMPP_PASSWORD}" [ -z "$PLUGIN_PASSWORD" ] && [ -n "$SENDXMPP_PASSWORD" ] && PLUGIN_PASSWORD="${SENDXMPP_PASSWORD}"
# check if all required fields are set # check if all required fields are set
[ -z "$PLUGIN_USERNAME" ] && echo "missing username or sendxmpp_username secret" && exit 1 [ -z "$PLUGIN_USERNAME" ] && echo "missing username or sendxmpp_username secret" && exit 123
[ -z "$PLUGIN_PASSWORD" ] && echo "missing password or sendxmpp_password secret" && exit 1 [ -z "$PLUGIN_PASSWORD" ] && echo "missing password or sendxmpp_password secret" && exit 123
[ -z "$PLUGIN_JSERVER" ] && echo "missing jserver" && exit 1 [ -z "$PLUGIN_JSERVER" ] && echo "missing jserver" && exit 123
[ -z "$PLUGIN_RECIPIENT" ] && echo "missing recipient" && exit 1 [ -z "$PLUGIN_RECIPIENT" ] && echo "missing recipient" && exit 123
# create message from drone environment # create message from drone environment
[ -n "$DRONE_TAG"] && MSG="$DRONE_REPO_NAME:$DRONE_TAG" || MSG="$DRONE_REPO_NAME:$DRONE_TAG" [ -n "$DRONE_TAG"] && MSG="$DRONE_REPO_NAME:$DRONE_TAG" || MSG="$DRONE_REPO_NAME:$DRONE_TAG"

@ -0,0 +1,77 @@
# !/bin/sh
setUp() {
export PLUGIN_USERNAME="username"
export PLUGIN_PASSWORD="password"
export PLUGIN_JSERVER="server.invalid"
export PLUGIN_RECIPIENT="foo@bar.invalid"
}
tearDown() {
unset PLUGIN_USERNAME
unset PLUGIN_PASSWORD
unset PLUGIN_JSERVER
unset PLUGIN_RECIPIENT
unset SENDXMPP_USERNAME
unset SENDXMPP_PASSWORD
}
testAllOk() {
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 1 $?
assertTrue "[ -z "$stdout" ]"
}
testMissingUsernameAndUsernameSecret() {
unset PLUGIN_USERNAME
unset SENDXMPP_USERNAME
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 123 $?
assertEquals "missing username or sendxmpp_username secret" "$stdout"
}
testUsernameSecretSet() {
unset PLUGIN_USERNAME
export SENDXMPP_USERNAME="secretusername"
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 1 $?
assertTrue "[ -z "$stdout" ]"
}
testMissingPasswordAndPasswordSecret() {
unset PLUGIN_PASSWORD
unset SENDXMPP_PASSWORD
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 123 $?
assertEquals "missing password or sendxmpp_password secret" "$stdout"
}
testPasswordSecretSet() {
unset PLUGIN_PASSWORD
export SENDXMPP_PASSWORD="secretpassword"
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 1 $?
assertTrue "[ -z "$stdout" ]"
}
testMissingJserver() {
unset PLUGIN_JSERVER
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 123 $?
assertEquals "missing jserver" "$stdout"
}
testMissingRecipient() {
unset PLUGIN_RECIPIENT
stdout=$( ../sendxmpp.sh 2> /dev/null )
assertEquals 123 $?
assertEquals "missing recipient" "$stdout"
}
. ./shunit2

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save