github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-plack/test.sh (about)

     1  #!/bin/sh
     2  
     3  prog=$(basename "$0")
     4  if ! [ -S /var/run/docker.sock ]
     5  then
     6  	echo "$prog: there are no running docker" >&2
     7  	exit 2
     8  fi
     9  
    10  cd "$(dirname "$0")" || exit
    11  PATH=$(pwd):$PATH
    12  plugin=$(basename "$(pwd)")
    13  if ! which "$plugin" >/dev/null
    14  then
    15  	echo "$prog: $plugin is not installed" >&2
    16  	exit 2
    17  fi
    18  
    19  image=local/test-$plugin
    20  port=5000
    21  
    22  docker build -t $image testdata/
    23  
    24  docker run --name "test-$plugin" -p $port:5000 -d $image
    25  trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
    26  sleep 10
    27  
    28  # to store previous value to calculate a diff of metrics
    29  $plugin -port $port >/dev/null 2>&1
    30  sleep 1
    31  
    32  $plugin -port $port | graphite-metric-test -f rule.txt
    33  status=$?
    34  
    35  docker stop "test-$plugin"
    36  docker rm "test-$plugin"
    37  exit $status