github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/apigw/v2/special_throttle_test.go (about)

     1  package v2
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
     9  	policy "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/tr_policy"
    10  	specials "github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/tr_specials"
    11  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    12  )
    13  
    14  func TestSpecialThrottleLifecycle(t *testing.T) {
    15  	gatewayID := os.Getenv("GATEWAY_ID")
    16  
    17  	if gatewayID == "" {
    18  		t.Skip("`GATEWAY_ID` needs to be defined")
    19  	}
    20  
    21  	client, err := clients.NewAPIGWClient()
    22  	th.AssertNoErr(t, err)
    23  
    24  	createPolicyResp := CreatePolicy(client, t, gatewayID)
    25  
    26  	t.Cleanup(func() {
    27  		th.AssertNoErr(t, policy.Delete(client, gatewayID, createPolicyResp.ID))
    28  	})
    29  
    30  	createOpts := specials.CreateOpts{
    31  		GatewayID:  gatewayID,
    32  		ThrottleID: createPolicyResp.ID,
    33  		CallLimits: 100,
    34  		ObjectType: "USER",
    35  		ObjectID:   "356de8eb7a8742168586e5daf5339965",
    36  	}
    37  
    38  	createResp, err := specials.Create(client, createOpts)
    39  	th.AssertNoErr(t, err)
    40  
    41  	t.Cleanup(func() {
    42  		th.AssertNoErr(t, specials.Delete(client, gatewayID, createPolicyResp.ID, createResp.ID))
    43  	})
    44  
    45  	tools.PrintResource(t, createResp)
    46  
    47  	updateOpts := specials.UpdateOpts{
    48  		GatewayID:       gatewayID,
    49  		ThrottleID:      createPolicyResp.ID,
    50  		SpecialPolicyID: createResp.ID,
    51  		CallLimits:      90,
    52  	}
    53  
    54  	updateResp, err := specials.Update(client, updateOpts)
    55  	th.AssertNoErr(t, err)
    56  
    57  	tools.PrintResource(t, updateResp)
    58  }
    59  
    60  func TestSpecialThrottleList(t *testing.T) {
    61  	gatewayID := os.Getenv("GATEWAY_ID")
    62  
    63  	if gatewayID == "" {
    64  		t.Skip("`GATEWAY_ID` needs to be defined")
    65  	}
    66  
    67  	client, err := clients.NewAPIGWClient()
    68  	th.AssertNoErr(t, err)
    69  
    70  	createPolicyResp := CreatePolicy(client, t, gatewayID)
    71  
    72  	t.Cleanup(func() {
    73  		th.AssertNoErr(t, policy.Delete(client, gatewayID, createPolicyResp.ID))
    74  	})
    75  
    76  	listResp, err := specials.List(client, specials.ListOpts{
    77  		GatewayID:  gatewayID,
    78  		ThrottleID: createPolicyResp.ID,
    79  	})
    80  	th.AssertNoErr(t, err)
    81  	tools.PrintResource(t, listResp)
    82  }