github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/db/v1/datastores/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/db/v1/datastores" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 fake "github.com/huaweicloud/golangsdk/testhelper/client" 10 "github.com/huaweicloud/golangsdk/testhelper/fixture" 11 ) 12 13 func TestList(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 fixture.SetupHandler(t, "/datastores", "GET", "", ListDSResp, 200) 17 18 pages := 0 19 20 err := datastores.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 21 pages++ 22 23 actual, err := datastores.ExtractDatastores(page) 24 if err != nil { 25 return false, err 26 } 27 28 th.CheckDeepEquals(t, []datastores.Datastore{ExampleDatastore}, actual) 29 30 return true, nil 31 }) 32 33 th.AssertNoErr(t, err) 34 th.AssertEquals(t, 1, pages) 35 } 36 37 func TestGet(t *testing.T) { 38 th.SetupHTTP() 39 defer th.TeardownHTTP() 40 fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", GetDSResp, 200) 41 42 ds, err := datastores.Get(fake.ServiceClient(), "{dsID}").Extract() 43 th.AssertNoErr(t, err) 44 th.AssertDeepEquals(t, &ExampleDatastore, ds) 45 } 46 47 func TestListVersions(t *testing.T) { 48 th.SetupHTTP() 49 defer th.TeardownHTTP() 50 fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", ListVersionsResp, 200) 51 52 pages := 0 53 54 err := datastores.ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) { 55 pages++ 56 57 actual, err := datastores.ExtractVersions(page) 58 if err != nil { 59 return false, err 60 } 61 62 th.CheckDeepEquals(t, ExampleVersions, actual) 63 64 return true, nil 65 }) 66 67 th.AssertNoErr(t, err) 68 th.AssertEquals(t, 1, pages) 69 } 70 71 func TestGetVersion(t *testing.T) { 72 th.SetupHTTP() 73 defer th.TeardownHTTP() 74 fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", GetVersionResp, 200) 75 76 ds, err := datastores.GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract() 77 th.AssertNoErr(t, err) 78 th.AssertDeepEquals(t, &ExampleVersion1, ds) 79 }