github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/fgs/v2/alias_test.go (about) 1 package v2 2 3 import ( 4 "strings" 5 "testing" 6 7 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/fgs/v2/alias" 11 "github.com/opentelekomcloud/gophertelekomcloud/openstack/fgs/v2/function" 12 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 13 ) 14 15 func TestFunctionGraphListAliases(t *testing.T) { 16 client, err := clients.NewFuncGraphClient() 17 th.AssertNoErr(t, err) 18 19 createResp, _ := createFunctionGraph(t, client) 20 funcUrn := strings.TrimSuffix(createResp.FuncURN, ":latest") 21 22 defer func(client *golangsdk.ServiceClient, id string) { 23 err = function.Delete(client, id) 24 th.AssertNoErr(t, err) 25 }(client, funcUrn) 26 27 publishOpts := alias.PublishOpts{ 28 FuncUrn: funcUrn, 29 Version: "new-version", 30 Description: "terraform", 31 } 32 33 publishOptsResp, err := alias.PublishVersion(client, publishOpts) 34 th.AssertNoErr(t, err) 35 36 createAliasOpts := alias.CreateAliasOpts{ 37 Name: "test-alias", 38 Version: "new-version", 39 Description: "terraform alias", 40 FuncUrn: publishOptsResp.FuncURN, 41 } 42 43 listVersion, err := alias.ListVersion(client, alias.ListVersionOpts{ 44 FuncUrn: publishOptsResp.FuncURN, 45 }) 46 th.AssertNoErr(t, err) 47 tools.PrintResource(t, listVersion) 48 49 createAliasResp, err := alias.CreateAlias(client, createAliasOpts) 50 th.AssertNoErr(t, err) 51 52 listAliasResp, err := alias.ListAlias(client, publishOptsResp.FuncURN) 53 th.AssertNoErr(t, err) 54 55 th.AssertEquals(t, listAliasResp[0].Name, createAliasResp.Name) 56 th.AssertEquals(t, listAliasResp[0].Version, createAliasResp.Version) 57 58 updateAliasResp, err := alias.UpdateAlias(client, alias.UpdateAliasOpts{ 59 FuncUrn: funcUrn, 60 AliasName: "test-alias", 61 Version: "new-version", 62 Description: "new description", 63 }) 64 th.AssertNoErr(t, err) 65 66 th.AssertEquals(t, listAliasResp[0].Name, updateAliasResp.Name) 67 th.AssertEquals(t, updateAliasResp.Description, "new description") 68 69 getAliasResp, err := alias.GetAlias(client, publishOptsResp.FuncURN, "test-alias") 70 th.AssertNoErr(t, err) 71 72 th.AssertEquals(t, listAliasResp[0].Name, getAliasResp.Name) 73 th.AssertEquals(t, getAliasResp.Description, updateAliasResp.Description) 74 th.AssertEquals(t, listAliasResp[0].AliasUrn, getAliasResp.AliasUrn) 75 76 th.AssertNoErr(t, alias.Delete(client, publishOptsResp.FuncURN, "test-alias")) 77 }