Ejemplo n.º 1
0
func testCreateDir(fs storage.Directory, path, referencePath string) error {
	dir, err := fs.Mkdir(path)

	if err != nil {
		return errors.New(fmt.Sprintf("error creating directory: %v", err))
	}

	if actualPath := dir.Entry().Path(); actualPath != referencePath {
		return errors.New(fmt.Sprintf("new directory has wrong path; expected %s, got %s", referencePath, actualPath))
	}

	err = dir.Close()

	if err != nil {
		return errors.New(fmt.Sprintf("failed to close newly created directory: %v", err))
	}

	entry, err := fs.Stat(path)

	if err != nil {
		return errors.New(fmt.Sprintf("failed to stat new directory: %v", err))
	}

	if _, ok := entry.(storage.DirectoryEntry); !ok {
		return errors.New("new directory failed to stat as a directory")
	}

	if actualPath := entry.Path(); actualPath != referencePath {
		return errors.New(fmt.Sprintf("new directory has wrong path after statting; expected %s, got %s", referencePath, actualPath))
	}

	return nil
}