Skip to content

Commit

Permalink
Merge pull request #654 from lufia/add-test-mongodb
Browse files Browse the repository at this point in the history
[plugin-mongodb] add test.sh
  • Loading branch information
lufia committed Jul 29, 2020
2 parents f82b4c7 + 34878b9 commit e3c8d01
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mackerel-plugin-accesslog/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

prog=$(basename $0)
cd $(dirname $0)
PATH=$(pwd):$PATH
plugin=$(basename $(pwd))
if ! which -s $plugin
then
Expand All @@ -11,7 +12,7 @@ fi

for i in lib/testdata/*.*
do
if $plugin -no-posfile $i >/dev/null 2>&1; then
if $plugin -no-posfile $i; then
echo OK: $i
else
echo FAIL: $i
Expand Down
3 changes: 2 additions & 1 deletion mackerel-plugin-docker/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ then
fi

cd $(dirname $0)
PATH=$(pwd):$PATH
plugin=$(basename $(pwd))
if ! which -s $plugin
then
echo "$prog: $plugin is not installed" >&2
exit 2
fi

if $plugin >/dev/null 2>&1; then
if $plugin; then
echo OK
else
echo FAIL
Expand Down
11 changes: 11 additions & 0 deletions mackerel-plugin-mongodb/UPDATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to check the plugin

## Requirements

* dockerd

## Steps

* Run mongo:3-xenial
* Run the plugin standalone
* Check the exit code
36 changes: 36 additions & 0 deletions mackerel-plugin-mongodb/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

prog=$(basename $0)
if ! [[ -S /var/run/docker.sock ]]
then
echo "$prog: there are no running docker" >&2
exit 2
fi

cd $(dirname $0)
PATH=$(pwd):$PATH
plugin=$(basename $(pwd))
if ! which -s $plugin
then
echo "$prog: $plugin is not installed" >&2
exit 2
fi

user=root
password=passpass
port=27017
docker run -d \
--name test-$plugin \
-p $port:$port \
-e MONGO_INITDB_ROOT_USERNAME=$user \
-e MONGO_INITDB_ROOT_PASSWORD=$password \
mongo:3-xenial
trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT
sleep 10

if $plugin -port $port -username=$user -password $password
then
echo OK
else
echo FAIL
fi
3 changes: 2 additions & 1 deletion mackerel-plugin-openldap/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ then
fi

cd $(dirname $0)
PATH=$(pwd):$PATH
plugin=$(basename $(pwd))
if ! which -s $plugin
then
Expand All @@ -24,7 +25,7 @@ trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT
sleep 10

base_dn='dc=example,dc=org'
if $plugin -bind "cn=monitor,$base_dn" -pw passpass >/dev/null 2>&1
if $plugin -bind "cn=monitor,$base_dn" -pw passpass
then
echo OK
else
Expand Down
3 changes: 2 additions & 1 deletion mackerel-plugin-postgres/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ then
fi

cd $(dirname $0)
PATH=$(pwd):$PATH
plugin=$(basename $(pwd))
if ! which -s $plugin
then
Expand All @@ -24,7 +25,7 @@ docker run -d \
trap 'docker stop test-$plugin; docker rm test-$plugin; exit' EXIT
sleep 10

if $plugin -port 15432 -user=$user -password $password >/dev/null 2>&1
if $plugin -port 15432 -user=$user -password $password
then
echo OK
else
Expand Down

0 comments on commit e3c8d01

Please sign in to comment.