github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/helpers/matchers.go (about) 1 package helpers 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "regexp" 7 "runtime" 8 9 . "github.com/onsi/gomega" 10 "github.com/onsi/gomega/gbytes" 11 "github.com/onsi/gomega/types" 12 ) 13 14 // SayPath is used to assert that a path is printed within streaming output. 15 // On Windows, it uses a case-insensitive match and escapes the path. 16 // On non-Windows, it evaluates the base directory of the path for symlinks. 17 func SayPath(format string, path string) types.GomegaMatcher { 18 theRealDir, err := filepath.EvalSymlinks(filepath.Dir(path)) 19 Expect(err).ToNot(HaveOccurred()) 20 theRealPath := filepath.Join(theRealDir, filepath.Base(path)) 21 22 if runtime.GOOS == "windows" { 23 expected := "(?i)" + format 24 expected = fmt.Sprintf(expected, regexp.QuoteMeta(path)) 25 return gbytes.Say(expected) 26 } 27 return gbytes.Say(format, theRealPath) 28 }