github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/internal/acceptance/openstack/containerinfra/v1/clustertemplates_test.go (about)

     1  //go:build acceptance || containerinfra || clustertemplates
     2  
     3  package v1
     4  
     5  import (
     6  	"context"
     7  	"testing"
     8  
     9  	"github.com/vnpaycloud-console/gophercloud/v2/internal/acceptance/clients"
    10  	"github.com/vnpaycloud-console/gophercloud/v2/internal/acceptance/tools"
    11  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/containerinfra/v1/clustertemplates"
    12  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    13  )
    14  
    15  func TestClusterTemplatesCRUD(t *testing.T) {
    16  	client, err := clients.NewContainerInfraV1Client()
    17  	th.AssertNoErr(t, err)
    18  
    19  	clusterTemplate, err := CreateKubernetesClusterTemplate(t, client)
    20  	th.AssertNoErr(t, err)
    21  	t.Log(clusterTemplate.Name)
    22  
    23  	defer DeleteClusterTemplate(t, client, clusterTemplate.UUID)
    24  
    25  	// Test clusters list
    26  	allPages, err := clustertemplates.List(client, nil).AllPages(context.TODO())
    27  	th.AssertNoErr(t, err)
    28  
    29  	allClusterTemplates, err := clustertemplates.ExtractClusterTemplates(allPages)
    30  	th.AssertNoErr(t, err)
    31  
    32  	var found bool
    33  	for _, v := range allClusterTemplates {
    34  		if v.UUID == clusterTemplate.UUID {
    35  			found = true
    36  		}
    37  	}
    38  
    39  	th.AssertEquals(t, found, true)
    40  
    41  	template, err := clustertemplates.Get(context.TODO(), client, clusterTemplate.UUID).Extract()
    42  	th.AssertNoErr(t, err)
    43  	th.AssertEquals(t, clusterTemplate.UUID, template.UUID)
    44  
    45  	// Test cluster update
    46  	updateOpts := []clustertemplates.UpdateOptsBuilder{
    47  		clustertemplates.UpdateOpts{
    48  			Op:    clustertemplates.ReplaceOp,
    49  			Path:  "/master_lb_enabled",
    50  			Value: "false",
    51  		},
    52  		clustertemplates.UpdateOpts{
    53  			Op:    clustertemplates.ReplaceOp,
    54  			Path:  "/registry_enabled",
    55  			Value: "false",
    56  		},
    57  		clustertemplates.UpdateOpts{
    58  			Op:    clustertemplates.AddOp,
    59  			Path:  "/labels/test",
    60  			Value: "test",
    61  		},
    62  	}
    63  
    64  	updateClusterTemplate, err := clustertemplates.Update(context.TODO(), client, clusterTemplate.UUID, updateOpts).Extract()
    65  	th.AssertNoErr(t, err)
    66  	th.AssertEquals(t, false, updateClusterTemplate.MasterLBEnabled)
    67  	th.AssertEquals(t, false, updateClusterTemplate.RegistryEnabled)
    68  	th.AssertEquals(t, "test", updateClusterTemplate.Labels["test"])
    69  	tools.PrintResource(t, updateClusterTemplate)
    70  
    71  }