From 5e0ba186fc8651ba11899e713ae220996d558f30 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:04:24 +0200 Subject: [PATCH] add testing variables --- e2e_test/combined_test.go | 4 +-- e2e_test/datacenter_test.go | 2 +- e2e_test/e2e_test.go | 2 +- e2e_test/firewall_test.go | 2 +- e2e_test/floatingip_test.go | 10 ++++---- e2e_test/network_test.go | 2 +- e2e_test/placement_group_test.go | 2 +- e2e_test/server_test.go | 2 +- e2e_test/variables.go | 42 ++++++++++++++++++++++++++++++++ 9 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 e2e_test/variables.go diff --git a/e2e_test/combined_test.go b/e2e_test/combined_test.go index af62376f..574595f6 100644 --- a/e2e_test/combined_test.go +++ b/e2e_test/combined_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "fmt" @@ -13,7 +13,7 @@ import ( func TestCombined(t *testing.T) { // combined tests combine multiple resources and can thus not be run in parallel - serverID := createServer(t, "test-server", "cpx11", "ubuntu-24.04") + serverID := createServer(t, "test-server", TestServerType, TestImage) firewallID, err := createFirewall(t, "test-firewall") if err != nil { diff --git a/e2e_test/datacenter_test.go b/e2e_test/datacenter_test.go index 10ba8359..48ea22ab 100644 --- a/e2e_test/datacenter_test.go +++ b/e2e_test/datacenter_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "encoding/json" diff --git a/e2e_test/e2e_test.go b/e2e_test/e2e_test.go index 6f16384c..31d9e123 100644 --- a/e2e_test/e2e_test.go +++ b/e2e_test/e2e_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "bytes" diff --git a/e2e_test/firewall_test.go b/e2e_test/firewall_test.go index 0420bf3b..16b42115 100644 --- a/e2e_test/firewall_test.go +++ b/e2e_test/firewall_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "fmt" diff --git a/e2e_test/floatingip_test.go b/e2e_test/floatingip_test.go index beb9034c..559c9ed9 100644 --- a/e2e_test/floatingip_test.go +++ b/e2e_test/floatingip_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "fmt" @@ -26,7 +26,7 @@ func TestFloatingIP(t *testing.T) { _, err = createFloatingIP(t, "ipv4", "--server", "non-existing-server") require.EqualError(t, err, "server not found: non-existing-server") - floatingIPId, err := createFloatingIP(t, "ipv4", "--home-location", "fsn1") + floatingIPId, err := createFloatingIP(t, "ipv4", "--home-location", TestLocationName) if err != nil { t.Fatal(err) } @@ -135,7 +135,7 @@ $`, out) ], "home_location": { "id": 1, - "name": "fsn1", + "name": "%s", "description": "Falkenstein DC Park 1", "country": "DE", "city": "Falkenstein", @@ -153,7 +153,7 @@ $`, out) "name": "new-test-floating-ip" } ] -`, floatingIPId, ipStr, ipStr)), []byte(out)) +`, floatingIPId, ipStr, ipStr, TestLocationName)), []byte(out)) out, err = runCommand(t, "floating-ip", "delete", strconv.Itoa(floatingIPId)) assert.Regexp(t, `^Floating IP deletion is protected \(protected, [0-9a-f]+\)$`, err.Error()) @@ -183,7 +183,7 @@ $`, out) require.NoError(t, err) assert.Equal(t, fmt.Sprintf("Floating IP %d deleted\n", floatingIPId), out) - floatingIPId, err = createFloatingIP(t, "ipv6", "--home-location", "fsn1") + floatingIPId, err = createFloatingIP(t, "ipv6", "--home-location", TestLocationName) if err != nil { t.Fatal(err) } diff --git a/e2e_test/network_test.go b/e2e_test/network_test.go index 241b9bc4..c6c1a769 100644 --- a/e2e_test/network_test.go +++ b/e2e_test/network_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "fmt" diff --git a/e2e_test/placement_group_test.go b/e2e_test/placement_group_test.go index d98c2d3a..47a61ccc 100644 --- a/e2e_test/placement_group_test.go +++ b/e2e_test/placement_group_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "fmt" diff --git a/e2e_test/server_test.go b/e2e_test/server_test.go index ab5eedee..4509e6a6 100644 --- a/e2e_test/server_test.go +++ b/e2e_test/server_test.go @@ -1,6 +1,6 @@ //go:build e2e -package e2e_test +package e2e import ( "strconv" diff --git a/e2e_test/variables.go b/e2e_test/variables.go new file mode 100644 index 00000000..02ec8958 --- /dev/null +++ b/e2e_test/variables.go @@ -0,0 +1,42 @@ +//go:build e2e + +package e2e + +import ( + "os" + + "github.com/hetznercloud/hcloud-go/v2/hcloud" +) + +var ( + // TestImage is the system image that is used in end-to-end tests. + TestImage = getEnv("TEST_IMAGE", "ubuntu-24.04") + + // TestImageID is the system image ID that is used in end-to-end tests. + TestImageID = getEnv("TEST_IMAGE_ID", "161547269") + + // TestServerType is the default server type used in end-to-end tests. + TestServerType = getEnv("TEST_SERVER_TYPE", "cpx11") + + // TestServerTypeUpgrade is the upgrade server type used in end-to-end tests. + TestServerTypeUpgrade = getEnv("TEST_SERVER_TYPE_UPGRADE", "cpx21") + + // TestArchitecture is the default architecture used in end-to-end tests, should match the architecture of the TestServerType. + TestArchitecture = getEnv("TEST_ARCHITECTURE", string(hcloud.ArchitectureX86)) + + // TestLoadBalancerType is the default Load Balancer type used in end-to-end tests. + TestLoadBalancerType = "lb11" + + // TestDataCenter is the default datacenter where we execute our end-to-end tests. + TestDataCenter = getEnv("TEST_DATACENTER", "nbg1-dc3") + + // TestLocationName is the default location where we execute our end-to-end tests. + TestLocationName = getEnv("TEST_LOCATION", "nbg1") +) + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +}