github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/db/v1/databases/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/vnpaycloud-console/gophercloud/v2/openstack/db/v1/databases" 8 "github.com/vnpaycloud-console/gophercloud/v2/pagination" 9 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 10 fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 11 ) 12 13 func TestCreate(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 HandleCreate(t) 17 18 opts := databases.BatchCreateOpts{ 19 databases.CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"}, 20 databases.CreateOpts{Name: "sampledb"}, 21 } 22 23 res := databases.Create(context.TODO(), fake.ServiceClient(), instanceID, opts) 24 th.AssertNoErr(t, res.Err) 25 } 26 27 func TestList(t *testing.T) { 28 th.SetupHTTP() 29 defer th.TeardownHTTP() 30 HandleList(t) 31 32 expectedDBs := []databases.Database{ 33 {Name: "anotherexampledb"}, 34 {Name: "exampledb"}, 35 {Name: "nextround"}, 36 {Name: "sampledb"}, 37 {Name: "testingdb"}, 38 } 39 40 pages := 0 41 err := databases.List(fake.ServiceClient(), instanceID).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) { 42 pages++ 43 44 actual, err := databases.ExtractDBs(page) 45 if err != nil { 46 return false, err 47 } 48 49 th.CheckDeepEquals(t, expectedDBs, actual) 50 51 return true, nil 52 }) 53 54 th.AssertNoErr(t, err) 55 56 if pages != 1 { 57 t.Errorf("Expected 1 page, saw %d", pages) 58 } 59 } 60 61 func TestDelete(t *testing.T) { 62 th.SetupHTTP() 63 defer th.TeardownHTTP() 64 HandleDelete(t) 65 66 err := databases.Delete(context.TODO(), fake.ServiceClient(), instanceID, "{dbName}").ExtractErr() 67 th.AssertNoErr(t, err) 68 }