Skip to content

Commit

Permalink
added test for plack
Browse files Browse the repository at this point in the history
  • Loading branch information
yseto committed Aug 26, 2022
1 parent f547b09 commit 454901d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mackerel-plugin-plack/rule.txt
@@ -0,0 +1,4 @@
plack.workers.busy_workers >=0
plack.workers.idle_workers >=0
plack.req.requests >=0
plack.bytes.bytes_sent >=0
37 changes: 37 additions & 0 deletions mackerel-plugin-plack/test.sh
@@ -0,0 +1,37 @@
#!/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")" || exit
PATH=$(pwd):$PATH
plugin=$(basename "$(pwd)")
if ! which "$plugin" >/dev/null
then
echo "$prog: $plugin is not installed" >&2
exit 2
fi

image=local/test-$plugin
port=5000

docker build -t $image testdata/

docker run --name "test-$plugin" -p $port:5000 -d $image
trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
sleep 10

# to store previous value to calculate a diff of metrics
$plugin -port $port >/dev/null 2>&1
sleep 1

$plugin -port $port | graphite-metric-test -f rule.txt
status=$?

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
14 changes: 14 additions & 0 deletions mackerel-plugin-plack/testdata/Dockerfile
@@ -0,0 +1,14 @@
FROM perl:5.36

COPY . /usr/src/myapp
WORKDIR /usr/src/myapp

RUN cpm install -v

EXPOSE 5000

ENV PERL5LIB /usr/src/myapp/local/lib/perl5
ENV PATH $PATH:/usr/src/myapp/local/bin/

CMD [ "plackup", "app.psgi" ]

20 changes: 20 additions & 0 deletions mackerel-plugin-plack/testdata/app.psgi
@@ -0,0 +1,20 @@
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;

use Plack::Builder;

builder {
enable "Plack::Middleware::ServerStatus::Lite",
path => '/server-status',
allow => [ '0.0.0.0/0' ],
counter_file => '/tmp/counter_file',
scoreboard => '/var/run/server';

sub {
[200, ["Content-Type" => "text/plain"], "ok"];
}
};

2 changes: 2 additions & 0 deletions mackerel-plugin-plack/testdata/cpanfile
@@ -0,0 +1,2 @@
requires "Plack", ">= 1.0048";
requires "Plack::Middleware::ServerStatus::Lite", "0.36";

0 comments on commit 454901d

Please sign in to comment.