Files
privatae-bastion/client-go/status_liveness_test.go
T
Privatae e4c9b69b46
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m4s
ci / fuzz (push) Successful in 3m45s
bastion 0.53.2
2026-10-20 04:42:14 +00:00

47 lines
1.3 KiB
Go

//go:build !windows
package main
import (
"net"
"os"
"testing"
)
// cmdStatus must actually answer "is it running", not just print pairings.
// Drives the real liveness probe against a real listener rather than asserting
// the string, because the probe is the part that can be wrong.
func TestStatusReportsWhetherItIsRunning(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
writePairing(t, tAnchor)
cfgs, err := loadPairings()
if err != nil || len(cfgs) == 0 {
t.Fatalf("setup: %v", err)
}
// writePairing leaves ListenAddr empty; give it one nothing is on.
if err := cfgs[0].updateOnDisk(func(d *Config) { d.ListenAddr = "127.0.0.1:53999" }); err != nil {
t.Fatal(err)
}
if bastionListening("127.0.0.1:53999") {
t.Fatal("nothing should be listening on the probe port yet")
}
if bastionListening("") {
t.Fatal("an empty address must never read as running")
}
ln, err := net.Listen("tcp", "127.0.0.1:53999")
if err != nil {
t.Skipf("cannot bind the probe port here: %v", err)
}
defer ln.Close()
if !bastionListening("127.0.0.1:53999") {
t.Fatal("a real listener must read as running — this is the whole probe")
}
// And cmdStatus itself must not explode on either path.
if err := cmdStatus(); err != nil {
t.Fatalf("status must not error while running: %v", err)
}
_ = os.Stdout
}