Skip to content

Commit

Permalink
Merge pull request #50 from voidspace/maas2-null-filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
jujubot committed Apr 28, 2016
2 parents c1d81f9 + b15beb7 commit b5d5d8e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
20 changes: 13 additions & 7 deletions filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ func (f *filesystem) UUID() string {
func filesystem2_0(source map[string]interface{}) (*filesystem, error) {
fields := schema.Fields{
"fstype": schema.String(),
"mount_point": schema.String(),
"label": schema.String(),
"mount_point": schema.OneOf(schema.Nil(""), schema.String()),
"label": schema.OneOf(schema.Nil(""), schema.String()),
"uuid": schema.String(),
// TODO: mount_options when we know the type.
// TODO: mount_options when we know the type (note it can be
// nil).
}
checker := schema.FieldMap(fields, nil)
defaults := schema.Defaults{
"mount_point": "",
"label": "",
}
checker := schema.FieldMap(fields, defaults)
coerced, err := checker.Coerce(source, nil)
if err != nil {
return nil, WrapWithDeserializationError(err, "filesystem 2.0 schema check failed")
}
valid := coerced.(map[string]interface{})
// From here we know that the map returned from the schema coercion
// contains fields of the right type.

mount_point, _ := valid["mount_point"].(string)
label, _ := valid["label"].(string)
result := &filesystem{
fstype: valid["fstype"].(string),
mountPoint: valid["mount_point"].(string),
label: valid["label"].(string),
mountPoint: mount_point,
label: label,
uuid: valid["uuid"].(string),
}
return result, nil
Expand Down
15 changes: 15 additions & 0 deletions filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ func (*filesystemSuite) TestParse2_0(c *gc.C) {
c.Check(fs.UUID(), gc.Equals, "fake-uuid")
}

func (*filesystemSuite) TestParse2_Defaults(c *gc.C) {
source := map[string]interface{}{
"fstype": "ext4",
"mount_point": nil,
"label": nil,
"uuid": "fake-uuid",
}
fs, err := filesystem2_0(source)
c.Assert(err, jc.ErrorIsNil)
c.Check(fs.Type(), gc.Equals, "ext4")
c.Check(fs.MountPoint(), gc.Equals, "")
c.Check(fs.Label(), gc.Equals, "")
c.Check(fs.UUID(), gc.Equals, "fake-uuid")
}

func (*filesystemSuite) TestParse2_0BadSchema(c *gc.C) {
source := map[string]interface{}{
"mount_point": "/",
Expand Down

0 comments on commit b5d5d8e

Please sign in to comment.