ehdou | b5066cd | 2016-11-10 22:15:42 +0200 | [diff] [blame] | 1 | package testing |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/securityservices" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | // Verifies that a security service can be created correctly |
| 13 | func TestCreate(t *testing.T) { |
| 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
| 16 | |
| 17 | MockCreateResponse(t) |
| 18 | |
| 19 | options := &securityservices.CreateOpts{ |
| 20 | Name: "SecServ1", |
| 21 | Description: "Creating my first Security Service", |
| 22 | DNSIP: "10.0.0.0/24", |
| 23 | User: "demo", |
| 24 | Password: "***", |
| 25 | Type: "kerberos", |
| 26 | } |
| 27 | |
| 28 | s, err := securityservices.Create(client.ServiceClient(), options).Extract() |
| 29 | th.AssertNoErr(t, err) |
| 30 | |
| 31 | th.AssertEquals(t, s.Name, "SecServ1") |
| 32 | th.AssertEquals(t, s.Description, "Creating my first Security Service") |
| 33 | th.AssertEquals(t, s.User, "demo") |
| 34 | th.AssertEquals(t, s.DNSIP, "10.0.0.0/24") |
| 35 | th.AssertEquals(t, s.Password, "supersecret") |
| 36 | th.AssertEquals(t, s.Type, "kerberos") |
| 37 | } |
| 38 | |
| 39 | // Verifies that a security service cannot be created without a type |
| 40 | func TestCreateFails(t *testing.T) { |
| 41 | options := &securityservices.CreateOpts{ |
| 42 | Name: "SecServ1", |
| 43 | Description: "Creating my first Security Service", |
| 44 | DNSIP: "10.0.0.0/24", |
| 45 | User: "demo", |
| 46 | Password: "***", |
| 47 | } |
| 48 | |
| 49 | _, err := securityservices.Create(client.ServiceClient(), options).Extract() |
| 50 | if _, ok := err.(gophercloud.ErrMissingInput); !ok { |
| 51 | t.Fatal("ErrMissingInput was expected to occur") |
| 52 | } |
| 53 | } |
ehdou | 894b50d | 2017-01-07 00:38:03 +0200 | [diff] [blame^] | 54 | |
| 55 | // Verifies that security service deletion works |
| 56 | func TestDelete(t *testing.T) { |
| 57 | th.SetupHTTP() |
| 58 | defer th.TeardownHTTP() |
| 59 | |
| 60 | MockDeleteResponse(t) |
| 61 | |
| 62 | res := securityservices.Delete(client.ServiceClient(), "securityServiceID") |
| 63 | th.AssertNoErr(t, res.Err) |
| 64 | } |