blob: 62e5df950ce12ea5ca5769269696905dd0b3a25d [file] [log] [blame]
Ash Wilson720c83c2014-10-22 17:49:15 -04001package keypairs
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func TestList(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 os.HandleListSuccessfully(t)
16
17 count := 0
18 err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
19 count++
20 actual, err := ExtractKeyPairs(page)
21 th.AssertNoErr(t, err)
22 th.CheckDeepEquals(t, os.ExpectedKeyPairSlice, actual)
23
24 return true, nil
25 })
26 th.AssertNoErr(t, err)
27 th.CheckEquals(t, 1, count)
28}
29
30func TestCreate(t *testing.T) {
31 th.SetupHTTP()
32 defer th.TeardownHTTP()
33 os.HandleCreateSuccessfully(t)
34
35 actual, err := Create(client.ServiceClient(), os.CreateOpts{
36 Name: "createdkey",
37 }).Extract()
38 th.AssertNoErr(t, err)
39 th.CheckDeepEquals(t, &os.CreatedKeyPair, actual)
40}
41
42func TestImport(t *testing.T) {
43 th.SetupHTTP()
44 defer th.TeardownHTTP()
45 os.HandleImportSuccessfully(t)
46
47 actual, err := Create(client.ServiceClient(), os.CreateOpts{
48 Name: "importedkey",
49 PublicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated by Nova",
50 }).Extract()
51 th.AssertNoErr(t, err)
52 th.CheckDeepEquals(t, &os.ImportedKeyPair, actual)
53}
54
55func TestGet(t *testing.T) {
56 th.SetupHTTP()
57 defer th.TeardownHTTP()
58 os.HandleGetSuccessfully(t)
59
60 actual, err := Get(client.ServiceClient(), "firstkey").Extract()
61 th.AssertNoErr(t, err)
62 th.CheckDeepEquals(t, &os.FirstKeyPair, actual)
63}
64
65func TestDelete(t *testing.T) {
66 th.SetupHTTP()
67 defer th.TeardownHTTP()
68 os.HandleDeleteSuccessfully(t)
69
Jon Perrittba2395e2014-10-27 15:23:21 -050070 err := Delete(client.ServiceClient(), "deletedkey").ExtractErr()
Ash Wilson720c83c2014-10-22 17:49:15 -040071 th.AssertNoErr(t, err)
72}