WithWorkingDirectory executes the passed function within the context of the passed working directory path. If the directory does not exist, panic.
(path string, f func())
| 146 | // WithWorkingDirectory executes the passed function within the context of |
| 147 | // the passed working directory path. If the directory does not exist, panic. |
| 148 | func WithWorkingDirectory(path string, f func()) { |
| 149 | if _, err := os.Stat(path); os.IsNotExist(err) { |
| 150 | panic(err) |
| 151 | } |
| 152 | |
| 153 | originalPath, err := os.Getwd() |
| 154 | |
| 155 | if err != nil { |
| 156 | panic(err) |
| 157 | } |
| 158 | |
| 159 | if err := os.Chdir(path); err != nil { |
| 160 | panic(err) |
| 161 | } |
| 162 | |
| 163 | f() |
| 164 | |
| 165 | if err := os.Chdir(originalPath); err != nil { |
| 166 | panic(err) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // RemoveAppSymlinkOrFail deletes a symlink at ~/.puma-dev/{name} or fails the test. |
| 171 | func RemoveAppSymlinkOrFail(t *testing.T, name string) { |