1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// +build acceptance networking vpnaas
package vpnaas
import (
"testing"
"github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/acceptance/tools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/vpnaas/ikepolicies"
)
func TestIKEPolicyList(t *testing.T) {
client, err := clients.NewNetworkV2Client()
if err != nil {
t.Fatalf("Unable to create a network client: %v", err)
}
allPages, err := ikepolicies.List(client, nil).AllPages()
if err != nil {
t.Fatalf("Unable to list IKE policies: %v", err)
}
allPolicies, err := ikepolicies.ExtractPolicies(allPages)
if err != nil {
t.Fatalf("Unable to extract IKE policies: %v", err)
}
for _, policy := range allPolicies {
tools.PrintResource(t, policy)
}
}
func TestIKEPolicyCRUD(t *testing.T) {
client, err := clients.NewNetworkV2Client()
if err != nil {
t.Fatalf("Unable to create a network client: %v", err)
}
policy, err := CreateIKEPolicy(t, client)
if err != nil {
t.Fatalf("Unable to create IKE policy: %v", err)
}
defer DeleteIKEPolicy(t, client, policy.ID)
tools.PrintResource(t, policy)
newPolicy, err := ikepolicies.Get(client, policy.ID).Extract()
if err != nil {
t.Fatalf("Unable to get IKE policy: %v", err)
}
tools.PrintResource(t, newPolicy)
updatedName := "updatedname"
updatedDescription := "updated policy"
updateOpts := ikepolicies.UpdateOpts{
Name: &updatedName,
Description: &updatedDescription,
Lifetime: &ikepolicies.LifetimeUpdateOpts{
Value: 7000,
},
}
updatedPolicy, err := ikepolicies.Update(client, policy.ID, updateOpts).Extract()
if err != nil {
t.Fatalf("Unable to update IKE policy: %v", err)
}
tools.PrintResource(t, updatedPolicy)
}
|