66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
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.
|
|
//
|
|
// 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.
|
|
func TestClientLive(t *testing.T) {
|
|
if os.Getenv("OPENSTACK_LIVE_TEST") != "1" {
|
|
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")
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
client, err := NewClient(ctx, cfg)
|
|
if err != nil {
|
|
t.Fatalf("new client (method=%s): %v", cfg.Method, 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 (auth method=%s)", fip.Address, fip.ID, fip.PortID, cfg.Method)
|
|
}
|