github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-squid/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=ubuntu/squid:5.2-22.04_beta
    20  port=13128
    21  
    22  docker run --name "test-$plugin" -p $port:3128 -v $(pwd)/testdata/squid.conf:/etc/squid/squid.conf:ro -d $image
    23  trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
    24  sleep 10
    25  
    26  # to store previous value to calculate a diff of metrics
    27  $plugin -port $port >/dev/null 2>&1
    28  sleep 1
    29  
    30  $plugin -port $port | graphite-metric-test -f rule.txt
    31  status=$?
    32  
    33  docker stop "test-$plugin"
    34  docker rm "test-$plugin"
    35  exit $status