github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-redis/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  export REDIS_PASSWORD=passpass
    20  image=redis:6
    21  port=16379
    22  
    23  docker run --name "test-$plugin" -p $port:6379 -d $image --requirepass $REDIS_PASSWORD
    24  trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
    25  sleep 10
    26  
    27  # to store previous value to calculate a diff of metrics
    28  $plugin -port $port >/dev/null 2>&1
    29  sleep 1
    30  
    31  $plugin -port $port | graphite-metric-test -f rule.txt
    32  status=$?
    33  
    34  docker stop "test-$plugin"
    35  docker rm "test-$plugin"
    36  exit $status