1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2025-10-13 05:09:08 +00:00

vis: refactored code to reflect using vis/unvis for file names

Added some more test cases for `vis`ing and `unvis`ing
strings, and a test case that walks/checks a directory with
filenames that require encoding. Had to change Path() and String()
to account for possible errors Vis() and Unvis() could return.

Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
Stephen Chung 2016-07-20 21:18:27 -04:00
parent 9bec5e46b7
commit c4d09ce5f7
7 changed files with 129 additions and 34 deletions

View file

@ -50,7 +50,11 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
creator.curSet = nil
}
case RelativeType, FullType:
info, err := os.Lstat(e.Path())
pathname, err := e.Path()
if err != nil {
return nil, err
}
info, err := os.Lstat(pathname)
if err != nil {
return nil, err
}
@ -65,17 +69,17 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
for _, kv := range kvs {
keywordFunc, ok := KeywordFuncs[kv.Keyword()]
if !ok {
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), e.Path())
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), pathname)
}
if keywords != nil && !inSlice(kv.Keyword(), keywords) {
continue
}
curKeyVal, err := keywordFunc(filepath.Join(root, e.Path()), info)
curKeyVal, err := keywordFunc(filepath.Join(root, pathname), info)
if err != nil {
return nil, err
}
if string(kv) != curKeyVal {
failure := Failure{Path: e.Path(), Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()}
failure := Failure{Path: pathname, Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()}
result.Failures = append(result.Failures, failure)
}
}