github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/internal/acceptance/openstack/networking/v2/extensions/qos/policies/policies.go (about)

     1  package policies
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/internal/acceptance/tools"
     9  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/networking/v2/extensions/qos/policies"
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  )
    12  
    13  // CreateQoSPolicy will create a QoS policy. An error will be returned if the
    14  // QoS policy could not be created.
    15  func CreateQoSPolicy(t *testing.T, client *gophercloud.ServiceClient) (*policies.Policy, error) {
    16  	policyName := tools.RandomString("TESTACC-", 8)
    17  	policyDescription := tools.RandomString("TESTACC-DESC-", 8)
    18  
    19  	createOpts := policies.CreateOpts{
    20  		Name:        policyName,
    21  		Description: policyDescription,
    22  	}
    23  
    24  	t.Logf("Attempting to create a QoS policy: %s", policyName)
    25  
    26  	policy, err := policies.Create(context.TODO(), client, createOpts).Extract()
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	t.Logf("Succesfully created a QoS policy")
    32  
    33  	th.AssertEquals(t, policyName, policy.Name)
    34  	th.AssertEquals(t, policyDescription, policy.Description)
    35  
    36  	return policy, nil
    37  }
    38  
    39  // DeleteQoSPolicy will delete a QoS policy with a specified ID.
    40  // A fatal error will occur if the delete was not successful.
    41  func DeleteQoSPolicy(t *testing.T, client *gophercloud.ServiceClient, policyID string) {
    42  	t.Logf("Attempting to delete the QoS policy: %s", policyID)
    43  
    44  	err := policies.Delete(context.TODO(), client, policyID).ExtractErr()
    45  	if err != nil {
    46  		t.Fatalf("Unable to delete QoS policy %s: %v", policyID, err)
    47  	}
    48  
    49  	t.Logf("Deleted QoS policy: %s", policyID)
    50  }