ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 1 | package v2 |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/gophercloud/gophercloud/acceptance/clients" |
ehdou | b46ba5a | 2017-03-08 20:56:49 +0200 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 8 | ) |
| 9 | |
ehdou | 894b50d | 2017-01-07 00:38:03 +0200 | [diff] [blame] | 10 | func TestSecurityServiceCreateDelete(t *testing.T) { |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 11 | client, err := clients.NewSharedFileSystemV2Client() |
| 12 | if err != nil { |
| 13 | t.Fatalf("Unable to create shared file system client: %v", err) |
| 14 | } |
| 15 | |
| 16 | securityService, err := CreateSecurityService(t, client) |
| 17 | if err != nil { |
| 18 | t.Fatalf("Unable to create security service: %v", err) |
| 19 | } |
| 20 | |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 21 | PrintSecurityService(t, securityService) |
ehdou | 894b50d | 2017-01-07 00:38:03 +0200 | [diff] [blame] | 22 | |
| 23 | defer DeleteSecurityService(t, client, securityService) |
ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 24 | } |
ehdou | b46ba5a | 2017-03-08 20:56:49 +0200 | [diff] [blame] | 25 | |
| 26 | func TestSecurityServiceList(t *testing.T) { |
| 27 | client, err := clients.NewSharedFileSystemV2Client() |
| 28 | if err != nil { |
| 29 | t.Fatalf("Unable to create a shared file system client: %v", err) |
| 30 | } |
| 31 | |
| 32 | allPages, err := securityservices.List(client, securityservices.ListOpts{}).AllPages() |
| 33 | if err != nil { |
| 34 | t.Fatalf("Unable to retrieve security services: %v", err) |
| 35 | } |
| 36 | |
| 37 | allSecurityServices, err := securityservices.ExtractSecurityServices(allPages) |
| 38 | if err != nil { |
| 39 | t.Fatalf("Unable to extract security services: %v", err) |
| 40 | } |
| 41 | |
| 42 | for _, securityService := range allSecurityServices { |
| 43 | PrintSecurityService(t, &securityService) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // The test creates 2 security services and verifies that only the one(s) with |
| 48 | // a particular name are being listed |
| 49 | func TestSecurityServiceListFiltering(t *testing.T) { |
| 50 | client, err := clients.NewSharedFileSystemV2Client() |
| 51 | if err != nil { |
| 52 | t.Fatalf("Unable to create a shared file system client: %v", err) |
| 53 | } |
| 54 | |
| 55 | securityService, err := CreateSecurityService(t, client) |
| 56 | if err != nil { |
| 57 | t.Fatalf("Unable to create security service: %v", err) |
| 58 | } |
| 59 | defer DeleteSecurityService(t, client, securityService) |
| 60 | |
| 61 | securityService, err = CreateSecurityService(t, client) |
| 62 | if err != nil { |
| 63 | t.Fatalf("Unable to create security service: %v", err) |
| 64 | } |
| 65 | defer DeleteSecurityService(t, client, securityService) |
| 66 | |
| 67 | options := securityservices.ListOpts{ |
| 68 | Name: securityService.Name, |
| 69 | } |
| 70 | |
| 71 | allPages, err := securityservices.List(client, options).AllPages() |
| 72 | if err != nil { |
| 73 | t.Fatalf("Unable to retrieve security services: %v", err) |
| 74 | } |
| 75 | |
| 76 | allSecurityServices, err := securityservices.ExtractSecurityServices(allPages) |
| 77 | if err != nil { |
| 78 | t.Fatalf("Unable to extract security services: %v", err) |
| 79 | } |
| 80 | |
| 81 | for _, listedSecurityService := range allSecurityServices { |
| 82 | if listedSecurityService.Name != securityService.Name { |
| 83 | t.Fatalf("The name of the security service was expected to be %s", securityService.Name) |
| 84 | } |
| 85 | PrintSecurityService(t, &listedSecurityService) |
| 86 | } |
| 87 | } |