config: add validity check for file permissions

This commit is contained in:
Alex Crawford 2014-12-21 11:14:03 -08:00
parent af8e590575
commit 0e70d4f01f
2 changed files with 24 additions and 1 deletions

View File

@ -21,5 +21,5 @@ type File struct {
Content string `yaml:"content"` Content string `yaml:"content"`
Owner string `yaml:"owner"` Owner string `yaml:"owner"`
Path string `yaml:"path"` Path string `yaml:"path"`
RawFilePermissions string `yaml:"permissions"` RawFilePermissions string `yaml:"permissions" valid:"^0?[0-7]{3,4}$"`
} }

View File

@ -46,3 +46,26 @@ func TestEncodingValid(t *testing.T) {
} }
} }
} }
func TestRawFilePermissionsValid(t *testing.T) {
tests := []struct {
value string
isValid bool
}{
{value: "744", isValid: true},
{value: "0744", isValid: true},
{value: "1744", isValid: true},
{value: "01744", isValid: true},
{value: "11744", isValid: false},
{value: "rwxr--r--", isValid: false},
{value: "800", isValid: false},
}
for _, tt := range tests {
isValid := (nil == AssertStructValid(File{RawFilePermissions: tt.value}))
if tt.isValid != isValid {
t.Errorf("bad assert (%s): want %t, got %t", tt.value, tt.isValid, isValid)
}
}
}