blob: ca221be450d8e0f8ffe21f641693df2545c6105a [file] [log] [blame]
Joe Topjianaa8aff12016-07-25 19:43:52 +00001// +build acceptance compute defsecrules
2
3package v2
4
5import (
6 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Joe Topjianaa8aff12016-07-25 19:43:52 +00009 dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules"
10)
11
12func TestDefSecRulesList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060013 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000014 if err != nil {
15 t.Fatalf("Unable to create a compute client: %v", err)
16 }
17
18 allPages, err := dsr.List(client).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to list default rules: %v", err)
21 }
22
23 allDefaultRules, err := dsr.ExtractDefaultRules(allPages)
24 if err != nil {
25 t.Fatalf("Unable to extract default rules: %v", err)
26 }
27
28 for _, defaultRule := range allDefaultRules {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060029 PrintDefaultRule(t, &defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000030 }
31}
32
33func TestDefSecRulesCreate(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060034 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000035 if err != nil {
36 t.Fatalf("Unable to create a compute client: %v", err)
37 }
38
Joe Topjian1c15e3f2016-08-08 10:48:38 -060039 defaultRule, err := CreateDefaultRule(t, client)
Joe Topjianaa8aff12016-07-25 19:43:52 +000040 if err != nil {
41 t.Fatalf("Unable to create default rule: %v", err)
42 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060043 defer DeleteDefaultRule(t, client, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000044
Joe Topjian1c15e3f2016-08-08 10:48:38 -060045 PrintDefaultRule(t, &defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000046}
47
48func TestDefSecRulesGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060049 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000050 if err != nil {
51 t.Fatalf("Unable to create a compute client: %v", err)
52 }
53
Joe Topjian1c15e3f2016-08-08 10:48:38 -060054 defaultRule, err := CreateDefaultRule(t, client)
Joe Topjianaa8aff12016-07-25 19:43:52 +000055 if err != nil {
56 t.Fatalf("Unable to create default rule: %v", err)
57 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060058 defer DeleteDefaultRule(t, client, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000059
60 newDefaultRule, err := dsr.Get(client, defaultRule.ID).Extract()
61 if err != nil {
62 t.Fatalf("Unable to get default rule %s: %v", defaultRule.ID, err)
63 }
64
Joe Topjian1c15e3f2016-08-08 10:48:38 -060065 PrintDefaultRule(t, newDefaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000066}