github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/apigw/v2/app_code_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  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/app"
    10  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/apigw/v2/app_code"
    11  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    12  )
    13  
    14  func TestAppCodeLifecycle(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  	_, createAppResp := CreateApp(client, t, gatewayID)
    25  
    26  	t.Cleanup(func() {
    27  		th.AssertNoErr(t, app.Delete(client, gatewayID, createAppResp.ID))
    28  	})
    29  
    30  	createOpts := app_code.CreateOpts{
    31  		GatewayID: gatewayID,
    32  		AppID:     createAppResp.ID,
    33  		AppCode:   tools.RandomString("test", 61),
    34  	}
    35  
    36  	createResp, err := app_code.Create(client, createOpts)
    37  	th.AssertNoErr(t, err)
    38  
    39  	t.Cleanup(func() {
    40  		th.AssertNoErr(t, app_code.Delete(client, gatewayID, createAppResp.ID, createResp.ID))
    41  	})
    42  
    43  	tools.PrintResource(t, createResp)
    44  
    45  	generatedCode, err := app_code.GenerateAppCode(client, gatewayID, createAppResp.ID)
    46  	th.AssertNoErr(t, err)
    47  	tools.PrintResource(t, generatedCode)
    48  
    49  	getResp, err := app_code.Get(client, gatewayID, createAppResp.ID, generatedCode.ID)
    50  	th.AssertNoErr(t, err)
    51  	tools.PrintResource(t, getResp)
    52  
    53  	listResp, err := app_code.List(client, app_code.ListOpts{
    54  		GatewayID: gatewayID,
    55  	})
    56  	th.AssertNoErr(t, err)
    57  	tools.PrintResource(t, listResp)
    58  }