github.com/leeclow-ops/gophercloud@v1.2.1/openstack/db/v1/instances/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 db "github.com/leeclow-ops/gophercloud/openstack/db/v1/databases" 7 "github.com/leeclow-ops/gophercloud/openstack/db/v1/instances" 8 "github.com/leeclow-ops/gophercloud/openstack/db/v1/users" 9 "github.com/leeclow-ops/gophercloud/pagination" 10 th "github.com/leeclow-ops/gophercloud/testhelper" 11 fake "github.com/leeclow-ops/gophercloud/testhelper/client" 12 ) 13 14 func TestCreate(t *testing.T) { 15 th.SetupHTTP() 16 defer th.TeardownHTTP() 17 HandleCreate(t) 18 19 opts := instances.CreateOpts{ 20 Name: "json_rack_instance", 21 FlavorRef: "1", 22 Databases: db.BatchCreateOpts{ 23 {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, 24 {Name: "nextround"}, 25 }, 26 Users: users.BatchCreateOpts{ 27 { 28 Name: "demouser", 29 Password: "demopassword", 30 Databases: db.BatchCreateOpts{ 31 {Name: "sampledb"}, 32 }, 33 }, 34 }, 35 Size: 2, 36 VolumeType: "ssd", 37 } 38 39 instance, err := instances.Create(fake.ServiceClient(), opts).Extract() 40 41 th.AssertNoErr(t, err) 42 th.AssertDeepEquals(t, &expectedInstance, instance) 43 } 44 45 func TestCreateWithFault(t *testing.T) { 46 th.SetupHTTP() 47 defer th.TeardownHTTP() 48 HandleCreateWithFault(t) 49 50 opts := instances.CreateOpts{ 51 Name: "json_rack_instance", 52 FlavorRef: "1", 53 Databases: db.BatchCreateOpts{ 54 {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"}, 55 {Name: "nextround"}, 56 }, 57 Users: users.BatchCreateOpts{ 58 { 59 Name: "demouser", 60 Password: "demopassword", 61 Databases: db.BatchCreateOpts{ 62 {Name: "sampledb"}, 63 }, 64 }, 65 }, 66 Size: 2, 67 VolumeType: "ssd", 68 } 69 70 instance, err := instances.Create(fake.ServiceClient(), opts).Extract() 71 72 th.AssertNoErr(t, err) 73 th.AssertDeepEquals(t, &expectedInstanceWithFault, instance) 74 } 75 76 func TestInstanceList(t *testing.T) { 77 th.SetupHTTP() 78 defer th.TeardownHTTP() 79 HandleList(t) 80 81 pages := 0 82 err := instances.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 83 pages++ 84 85 actual, err := instances.ExtractInstances(page) 86 if err != nil { 87 return false, err 88 } 89 90 th.CheckDeepEquals(t, []instances.Instance{expectedInstance}, actual) 91 return true, nil 92 }) 93 94 th.AssertNoErr(t, err) 95 th.AssertEquals(t, 1, pages) 96 } 97 98 func TestGetInstance(t *testing.T) { 99 th.SetupHTTP() 100 defer th.TeardownHTTP() 101 HandleGet(t) 102 103 instance, err := instances.Get(fake.ServiceClient(), instanceID).Extract() 104 105 th.AssertNoErr(t, err) 106 th.AssertDeepEquals(t, &expectedGetInstance, instance) 107 } 108 109 func TestDeleteInstance(t *testing.T) { 110 th.SetupHTTP() 111 defer th.TeardownHTTP() 112 HandleDelete(t) 113 114 res := instances.Delete(fake.ServiceClient(), instanceID) 115 th.AssertNoErr(t, res.Err) 116 } 117 118 func TestEnableRootUser(t *testing.T) { 119 th.SetupHTTP() 120 defer th.TeardownHTTP() 121 HandleEnableRoot(t) 122 123 expected := &users.User{Name: "root", Password: "secretsecret"} 124 user, err := instances.EnableRootUser(fake.ServiceClient(), instanceID).Extract() 125 126 th.AssertNoErr(t, err) 127 th.AssertDeepEquals(t, expected, user) 128 } 129 130 func TestIsRootEnabled(t *testing.T) { 131 th.SetupHTTP() 132 defer th.TeardownHTTP() 133 HandleIsRootEnabled(t) 134 135 isEnabled, err := instances.IsRootEnabled(fake.ServiceClient(), instanceID).Extract() 136 137 th.AssertNoErr(t, err) 138 th.AssertEquals(t, true, isEnabled) 139 } 140 141 func TestRestart(t *testing.T) { 142 th.SetupHTTP() 143 defer th.TeardownHTTP() 144 HandleRestart(t) 145 146 res := instances.Restart(fake.ServiceClient(), instanceID) 147 th.AssertNoErr(t, res.Err) 148 } 149 150 func TestResize(t *testing.T) { 151 th.SetupHTTP() 152 defer th.TeardownHTTP() 153 HandleResize(t) 154 155 res := instances.Resize(fake.ServiceClient(), instanceID, "2") 156 th.AssertNoErr(t, res.Err) 157 } 158 159 func TestResizeVolume(t *testing.T) { 160 th.SetupHTTP() 161 defer th.TeardownHTTP() 162 HandleResizeVol(t) 163 164 res := instances.ResizeVolume(fake.ServiceClient(), instanceID, 4) 165 th.AssertNoErr(t, res.Err) 166 } 167 168 func TestAttachConfigurationGroup(t *testing.T) { 169 th.SetupHTTP() 170 defer th.TeardownHTTP() 171 HandleAttachConfigurationGroup(t) 172 173 res := instances.AttachConfigurationGroup(fake.ServiceClient(), instanceID, configGroupID) 174 th.AssertNoErr(t, res.Err) 175 } 176 177 func TestDetachConfigurationGroup(t *testing.T) { 178 th.SetupHTTP() 179 defer th.TeardownHTTP() 180 HandleDetachConfigurationGroup(t) 181 182 res := instances.DetachConfigurationGroup(fake.ServiceClient(), instanceID) 183 th.AssertNoErr(t, res.Err) 184 }