github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/cce/v3/kubeconfig_test.go (about)

     1  package v3
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/cce"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters"
     9  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    10  	"github.com/stretchr/testify/require"
    11  	"github.com/stretchr/testify/suite"
    12  )
    13  
    14  type testKubeConfig struct {
    15  	suite.Suite
    16  
    17  	routerID  string
    18  	subnetID  string
    19  	clusterID string
    20  }
    21  
    22  func TestKubeConfig(t *testing.T) {
    23  	suite.Run(t, new(testKubeConfig))
    24  }
    25  
    26  func (s *testKubeConfig) SetupSuite() {
    27  	t := s.T()
    28  	s.routerID = clients.EnvOS.GetEnv("VPC_ID", "ROUTER_ID")
    29  	s.subnetID = clients.EnvOS.GetEnv("NETWORK_ID")
    30  	if s.routerID == "" || s.subnetID == "" {
    31  		t.Skip("OS_ROUTER_ID and OS_NETWORK_ID are required for this test")
    32  	}
    33  	s.clusterID = cce.CreateCluster(t, s.routerID, s.subnetID)
    34  }
    35  
    36  func (s *testKubeConfig) TearDownSuite() {
    37  	t := s.T()
    38  	if s.clusterID != "" {
    39  		cce.DeleteCluster(t, s.clusterID)
    40  		s.clusterID = ""
    41  	}
    42  }
    43  
    44  func (s *testKubeConfig) TestKubeConfigReading() {
    45  	t := s.T()
    46  
    47  	client, err := clients.NewCceV3Client()
    48  	th.AssertNoErr(t, err)
    49  
    50  	kubeConfig, err := clusters.GetCert(client, s.clusterID).ExtractMap()
    51  	th.AssertNoErr(t, err)
    52  	require.NotEmpty(t, kubeConfig)
    53  
    54  	kubeConfigExp, err := clusters.GetCertWithExpiration(client, s.clusterID, clusters.ExpirationOpts{
    55  		Duration: 5,
    56  	}).ExtractMap()
    57  	th.AssertNoErr(t, err)
    58  	require.NotEmpty(t, kubeConfigExp)
    59  }