package openstack import ( "context" "os" "testing" "time" ) // TestClientLive is a smoke test against a real OpenStack deployment. It's // skipped unless OPENSTACK_LIVE_TEST=1 and the usual OS_* credential env // vars are set, so the default `go test ./...` run needs no cloud access. // It only exercises GetFloatingIPByAddress (read-only) against // OS_TEST_FLOATING_IP, to avoid mutating real infrastructure in CI. func TestClientLive(t *testing.T) { if os.Getenv("OPENSTACK_LIVE_TEST") != "1" { t.Skip("set OPENSTACK_LIVE_TEST=1 (and OS_AUTH_URL, OS_TOKEN, OS_TEST_FLOATING_IP) to run") } testIP := os.Getenv("OS_TEST_FLOATING_IP") if testIP == "" { t.Fatal("OS_TEST_FLOATING_IP must name a floating IP address that exists in the target project") } ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() client, err := NewClient(ctx, ClientConfig{ AuthURL: os.Getenv("OS_AUTH_URL"), Token: os.Getenv("OS_TOKEN"), ProjectID: os.Getenv("OS_PROJECT_ID"), ProjectName: os.Getenv("OS_PROJECT_NAME"), DomainName: os.Getenv("OS_PROJECT_DOMAIN_NAME"), Region: os.Getenv("OS_REGION_NAME"), }) if err != nil { t.Fatalf("new client: %v", err) } fip, err := client.GetFloatingIPByAddress(ctx, testIP) if err != nil { t.Fatalf("get floating ip %s: %v", testIP, err) } if fip.Address != testIP { t.Fatalf("expected address %s, got %s", testIP, fip.Address) } t.Logf("found floating ip %s: id=%s port_id=%q", fip.Address, fip.ID, fip.PortID) }