From d1eafdd6def96526653276d6ef00609888437d5a Mon Sep 17 00:00:00 2001 From: mkelvers Date: Sat, 4 Jul 2026 05:17:30 +0200 Subject: [PATCH] test: add isLocalClientIP tests --- internal/observability/localip_test.go | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/observability/localip_test.go diff --git a/internal/observability/localip_test.go b/internal/observability/localip_test.go new file mode 100644 index 00000000..c2fe1762 --- /dev/null +++ b/internal/observability/localip_test.go @@ -0,0 +1,27 @@ +package observability + +import ( + "testing" +) + +func TestIsLocalClientIPReturnsTrueForLoopback(t *testing.T) { + for _, ip := range []string{"127.0.0.1", "::1"} { + if !isLocalClientIP(ip) { + t.Fatalf("isLocalClientIP(%q) = false, want true", ip) + } + } +} + +func TestIsLocalClientIPReturnsFalseForExternal(t *testing.T) { + for _, ip := range []string{"8.8.8.8", "192.168.1.1", ""} { + if isLocalClientIP(ip) { + t.Fatalf("isLocalClientIP(%q) = true, want false", ip) + } + } +} + +func TestIsLocalClientIPReturnsFalseForInvalid(t *testing.T) { + if isLocalClientIP("not-an-ip") { + t.Fatal("isLocalClientIP('not-an-ip') = true, want false") + } +}