79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
// This file is part of the happyDomain (R) project.
|
|
// Copyright (c) 2020-2026 happyDomain
|
|
// Authors: Pierre-Olivier Mercier, et al.
|
|
|
|
package checker
|
|
|
|
import (
|
|
"testing"
|
|
|
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
|
)
|
|
|
|
func TestReachabilityRule_NoProbes(t *testing.T) {
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
states := runRule(t, r, &HTTPData{}, nil)
|
|
mustStatus(t, states, sdk.StatusUnknown)
|
|
if !hasCode(states, "https.tcp_reachable.no_probes") {
|
|
t.Errorf("expected no_probes code: %+v", states)
|
|
}
|
|
}
|
|
|
|
func TestReachabilityRule_AllOK(t *testing.T) {
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
data := &HTTPData{Probes: []HTTPProbe{httpsProbe("a:443"), httpsProbe("b:443")}}
|
|
states := runRule(t, r, data, nil)
|
|
mustStatus(t, states, sdk.StatusOK)
|
|
if !hasCode(states, "https.tcp_reachable.ok") {
|
|
t.Errorf("expected ok code: %+v", states)
|
|
}
|
|
}
|
|
|
|
func TestReachabilityRule_Unreachable(t *testing.T) {
|
|
p := httpsProbe("a:443")
|
|
p.TCPConnected = false
|
|
p.StatusCode = 0
|
|
p.Error = "i/o timeout"
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
states := runRule(t, r, &HTTPData{Probes: []HTTPProbe{p}}, nil)
|
|
mustStatus(t, states, sdk.StatusCrit)
|
|
if !hasCode(states, "https.tcp_reachable.unreachable") {
|
|
t.Errorf("expected unreachable: %+v", states)
|
|
}
|
|
}
|
|
|
|
func TestReachabilityRule_NoResponse(t *testing.T) {
|
|
p := httpsProbe("a:443")
|
|
p.StatusCode = 0
|
|
p.Error = "EOF"
|
|
// TCPConnected stays true (connection accepted, no HTTP response).
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
states := runRule(t, r, &HTTPData{Probes: []HTTPProbe{p}}, nil)
|
|
mustStatus(t, states, sdk.StatusCrit)
|
|
if !hasCode(states, "https.tcp_reachable.no_response") {
|
|
t.Errorf("expected no_response: %+v", states)
|
|
}
|
|
}
|
|
|
|
func TestReachabilityRule_5xx(t *testing.T) {
|
|
p := httpsProbe("a:443")
|
|
p.StatusCode = 502
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
states := runRule(t, r, &HTTPData{Probes: []HTTPProbe{p}}, nil)
|
|
mustStatus(t, states, sdk.StatusWarn)
|
|
if !hasCode(states, "https.tcp_reachable.server_error") {
|
|
t.Errorf("expected server_error: %+v", states)
|
|
}
|
|
}
|
|
|
|
func TestReachabilityRule_FiltersByScheme(t *testing.T) {
|
|
// An HTTP failure should not surface in the HTTPS reachability rule.
|
|
pHTTPS := httpsProbe("a:443")
|
|
pHTTP := httpProbe("a:80")
|
|
pHTTP.TCPConnected = false
|
|
pHTTP.StatusCode = 0
|
|
|
|
r := &reachabilityRule{scheme: "https", code: "https.tcp_reachable"}
|
|
states := runRule(t, r, &HTTPData{Probes: []HTTPProbe{pHTTPS, pHTTP}}, nil)
|
|
mustStatus(t, states, sdk.StatusOK)
|
|
}
|