Allow chaining of FileSystem methods

This commit is contained in:
Stefan Haller 2025-03-27 17:01:35 +01:00
parent 2e1be45957
commit efcd71b296

View file

@ -10,23 +10,25 @@ type FileSystem struct {
}
// This does _not_ check the files panel, it actually checks the filesystem
func (self *FileSystem) PathPresent(path string) {
func (self *FileSystem) PathPresent(path string) *FileSystem {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
return err == nil, fmt.Sprintf("Expected path '%s' to exist, but it does not", path)
})
return self
}
// This does _not_ check the files panel, it actually checks the filesystem
func (self *FileSystem) PathNotPresent(path string) {
func (self *FileSystem) PathNotPresent(path string) *FileSystem {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
})
return self
}
// Asserts that the file at the given path has the given content
func (self *FileSystem) FileContent(path string, matcher *TextMatcher) {
func (self *FileSystem) FileContent(path string, matcher *TextMatcher) *FileSystem {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
@ -46,4 +48,5 @@ func (self *FileSystem) FileContent(path string, matcher *TextMatcher) {
return true, ""
})
return self
}