func TestList(t *testing.T) { th.SetupHTTP() defer th.TeardownHTTP() os.HandleListSuccessfully(t) serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0" count := 0 err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) { count++ actual, err := os.ExtractVolumeAttachments(page) th.AssertNoErr(t, err) th.CheckDeepEquals(t, os.ExpectedVolumeAttachmentSlice, actual) return true, nil }) th.AssertNoErr(t, err) th.CheckEquals(t, 1, count) }
func (command *commandList) Execute(resource *handler.Resource) { params := resource.Params.(*paramsList) err := osVolumeAttach.List(command.Ctx.ServiceClient, params.serverID).EachPage(func(page pagination.Page) (bool, error) { volumeAttachments, err := osVolumeAttach.ExtractVolumeAttachments(page) if err != nil { return false, err } result := make([]map[string]interface{}, len(volumeAttachments)) for j, volumeAttachment := range volumeAttachments { result[j] = structs.Map(volumeAttachment) } resource.Result = result return false, nil }) if err != nil { resource.Err = err return } }