Skip to content
Snippets Groups Projects
Commit 6c04a969 authored by ale's avatar ale
Browse files

Merge branch 'integration-tests' into 'master'

Add an integration test with a simple HTTP probe

See merge request !14
parents 171843a2 6379502a
Branches
No related tags found
1 merge request!14Add an integration test with a simple HTTP probe
Pipeline #56981 passed
include:
- "https://git.autistici.org/pipelines/containers/raw/master/common.yml"
- "https://git.autistici.org/ai3/docker/test/golang/raw/master/ci.yml"
ctest-http:
image: registry.git.autistici.org/ai3/docker/test/float-like-podman:master
stage: container-test
tags: [podman]
variables:
URL: https://www.incal.net/
script:
- sed -e "s,@URL@,$URL,g" < test/http/config.json > config.json
- with-container --mount=type=bind,source=$PWD/config.json,destination=/etc/service-prober.json --env=SERVICE_PROBER_CONFIG=/etc/service-prober.json --env=SERVICE_PROBER_HTTP_ADDR=:5521 --expose=5521 $IMAGE_TAG ./test/test.sh
......@@ -21,12 +21,19 @@ import (
_ "git.autistici.org/ai3/tools/service-prober/probes/openvpn"
)
func getenvDef(key, def string) string {
if s := os.Getenv(key); s != "" {
return s
}
return def
}
var (
config = flag.String("config", "", "configuration file `path`")
config = flag.String("config", os.Getenv("SERVICE_PROBER_CONFIG"), "configuration file `path`")
oneshot = flag.Bool("oneshot", false, "run just one shot and exit")
validate = flag.Bool("validate", false, "just validate the configuration syntax")
only = flag.String("only", "", "only run probes with names matching this `regex`")
httpAddr = flag.String("http-addr", ":5522", "`address` for the HTTP server")
only = flag.String("only", os.Getenv("SERVICE_PROBER_ONLY"), "only run probes with names matching this `regex`")
httpAddr = flag.String("http-addr", getenvDef("SERVICE_PROBER_HTTP_ADDR", ":5522"), "`address` for the HTTP server")
keepResults = flag.Int("keep-results", 100, "keep `N` results of past probes in memory")
)
......
{
"vars": {},
"probes": [
{
"type": "http",
"name": "test",
"interval": "1m",
"timeout": "1m",
"params": {
"script": [
{
"type": "open",
"url": "@URL@",
"expected_url": "@URL@"
}
]
}
}
]
}
#!/bin/sh
value=$(curl -sf http://localhost:5521/metrics | awk '/^probe_success/ {print $2}')
case "$value" in
1)
echo "success!" >&2
exit 0
;;
0)
echo "probe has failed" >&2
exit 2
;;
esac
# No probe_success value, or connection error. Retry.
exit 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment