Ash Wilson | ad612f6 | 2014-10-22 14:04:37 -0400 | [diff] [blame] | 1 | package keypairs |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | func TestList(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | HandleListSuccessfully(t) |
| 15 | |
| 16 | count := 0 |
| 17 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 18 | count++ |
| 19 | actual, err := ExtractKeyPairs(page) |
| 20 | th.AssertNoErr(t, err) |
| 21 | th.CheckDeepEquals(t, ExpectedKeyPairSlice, actual) |
| 22 | |
| 23 | return true, nil |
| 24 | }) |
| 25 | th.AssertNoErr(t, err) |
| 26 | th.CheckEquals(t, 1, count) |
| 27 | } |
Ash Wilson | 4aaaa1e | 2014-10-22 14:38:02 -0400 | [diff] [blame] | 28 | |
Ash Wilson | 10fede7 | 2014-10-22 14:58:52 -0400 | [diff] [blame] | 29 | func TestCreate(t *testing.T) { |
| 30 | th.SetupHTTP() |
| 31 | defer th.TeardownHTTP() |
| 32 | HandleCreateSuccessfully(t) |
| 33 | |
| 34 | actual, err := Create(client.ServiceClient(), CreateOpts{ |
| 35 | Name: "createdkey", |
| 36 | }).Extract() |
| 37 | th.AssertNoErr(t, err) |
| 38 | th.CheckDeepEquals(t, &CreatedKeyPair, actual) |
| 39 | } |
| 40 | |
Ash Wilson | bae65cd | 2014-10-22 15:02:14 -0400 | [diff] [blame^] | 41 | func TestImport(t *testing.T) { |
| 42 | th.SetupHTTP() |
| 43 | defer th.TeardownHTTP() |
| 44 | HandleImportSuccessfully(t) |
| 45 | |
| 46 | actual, err := Create(client.ServiceClient(), CreateOpts{ |
| 47 | Name: "importedkey", |
| 48 | PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova", |
| 49 | }).Extract() |
| 50 | th.AssertNoErr(t, err) |
| 51 | th.CheckDeepEquals(t, &ImportedKeyPair, actual) |
| 52 | } |
| 53 | |
Ash Wilson | 4aaaa1e | 2014-10-22 14:38:02 -0400 | [diff] [blame] | 54 | func TestGet(t *testing.T) { |
| 55 | th.SetupHTTP() |
| 56 | defer th.TeardownHTTP() |
| 57 | HandleGetSuccessfully(t) |
| 58 | |
| 59 | actual, err := Get(client.ServiceClient(), "firstkey").Extract() |
| 60 | th.AssertNoErr(t, err) |
| 61 | th.CheckDeepEquals(t, &FirstKeyPair, actual) |
| 62 | } |