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{})
| 1688 | // FileExists checks whether a file exists in the given path. It also fails if |
| 1689 | // the path points to a directory or there is an error when trying to check the file. |
| 1690 | func FileExists(t TestingT, path string, msgAndArgs ...interface{}) bool { |
| 1691 | if h, ok := t.(tHelper); ok { |
| 1692 | h.Helper() |
| 1693 | } |
| 1694 | info, err := os.Lstat(path) |
| 1695 | if err != nil { |
| 1696 | if os.IsNotExist(err) { |
| 1697 | return Fail(t, fmt.Sprintf("unable to find file %q", path), msgAndArgs...) |
| 1698 | } |
| 1699 | return Fail(t, fmt.Sprintf("error when running os.Lstat(%q): %s", path, err), msgAndArgs...) |
| 1700 | } |
| 1701 | if info.IsDir() { |
| 1702 | return Fail(t, fmt.Sprintf("%q is a directory", path), msgAndArgs...) |
| 1703 | } |
| 1704 | return true |
| 1705 | } |
| 1706 | |
| 1707 | // NoFileExists checks whether a file does not exist in a given path. It fails |
| 1708 | // if the path points to an existing _file_ only. |
searching dependent graphs…