MCPcopy
hub / github.com/puma/puma-dev / WithWorkingDirectory

Function WithWorkingDirectory

dev/devtest/testutils.go:148–168  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

146// WithWorkingDirectory executes the passed function within the context of
147// the passed working directory path. If the directory does not exist, panic.
148func 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.
171func RemoveAppSymlinkOrFail(t *testing.T, name string) {

Callers 2

TestCommand_link_noArgsFunction · 0.85

Calls 1

fFunction · 0.50

Tested by 2

TestCommand_link_noArgsFunction · 0.68