Asserts that the file at the given path has the given content
(path string, matcher *TextMatcher)
| 29 | |
| 30 | // Asserts that the file at the given path has the given content |
| 31 | func (self *FileSystem) FileContent(path string, matcher *TextMatcher) *FileSystem { |
| 32 | self.assertWithRetries(func() (bool, string) { |
| 33 | _, err := os.Stat(path) |
| 34 | if os.IsNotExist(err) { |
| 35 | return false, fmt.Sprintf("Expected path '%s' to exist, but it does not", path) |
| 36 | } |
| 37 | |
| 38 | output, err := os.ReadFile(path) |
| 39 | if err != nil { |
| 40 | return false, fmt.Sprintf("Expected error when reading file content at path '%s': %s", path, err.Error()) |
| 41 | } |
| 42 | |
| 43 | strOutput := string(output) |
| 44 | |
| 45 | if ok, errMsg := matcher.context("").test(strOutput); !ok { |
| 46 | return false, fmt.Sprintf("Unexpected content in file %s: %s", path, errMsg) |
| 47 | } |
| 48 | |
| 49 | return true, "" |
| 50 | }) |
| 51 | return self |
| 52 | } |
no test coverage detected