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{})
| 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. |
| 1816 | func 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. |