func (s *FilesystemStateSuite) TestParseFilesystemAttachmentIdError(c *gc.C) { assertError := func(id, expect string) { _, _, err := state.ParseFilesystemAttachmentId(id) c.Assert(err, gc.ErrorMatches, expect) } assertError("", `invalid filesystem attachment ID ""`) assertError("0", `invalid filesystem attachment ID "0"`) assertError("0:foo", `invalid filesystem attachment ID "0:foo"`) assertError("bar:0", `invalid filesystem attachment ID "bar:0"`) }
func (s *FilesystemStateSuite) TestParseFilesystemAttachmentId(c *gc.C) { assertValid := func(id string, m names.MachineTag, v names.FilesystemTag) { machineTag, filesystemTag, err := state.ParseFilesystemAttachmentId(id) c.Assert(err, jc.ErrorIsNil) c.Assert(machineTag, gc.Equals, m) c.Assert(filesystemTag, gc.Equals, v) } assertValid("0:0", names.NewMachineTag("0"), names.NewFilesystemTag("0")) assertValid("0:0/1", names.NewMachineTag("0"), names.NewFilesystemTag("0/1")) assertValid("0/lxc/0:1", names.NewMachineTag("0/lxc/0"), names.NewFilesystemTag("1")) }
// ParseFilesystemAttachmentIds parses the strings, returning machine storage IDs. func ParseFilesystemAttachmentIds(stringIds []string) ([]params.MachineStorageId, error) { ids := make([]params.MachineStorageId, len(stringIds)) for i, s := range stringIds { m, f, err := state.ParseFilesystemAttachmentId(s) if err != nil { return nil, err } ids[i] = params.MachineStorageId{ MachineTag: m.String(), AttachmentTag: f.String(), } } return ids, nil }