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