From ebba418597c8b81b68d477629340cc4fb793487e Mon Sep 17 00:00:00 2001 From: "Muneeb H. Jan" Date: Thu, 28 Nov 2024 12:03:41 +0100 Subject: [PATCH] [Test] Add and Refactor cluster tests --- acceptance/openstack/cce/helpers.go | 4 +- acceptance/openstack/cce/v3/clusters_test.go | 54 +++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/acceptance/openstack/cce/helpers.go b/acceptance/openstack/cce/helpers.go index a26390beb..a2a07edf5 100644 --- a/acceptance/openstack/cce/helpers.go +++ b/acceptance/openstack/cce/helpers.go @@ -51,7 +51,7 @@ func CreateCluster(t *testing.T, vpcID, subnetID string) string { return cluster.Metadata.Id } -func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string, eniCidr string) string { +func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string, eniCidr string) *clusters.Clusters { client, err := clients.NewCceV3Client() th.AssertNoErr(t, err) @@ -86,7 +86,7 @@ func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string th.AssertNoErr(t, err) th.AssertNoErr(t, waitForClusterToActivate(client, cluster.Metadata.Id, 30*60)) - return cluster.Metadata.Id + return cluster } func DeleteCluster(t *testing.T, clusterID string) { diff --git a/acceptance/openstack/cce/v3/clusters_test.go b/acceptance/openstack/cce/v3/clusters_test.go index 62cf24cf7..f3b0dcc78 100644 --- a/acceptance/openstack/cce/v3/clusters_test.go +++ b/acceptance/openstack/cce/v3/clusters_test.go @@ -5,39 +5,43 @@ import ( "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/cce" - "github.com/stretchr/testify/suite" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters" + th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" ) -type testCluster struct { - suite.Suite +func TestListCluster(t *testing.T) { + client, err := clients.NewCceV3Client() + th.AssertNoErr(t, err) - vpcID string - subnetID string - clusterID string - eniSubnetID string - eniCidr string + _, err = clusters.List(client, clusters.ListOpts{}) + th.AssertNoErr(t, err) } func TestCluster(t *testing.T) { - suite.Run(t, new(testCluster)) -} - -func (s *testCluster) SetupSuite() { - t := s.T() - s.vpcID = clients.EnvOS.GetEnv("VPC_ID") - s.subnetID = clients.EnvOS.GetEnv("NETWORK_ID") - s.eniSubnetID = clients.EnvOS.GetEnv("ENI_SUBNET_ID") - s.eniCidr = "10.0.0.0/14" - if s.vpcID == "" || s.subnetID == "" || s.eniSubnetID == "" { + vpcID := clients.EnvOS.GetEnv("VPC_ID") + subnetID := clients.EnvOS.GetEnv("NETWORK_ID") + eniSubnetID := clients.EnvOS.GetEnv("ENI_SUBNET_ID") + eniCidr := clients.EnvOS.GetEnv("ENI_SUBNET_CIDR") + if vpcID == "" || subnetID == "" || eniSubnetID == "" { t.Skip("OS_VPC_ID, OS_NETWORK_ID and OS_ENI_SUBNET_ID are required for this test") } - s.clusterID = cce.CreateTurboCluster(t, s.vpcID, s.subnetID, s.eniSubnetID, s.eniCidr) -} + if eniCidr == "" { + eniCidr = "192.168.0.0/24" + } + + client, err := clients.NewCceV3Client() + th.AssertNoErr(t, err) + + cluster := cce.CreateTurboCluster(t, vpcID, subnetID, eniSubnetID, eniCidr) + + clusterID := cluster.Metadata.Id + + clusterGet, err := clusters.Get(client, clusterID) + th.AssertNoErr(t, err) + th.AssertEquals(t, cluster.Metadata.Name, clusterGet.Metadata.Name) -func (s *testCluster) TearDownSuite() { - t := s.T() - if s.clusterID != "" { - cce.DeleteCluster(t, s.clusterID) - s.clusterID = "" + if clusterID != "" { + cce.DeleteCluster(t, clusterID) + clusterID = "" } }