arnaucube
arnaucube/mirror-to-giteaPublic Self-hosted repository
mirror-to-gitea/vendor/github.com/onsi/gomega/matchers/be_an_existing_file.go
vendor/github.com/onsi/gomega/matchers/be_an_existing_file.goRaw
 1// untested sections: 3
 2
 3package matchers
 4
 5import (
 6	"fmt"
 7	"os"
 8
 9	"github.com/onsi/gomega/format"
10)
11
12type BeAnExistingFileMatcher struct {
13	expected interface{}
14}
15
16func (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
34func (matcher *BeAnExistingFileMatcher) FailureMessage(actual interface{}) (message string) {
35	return format.Message(actual, fmt.Sprintf("to exist"))
36}
37
38func (matcher *BeAnExistingFileMatcher) NegatedFailureMessage(actual interface{}) (message string) {
39	return format.Message(actual, fmt.Sprintf("not to exist"))
40}