7 "github.com/onsi/gomega/format"
10 type notADirectoryError struct {
14 func (t notADirectoryError) Error() string {
15 fileInfo := os.FileInfo(t)
17 case fileInfo.Mode().IsRegular():
18 return "file is a regular file"
20 return fmt.Sprintf("file mode is: %s", fileInfo.Mode().String())
24 type BeADirectoryMatcher struct {
29 func (matcher *BeADirectoryMatcher) Match(actual interface{}) (success bool, err error) {
30 actualFilename, ok := actual.(string)
32 return false, fmt.Errorf("BeADirectoryMatcher matcher expects a file path")
35 fileInfo, err := os.Stat(actualFilename)
41 if !fileInfo.Mode().IsDir() {
42 matcher.err = notADirectoryError{fileInfo}
48 func (matcher *BeADirectoryMatcher) FailureMessage(actual interface{}) (message string) {
49 return format.Message(actual, fmt.Sprintf("to be a directory: %s", matcher.err))
52 func (matcher *BeADirectoryMatcher) NegatedFailureMessage(actual interface{}) (message string) {
53 return format.Message(actual, fmt.Sprintf("not be a directory"))