Files

65 lines
2.1 KiB
Go
Raw Permalink Normal View History

2026-08-21 07:34:45 +03:00
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.
2026-08-21 09:58:08 +03:00
//
// OS_AUTH_METHOD selects which credential shape to test: "token" (default)
// reads OS_TOKEN and exercises the passthrough path; "password" reads
// OS_USERNAME/OS_PASSWORD/OS_USER_DOMAIN_NAME and exercises the
// auto-obtain/auto-reauth path. Run once per method to validate both
// against the real deployment.
2026-08-21 07:34:45 +03:00
func TestClientLive(t *testing.T) {
if os.Getenv("OPENSTACK_LIVE_TEST") != "1" {
2026-08-21 09:58:08 +03:00
t.Skip("set OPENSTACK_LIVE_TEST=1 (and OS_AUTH_URL, OS_PROJECT_ID, OS_TEST_FLOATING_IP, plus either OS_TOKEN or OS_USERNAME/OS_PASSWORD/OS_USER_DOMAIN_NAME) to run")
2026-08-21 07:34:45 +03:00
}
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")
}
2026-08-21 09:58:08 +03:00
cfg := ClientConfig{
AuthURL: os.Getenv("OS_AUTH_URL"),
ProjectID: os.Getenv("OS_PROJECT_ID"),
Region: os.Getenv("OS_REGION_NAME"),
Interface: os.Getenv("OS_INTERFACE"),
}
switch os.Getenv("OS_AUTH_METHOD") {
case "password":
cfg.Method = AuthMethodPassword
cfg.Username = os.Getenv("OS_USERNAME")
cfg.Password = os.Getenv("OS_PASSWORD")
cfg.UserDomainName = os.Getenv("OS_USER_DOMAIN_NAME")
default:
cfg.Method = AuthMethodToken
cfg.Token = os.Getenv("OS_TOKEN")
}
2026-08-21 07:34:45 +03:00
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
2026-08-21 09:58:08 +03:00
client, err := NewClient(ctx, cfg)
2026-08-21 07:34:45 +03:00
if err != nil {
2026-08-21 09:58:08 +03:00
t.Fatalf("new client (method=%s): %v", cfg.Method, err)
2026-08-21 07:34:45 +03:00
}
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)
}
2026-08-21 09:58:08 +03:00
t.Logf("found floating ip %s: id=%s port_id=%q (auth method=%s)", fip.Address, fip.ID, fip.PortID, cfg.Method)
2026-08-21 07:34:45 +03:00
}