Add some tests and simplify push syntax

This commit is contained in:
ViViDboarder 2020-05-18 18:08:06 -07:00
parent 33594bbc59
commit 21ad3e9eeb
6 changed files with 65 additions and 6 deletions

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
.PHONY: clean all
.PHONY: default
default: test
.PHONY: test
test:
docker-compose -f ./tests/docker-compose-private.yml up \
--abort-on-container-exit --exit-code-from plugin
docker-compose -f ./tests/docker-compose-public.yml up \
--abort-on-container-exit --exit-code-from plugin

View File

@ -46,3 +46,12 @@ The following environment variables can be used for further cutomization:
| ``PLUGIN_TIMEOUT`` | Defines a timeout (in seconds) to stop the upload after a certain time. | | ``PLUGIN_TIMEOUT`` | Defines a timeout (in seconds) to stop the upload after a certain time. |
| ``PLUGIN_ATTEMPTS`` | Defines how often a failed upload should be retried. Normally there is only one upload attempt. | | ``PLUGIN_ATTEMPTS`` | Defines how often a failed upload should be retried. Normally there is only one upload attempt. |
| ``PLUGIN_CUSTOM_ARGUMENTS`` | Additional arguments to be passed to `curl`. | | ``PLUGIN_CUSTOM_ARGUMENTS`` | Additional arguments to be passed to `curl`. |
## Development
There are only two tests right now and they are configured using Docker Compose. To run them, just use
make test
If someone wants to make this better (or add a Drone file) I'd gladly accept the patch.

13
push.sh
View File

@ -1,31 +1,31 @@
#! /bin/sh #! /bin/sh
# Use WEBDAV_USERNAME as default, if provided. # Use WEBDAV_USERNAME as default, if provided.
if [ -z "$PLUGIN_USERNAME" ] && [ ! -z "$WEBDAV_USERNAME" ]; then if [ -z "$PLUGIN_USERNAME" ] && [ -n "$WEBDAV_USERNAME" ]; then
PLUGIN_USERNAME="$WEBDAV_USERNAME" PLUGIN_USERNAME="$WEBDAV_USERNAME"
fi fi
# Use WEBDAV_PASSWORD as default, if provided. # Use WEBDAV_PASSWORD as default, if provided.
if [ -z "$PLUGIN_PASSWORD" ] && [ ! -z "$WEBDAV_PASSWORD" ]; then if [ -z "$PLUGIN_PASSWORD" ] && [ -n "$WEBDAV_PASSWORD" ]; then
PLUGIN_PASSWORD="$WEBDAV_PASSWORD" PLUGIN_PASSWORD="$WEBDAV_PASSWORD"
fi fi
# If username and password are provided, add auth # If username and password are provided, add auth
if [ ! -z "$PLUGIN_USERNAME" ] && [ ! -z "$PLUGIN_PASSWORD" ]; then if [ -n "$PLUGIN_USERNAME" ] && [ -n "$PLUGIN_PASSWORD" ]; then
AUTH="--user '${PLUGIN_USERNAME}':'${PLUGIN_PASSWORD}'" AUTH="--user '${PLUGIN_USERNAME}:${PLUGIN_PASSWORD}'"
fi fi
# Use a proxy, if one is specified # Use a proxy, if one is specified
if [ ! -z "$PLUGIN_PROXY_URL" ]; then if [ -n "$PLUGIN_PROXY_URL" ]; then
PLUGIN_PROXY_URL="--proxy '${PLUGIN_PROXY_URL}'" PLUGIN_PROXY_URL="--proxy '${PLUGIN_PROXY_URL}'"
fi fi
# If a timeout is specified, make use of it. # If a timeout is specified, make use of it.
if [ ! -z "$PLUGIN_TIMEOUT" ]; then if [ -n "$PLUGIN_TIMEOUT" ]; then
PLUGIN_TIMEOUT="--max-time '${PLUGIN_TIMEOUT}'" PLUGIN_TIMEOUT="--max-time '${PLUGIN_TIMEOUT}'"
fi fi
@ -55,6 +55,7 @@ while [ "${PLUGIN_ATTEMPTS}" -gt 0 ]; do
} }
sleep 5
PLUGIN_ATTEMPTS=$((PLUGIN_ATTEMPTS-1)) PLUGIN_ATTEMPTS=$((PLUGIN_ATTEMPTS-1))
done done

View File

@ -0,0 +1,21 @@
---
version: '2.4'
services:
webdav:
image: sashgorokhov/webdav
environment:
USERNAME: jdoe
PASSWORD: hunter2
plugin:
build:
context: ../
dockerfile: Dockerfile
volumes:
- './test.txt:/test.txt'
environment:
PLUGIN_FILE: '/test.txt'
PLUGIN_DESTINATION: 'http://webdav/'
PLUGIN_USERNAME: jdoe
PLUGIN_PASSWORD: hunter2
PLUGIN_ATTEMPTS: 4

View File

@ -0,0 +1,16 @@
---
version: '2.4'
services:
webdav:
image: sashgorokhov/webdav
plugin:
build:
context: ../
dockerfile: Dockerfile
volumes:
- './test.txt:/test.txt'
environment:
PLUGIN_FILE: '/test.txt'
PLUGIN_DESTINATION: 'http://webdav/'
PLUGIN_ATTEMPTS: 4

1
tests/test.txt Normal file
View File

@ -0,0 +1 @@
ohai