1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

50 lines
1.4 KiB
Go
Raw Normal View History

2022-12-27 15:22:31 +11:00
package components
import (
"fmt"
"os"
)
type FileSystem struct {
*assertionHelper
}
// This does _not_ check the files panel, it actually checks the filesystem
func (self *FileSystem) PathPresent(path string) {
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
return err == nil, fmt.Sprintf("Expected path '%s' to exist, but it does not", path)
})
}
// This does _not_ check the files panel, it actually checks the filesystem
func (self *FileSystem) PathNotPresent(path string) {
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)
})
}
2022-12-28 13:24:23 +11:00
// Asserts that the file at the given path has the given content
func (self *FileSystem) FileContent(path string, matcher *TextMatcher) {
2022-12-28 13:24:23 +11:00
self.assertWithRetries(func() (bool, string) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false, fmt.Sprintf("Expected path '%s' to not exist, but it does", path)
}
output, err := os.ReadFile(path)
if err != nil {
return false, fmt.Sprintf("Expected error when reading file content at path '%s': %s", path, err.Error())
}
strOutput := string(output)
if ok, errMsg := matcher.context("").test(strOutput); !ok {
return false, fmt.Sprintf("Unexpected content in file %s: %s", path, errMsg)
}
return true, ""
})
}