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

Function DirExists

assert/assertions.go:1816–1831  ·  view source on GitHub ↗

DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.

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

Source from the content-addressed store, hash-verified

1814// DirExists checks whether a directory exists in the given path. It also fails
1815// if the path is a file rather a directory or there is an error checking whether it exists.
1816func DirExists(t TestingT, path string, msgAndArgs ...interface{}) bool {
1817 if h, ok := t.(tHelper); ok {
1818 h.Helper()
1819 }
1820 info, err := os.Lstat(path)
1821 if err != nil {
1822 if os.IsNotExist(err) {
1823 return Fail(t, fmt.Sprintf("unable to find file %q", path), msgAndArgs...)
1824 }
1825 return Fail(t, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), msgAndArgs...)
1826 }
1827 if !info.IsDir() {
1828 return Fail(t, fmt.Sprintf("%q is a file", path), msgAndArgs...)
1829 }
1830 return true
1831}
1832
1833// NoDirExists checks whether a directory does not exist in the given path.
1834// It fails if the path points to an existing _directory_ only.

Callers 4

DirExistsFunction · 0.92
DirExistsfFunction · 0.70
TestDirExistsFunction · 0.70
DirExistsMethod · 0.70

Calls 2

FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestDirExistsFunction · 0.56