github.com/gophercloud/gophercloud@v1.11.0/openstack/clustering/v1/profiles/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud/openstack/clustering/v1/profiles" 7 "github.com/gophercloud/gophercloud/pagination" 8 th "github.com/gophercloud/gophercloud/testhelper" 9 fake "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 func TestCreateProfile(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 16 HandleCreateSuccessfully(t) 17 18 networks := []map[string]interface{}{ 19 {"network": "private-network"}, 20 } 21 22 props := map[string]interface{}{ 23 "name": "test_gopher_cloud_profile", 24 "flavor": "t2.small", 25 "image": "centos7.3-latest", 26 "networks": networks, 27 "security_groups": "", 28 } 29 30 createOpts := &profiles.CreateOpts{ 31 Name: "TestProfile", 32 Spec: profiles.Spec{ 33 Type: "os.nova.server", 34 Version: "1.0", 35 Properties: props, 36 }, 37 } 38 39 profile, err := profiles.Create(fake.ServiceClient(), createOpts).Extract() 40 if err != nil { 41 t.Errorf("Failed to extract profile: %v", err) 42 } 43 44 th.AssertDeepEquals(t, ExpectedCreate, *profile) 45 } 46 47 func TestGetProfile(t *testing.T) { 48 th.SetupHTTP() 49 defer th.TeardownHTTP() 50 51 HandleGetSuccessfully(t) 52 53 actual, err := profiles.Get(fake.ServiceClient(), ExpectedGet.ID).Extract() 54 th.AssertNoErr(t, err) 55 th.AssertDeepEquals(t, ExpectedGet, *actual) 56 } 57 58 func TestListProfiles(t *testing.T) { 59 th.SetupHTTP() 60 defer th.TeardownHTTP() 61 62 HandleListSuccessfully(t) 63 64 var iFalse bool 65 listOpts := profiles.ListOpts{ 66 GlobalProject: &iFalse, 67 } 68 69 count := 0 70 err := profiles.List(fake.ServiceClient(), listOpts).EachPage(func(page pagination.Page) (bool, error) { 71 count++ 72 actual, err := profiles.ExtractProfiles(page) 73 th.AssertNoErr(t, err) 74 th.AssertDeepEquals(t, ExpectedList, actual) 75 76 return true, nil 77 }) 78 79 th.AssertNoErr(t, err) 80 81 if count != 1 { 82 t.Errorf("Expected 1 page of profiles, got %d pages instead", count) 83 } 84 } 85 86 func TestUpdateProfile(t *testing.T) { 87 th.SetupHTTP() 88 defer th.TeardownHTTP() 89 90 HandleUpdateSuccessfully(t) 91 92 updateOpts := profiles.UpdateOpts{ 93 Name: "pserver", 94 } 95 96 actual, err := profiles.Update(fake.ServiceClient(), ExpectedUpdate.ID, updateOpts).Extract() 97 th.AssertNoErr(t, err) 98 th.AssertDeepEquals(t, ExpectedUpdate, *actual) 99 } 100 101 func TestDeleteProfile(t *testing.T) { 102 th.SetupHTTP() 103 defer th.TeardownHTTP() 104 105 HandleDeleteSuccessfully(t) 106 107 deleteResult := profiles.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee") 108 th.AssertNoErr(t, deleteResult.ExtractErr()) 109 } 110 111 func TestValidateProfile(t *testing.T) { 112 th.SetupHTTP() 113 defer th.TeardownHTTP() 114 115 HandleValidateSuccessfully(t) 116 117 validateOpts := profiles.ValidateOpts{ 118 Spec: profiles.Spec{ 119 Properties: map[string]interface{}{ 120 "flavor": "t2.micro", 121 "image": "cirros-0.3.4-x86_64-uec", 122 "key_name": "oskey", 123 "name": "cirros_server", 124 "networks": []interface{}{ 125 map[string]interface{}{"network": "private"}, 126 }, 127 }, 128 Type: "os.nova.server", 129 Version: "1.0", 130 }, 131 } 132 133 client := fake.ServiceClient() 134 client.Microversion = "1.2" 135 client.Type = "clustering" 136 137 profile, err := profiles.Validate(client, validateOpts).Extract() 138 th.AssertNoErr(t, err) 139 th.AssertDeepEquals(t, ExpectedValidate, *profile) 140 }