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