func TestBuildHeaders(t *testing.T) { testStruct := struct { Accept string `h:"Accept"` Num int `h:"Number,required"` Style bool `h:"Style"` }{ Accept: "application/json", Num: 4, Style: true, } expected := map[string]string{"Accept": "application/json", "Number": "4", "Style": "true"} actual, err := gophercloud.BuildHeaders(&testStruct) th.CheckNoErr(t, err) th.CheckDeepEquals(t, expected, actual) testStruct.Num = 0 _, err = gophercloud.BuildHeaders(&testStruct) if err == nil { t.Errorf("Expected error: 'Required header not set'") } _, err = gophercloud.BuildHeaders(map[string]interface{}{"Number": 4}) if err == nil { t.Errorf("Expected error: 'Options type is not a struct'") } }
func TestGetHomeDocument(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGetSuccessfully(t) actual, err := base.Get(fake.ServiceClient()).Extract() th.CheckNoErr(t, err) expected := base.HomeDocument{ "rel/cdn": map[string]interface{}{ "href-template": "services{?marker,limit}", "href-vars": map[string]interface{}{ "marker": "param/marker", "limit": "param/limit", }, "hints": map[string]interface{}{ "allow": []string{"GET"}, "formats": map[string]interface{}{ "application/json": map[string]interface{}{}, }, }, }, } th.CheckDeepEquals(t, expected, *actual) }
func TestPing(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandlePingSuccessfully(t) err := base.Ping(fake.ServiceClient()).ExtractErr() th.CheckNoErr(t, err) }
func TestDeleteContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleDeleteContainerSuccessfully(t) res := containers.Delete(fake.ServiceClient(), "testContainer") th.CheckNoErr(t, res.Err) }
func TestUpateContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleUpdateContainerSuccessfully(t) options := &containers.UpdateOpts{Metadata: map[string]string{"foo": "bar"}} res := containers.Update(fake.ServiceClient(), "testContainer", options) th.CheckNoErr(t, res.Err) }
func TestGetContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleGetContainerSuccessfully(t) res := containers.Get(fake.ServiceClient(), "testContainer") _, err := res.ExtractMetadata() th.CheckNoErr(t, err) expected := &containers.GetHeader{ AcceptRanges: "bytes", BytesUsed: 100, ContentType: "application/json; charset=utf-8", Date: gophercloud.JSONRFC1123(time.Date(2016, time.August, 17, 19, 25, 43, 0, loc)), //Wed, 17 Aug 2016 19:25:43 GMT ObjectCount: 4, Read: []string{"test"}, TransID: "tx554ed59667a64c61866f1-0057b4ba37", Write: []string{"test2", "user4"}, } actual, err := res.Extract() th.CheckNoErr(t, err) th.AssertDeepEquals(t, expected, actual) }
func TestEnumerateSinglePaged(t *testing.T) { callCount := 0 pager := setupSinglePaged() defer testhelper.TeardownHTTP() err := pager.EachPage(func(page pagination.Page) (bool, error) { callCount++ expected := []int{1, 2, 3} actual, err := ExtractSingleInts(page) testhelper.AssertNoErr(t, err) testhelper.CheckDeepEquals(t, expected, actual) return true, nil }) testhelper.CheckNoErr(t, err) testhelper.CheckEquals(t, 1, callCount) }
func TestCreateContainer(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() HandleCreateContainerSuccessfully(t) options := containers.CreateOpts{ContentType: "application/json", Metadata: map[string]string{"foo": "bar"}} res := containers.Create(fake.ServiceClient(), "testContainer", options) th.CheckEquals(t, "bar", res.Header["X-Container-Meta-Foo"][0]) expected := &containers.CreateHeader{ ContentLength: 0, ContentType: "text/html; charset=UTF-8", Date: gophercloud.JSONRFC1123(time.Date(2016, time.August, 17, 19, 25, 43, 0, loc)), //Wed, 17 Aug 2016 19:25:43 GMT TransID: "tx554ed59667a64c61866f1-0058b4ba37", } actual, err := res.Extract() th.CheckNoErr(t, err) th.AssertDeepEquals(t, expected, actual) }
func TestWaitFor(t *testing.T) { err := gophercloud.WaitFor(5, func() (bool, error) { return true, nil }) th.CheckNoErr(t, err) }