func (s *VolumeStateSuite) TestParseVolumeAttachmentIdError(c *gc.C) { assertError := func(id, expect string) { _, _, err := state.ParseVolumeAttachmentId(id) c.Assert(err, gc.ErrorMatches, expect) } assertError("", `invalid volume attachment ID ""`) assertError("0", `invalid volume attachment ID "0"`) assertError("0:foo", `invalid volume attachment ID "0:foo"`) assertError("bar:0", `invalid volume attachment ID "bar:0"`) }
func (s *VolumeStateSuite) TestParseVolumeAttachmentId(c *gc.C) { assertValid := func(id string, m names.MachineTag, v names.VolumeTag) { machineTag, volumeTag, err := state.ParseVolumeAttachmentId(id) c.Assert(err, jc.ErrorIsNil) c.Assert(machineTag, gc.Equals, m) c.Assert(volumeTag, gc.Equals, v) } assertValid("0:0", names.NewMachineTag("0"), names.NewVolumeTag("0")) assertValid("0:0/1", names.NewMachineTag("0"), names.NewVolumeTag("0/1")) assertValid("0/lxc/0:1", names.NewMachineTag("0/lxc/0"), names.NewVolumeTag("1")) }
// ParseVolumeAttachmentIds parses the strings, returning machine storage IDs. func ParseVolumeAttachmentIds(stringIds []string) ([]params.MachineStorageId, error) { ids := make([]params.MachineStorageId, len(stringIds)) for i, s := range stringIds { m, v, err := state.ParseVolumeAttachmentId(s) if err != nil { return nil, err } ids[i] = params.MachineStorageId{ MachineTag: m.String(), AttachmentTag: v.String(), } } return ids, nil }