Update nat_test.go

This commit is contained in:
crStiv 2024-12-27 02:46:38 +01:00 committed by GitHub
parent 0b542721e9
commit 39101e314f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,11 +18,12 @@ package nat
import ( import (
"net" "net"
"os"
"testing" "testing"
"time" "time"
) )
// This test checks that autodisc doesn't hang and returns // This test ensures that autodisc doesn't hang and returns
// consistent results when multiple goroutines call its methods // consistent results when multiple goroutines call its methods
// concurrently. // concurrently.
func TestAutoDiscRace(t *testing.T) { func TestAutoDiscRace(t *testing.T) {
@ -61,3 +62,21 @@ func TestAutoDiscRace(t *testing.T) {
} }
} }
} }
func TestExtIPInKubernetes(t *testing.T) {
// Setting up the test environment
os.Setenv("KUBERNETES_SERVICE_HOST", "10.0.0.1")
defer os.Unsetenv("KUBERNETES_SERVICE_HOST")
testIP := net.ParseIP("192.0.2.1")
extIP := ExtIP(testIP)
// Verify that the IP is returned unchanged in Kubernetes
ip, err := extIP.ExternalIP()
if err != nil {
t.Fatalf("ExternalIP failed: %v", err)
}
if !ip.Equal(testIP) {
t.Errorf("wrong IP: got %v, want %v", ip, testIP)
}
}