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{})
| 1723 | // DirExists checks whether a directory exists in the given path. It also fails |
| 1724 | // if the path is a file rather a directory or there is an error checking whether it exists. |
| 1725 | func DirExists(t TestingT, path string, msgAndArgs ...interface{}) bool { |
| 1726 | if h, ok := t.(tHelper); ok { |
| 1727 | h.Helper() |
| 1728 | } |
| 1729 | info, err := os.Lstat(path) |
| 1730 | if err != nil { |
| 1731 | if os.IsNotExist(err) { |
| 1732 | return Fail(t, fmt.Sprintf("unable to find file %q", path), msgAndArgs...) |
| 1733 | } |
| 1734 | return Fail(t, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), msgAndArgs...) |
| 1735 | } |
| 1736 | if !info.IsDir() { |
| 1737 | return Fail(t, fmt.Sprintf("%q is a file", path), msgAndArgs...) |
| 1738 | } |
| 1739 | return true |
| 1740 | } |
| 1741 | |
| 1742 | // NoDirExists checks whether a directory does not exist in the given path. |
| 1743 | // It fails if the path points to an existing _directory_ only. |
searching dependent graphs…