Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 1 | // +build acceptance compute defsecrules |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 9 | dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules" |
| 10 | ) |
| 11 | |
| 12 | func TestDefSecRulesList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 13 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 14 | 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 Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 29 | PrintDefaultRule(t, &defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestDefSecRulesCreate(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 34 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 35 | if err != nil { |
| 36 | t.Fatalf("Unable to create a compute client: %v", err) |
| 37 | } |
| 38 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 39 | defaultRule, err := CreateDefaultRule(t, client) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 40 | if err != nil { |
| 41 | t.Fatalf("Unable to create default rule: %v", err) |
| 42 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 43 | defer DeleteDefaultRule(t, client, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 44 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 45 | PrintDefaultRule(t, &defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | func TestDefSecRulesGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 49 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 50 | if err != nil { |
| 51 | t.Fatalf("Unable to create a compute client: %v", err) |
| 52 | } |
| 53 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 54 | defaultRule, err := CreateDefaultRule(t, client) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 55 | if err != nil { |
| 56 | t.Fatalf("Unable to create default rule: %v", err) |
| 57 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 58 | defer DeleteDefaultRule(t, client, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 59 | |
| 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 Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 65 | PrintDefaultRule(t, newDefaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 66 | } |