github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/keypairs/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/keypairs" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestList(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListSuccessfully(t) 16 17 count := 0 18 err := keypairs.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 19 count++ 20 actual, err := keypairs.ExtractKeyPairs(page) 21 th.AssertNoErr(t, err) 22 th.CheckDeepEquals(t, ExpectedKeyPairSlice, actual) 23 24 return true, nil 25 }) 26 th.AssertNoErr(t, err) 27 th.CheckEquals(t, 1, count) 28 } 29 30 func TestCreate(t *testing.T) { 31 th.SetupHTTP() 32 defer th.TeardownHTTP() 33 HandleCreateSuccessfully(t) 34 35 actual, err := keypairs.Create(client.ServiceClient(), keypairs.CreateOpts{ 36 Name: "createdkey", 37 }).Extract() 38 th.AssertNoErr(t, err) 39 th.CheckDeepEquals(t, &CreatedKeyPair, actual) 40 } 41 42 func TestImport(t *testing.T) { 43 th.SetupHTTP() 44 defer th.TeardownHTTP() 45 HandleImportSuccessfully(t) 46 47 actual, err := keypairs.Create(client.ServiceClient(), keypairs.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, &ImportedKeyPair, actual) 53 } 54 55 func TestGet(t *testing.T) { 56 th.SetupHTTP() 57 defer th.TeardownHTTP() 58 HandleGetSuccessfully(t) 59 60 actual, err := keypairs.Get(client.ServiceClient(), "firstkey").Extract() 61 th.AssertNoErr(t, err) 62 th.CheckDeepEquals(t, &FirstKeyPair, actual) 63 } 64 65 func TestDelete(t *testing.T) { 66 th.SetupHTTP() 67 defer th.TeardownHTTP() 68 HandleDeleteSuccessfully(t) 69 70 err := keypairs.Delete(client.ServiceClient(), "deletedkey").ExtractErr() 71 th.AssertNoErr(t, err) 72 }