added shunit2 tests for parameter validation
This commit is contained in:
parent
5571785ad1
commit
958b842e54
20
.drone.yml
20
.drone.yml
@ -1,9 +1,15 @@
|
||||
pipeline:
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
repo: bunix42/drone-sendxmpp
|
||||
tags:
|
||||
- 0.0.1
|
||||
- latest
|
||||
secrets: [ docker_username, docker_password ]
|
||||
test:
|
||||
image: alpine
|
||||
commands:
|
||||
- cd test
|
||||
- ./sendxmpp_parameter_test.sh
|
||||
|
||||
# docker:
|
||||
# image: plugins/docker
|
||||
# repo: bunix42/drone-sendxmpp
|
||||
# tags:
|
||||
# - 0.0.1
|
||||
# - latest
|
||||
# secrets: [ docker_username, docker_password ]
|
||||
|
12
sendxmpp.sh
Normal file → Executable file
12
sendxmpp.sh
Normal file → Executable file
@ -1,14 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
# set username from secret if not supplied
|
||||
[ -z $PLUGIN_USERNAME ] && [ -n $SENDXMPP_USERNAME ] && PLUGIN_USERNAME="${SENDXMPP_USERNAME}"
|
||||
[ -z $PLUGIN_PASSWORD ] && [ -n $SENDXMPP_PASSWORD ] && PLUGIN_PASSWORD="${SENDXMPP_PASSWORD}"
|
||||
[ -z "$PLUGIN_USERNAME" ] && [ -n "$SENDXMPP_USERNAME" ] && PLUGIN_USERNAME="${SENDXMPP_USERNAME}"
|
||||
[ -z "$PLUGIN_PASSWORD" ] && [ -n "$SENDXMPP_PASSWORD" ] && PLUGIN_PASSWORD="${SENDXMPP_PASSWORD}"
|
||||
|
||||
# check if all required fields are set
|
||||
[ -z "$PLUGIN_USERNAME" ] && echo "missing username or sendxmpp_username secret" && exit 1
|
||||
[ -z "$PLUGIN_PASSWORD" ] && echo "missing password or sendxmpp_password secret" && exit 1
|
||||
[ -z "$PLUGIN_JSERVER" ] && echo "missing jserver" && exit 1
|
||||
[ -z "$PLUGIN_RECIPIENT" ] && echo "missing recipient" && 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 123
|
||||
[ -z "$PLUGIN_JSERVER" ] && echo "missing jserver" && exit 123
|
||||
[ -z "$PLUGIN_RECIPIENT" ] && echo "missing recipient" && exit 123
|
||||
|
||||
# create message from drone environment
|
||||
[ -n "$DRONE_TAG"] && MSG="$DRONE_REPO_NAME:$DRONE_TAG" || MSG="$DRONE_REPO_NAME:$DRONE_TAG"
|
||||
|
77
test/sendxmpp_parameter_test.sh
Executable file
77
test/sendxmpp_parameter_test.sh
Executable file
@ -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
|
1137
test/shunit2
Executable file
1137
test/shunit2
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user