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