コード例 #1
0
ファイル: common_test.go プロジェクト: DirtyHairy/csync
func checkDirectoryContents(directory storage.Directory, expectedContents []string) (entries map[string]storage.Entry, e error) {
	entries = make(map[string]storage.Entry)
	e = nil

	contents := make([]string, 0, 10)

	for entry, err := directory.NextEntry(); entry != nil; entry, err = directory.NextEntry() {
		if err != nil {
			e = errors.New(fmt.Sprintf("error while iterating over directory entries: %v", err))
			return
		}

		contents = append(contents, entry.Name())
		entries[entry.Name()] = entry
	}

	if len(contents) != len(expectedContents) {
		e = errors.New(fmt.Sprintf("expected %d dir entries, got %d instead", len(expectedContents), len(contents)))
		return
	}

	sort.Sort(sort.StringSlice(contents))
	sort.Sort(sort.StringSlice(expectedContents))

	for idx, filename := range contents {
		if filename != expectedContents[idx] {
			e = errors.New(fmt.Sprintf("directory listing differs at %d: expected %s, got %s", idx, expectedContents[idx], filename))
			return
		}
	}

	return
}