Skip to content

Commit

Permalink
[Test] Add and Refactor cluster tests
Browse files Browse the repository at this point in the history
  • Loading branch information
muneeb-jan committed Nov 28, 2024
1 parent b54177b commit ebba418
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
4 changes: 2 additions & 2 deletions acceptance/openstack/cce/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down
54 changes: 29 additions & 25 deletions acceptance/openstack/cce/v3/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Check failure on line 45 in acceptance/openstack/cce/v3/clusters_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ineffectual assignment to clusterID (ineffassign)
}
}

0 comments on commit ebba418

Please sign in to comment.