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 | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 10 | dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules" |
| 11 | ) |
| 12 | |
| 13 | func TestDefSecRulesList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 14 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a compute client: %v", err) |
| 17 | } |
| 18 | |
| 19 | allPages, err := dsr.List(client).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to list default rules: %v", err) |
| 22 | } |
| 23 | |
| 24 | allDefaultRules, err := dsr.ExtractDefaultRules(allPages) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to extract default rules: %v", err) |
| 27 | } |
| 28 | |
| 29 | for _, defaultRule := range allDefaultRules { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestDefSecRulesCreate(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 35 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 36 | if err != nil { |
| 37 | t.Fatalf("Unable to create a compute client: %v", err) |
| 38 | } |
| 39 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 40 | defaultRule, err := CreateDefaultRule(t, client) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 41 | if err != nil { |
| 42 | t.Fatalf("Unable to create default rule: %v", err) |
| 43 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 44 | defer DeleteDefaultRule(t, client, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 45 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 46 | tools.PrintResource(t, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | func TestDefSecRulesGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 50 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 51 | if err != nil { |
| 52 | t.Fatalf("Unable to create a compute client: %v", err) |
| 53 | } |
| 54 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 55 | defaultRule, err := CreateDefaultRule(t, client) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 56 | if err != nil { |
| 57 | t.Fatalf("Unable to create default rule: %v", err) |
| 58 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 59 | defer DeleteDefaultRule(t, client, defaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 60 | |
| 61 | newDefaultRule, err := dsr.Get(client, defaultRule.ID).Extract() |
| 62 | if err != nil { |
| 63 | t.Fatalf("Unable to get default rule %s: %v", defaultRule.ID, err) |
| 64 | } |
| 65 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 66 | tools.PrintResource(t, newDefaultRule) |
Joe Topjian | aa8aff1 | 2016-07-25 19:43:52 +0000 | [diff] [blame] | 67 | } |