...
1
2
3 package matchers
4
5 import (
6 "fmt"
7 "os"
8
9 "github.com/onsi/gomega/format"
10 )
11
12 type BeAnExistingFileMatcher struct {
13 expected interface{}
14 }
15
16 func (matcher *BeAnExistingFileMatcher) Match(actual interface{}) (success bool, err error) {
17 actualFilename, ok := actual.(string)
18 if !ok {
19 return false, fmt.Errorf("BeAnExistingFileMatcher matcher expects a file path")
20 }
21
22 if _, err = os.Stat(actualFilename); err != nil {
23 switch {
24 case os.IsNotExist(err):
25 return false, nil
26 default:
27 return false, err
28 }
29 }
30
31 return true, nil
32 }
33
34 func (matcher *BeAnExistingFileMatcher) FailureMessage(actual interface{}) (message string) {
35 return format.Message(actual, "to exist")
36 }
37
38 func (matcher *BeAnExistingFileMatcher) NegatedFailureMessage(actual interface{}) (message string) {
39 return format.Message(actual, "not to exist")
40 }
41
View as plain text