MCPcopy
hub / github.com/stretchr/testify / FileExists

Function FileExists

assert/assertions.go:1781–1796  ·  assert/assertions.go::FileExists

FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.

(t TestingT, path string, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1779// FileExists checks whether a file exists in the given path. It also fails if
1780// the path points to a directory or there is an error when trying to check the file.
1781func FileExists(t TestingT, path string, msgAndArgs ...interface{}) bool {
1782 if h, ok := t.(tHelper); ok {
1783 h.Helper()
1784 }
1785 info, err := os.Lstat(path)
1786 if err != nil {
1787 if os.IsNotExist(err) {
1788 return Fail(t, fmt.Sprintf("unable to find file %q", path), msgAndArgs...)
1789 }
1790 return Fail(t, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), msgAndArgs...)
1791 }
1792 if info.IsDir() {
1793 return Fail(t, fmt.Sprintf("%q is a directory", path), msgAndArgs...)
1794 }
1795 return true
1796}
1797
1798// NoFileExists checks whether a file does not exist in a given path. It fails
1799// if the path points to an existing _file_ only.

Callers 4

FileExistsFunction · 0.92
FileExistsfFunction · 0.70
TestFileExistsFunction · 0.70
FileExistsMethod · 0.70

Calls 2

FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestFileExistsFunction · 0.56