MCPcopy Index your code
hub / github.com/gotify/server / TestWithWd

Function TestWithWd

test/filepath_test.go:16–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14}
15
16func TestWithWd(t *testing.T) {
17 wd1, _ := os.Getwd()
18 tmpDir := NewTmpDir("gotify_withwd")
19 defer tmpDir.Clean()
20 var wd2 string
21 WithWd(tmpDir.Path(), func(origWd string) {
22 assert.Equal(t, wd1, origWd)
23 wd2, _ = os.Getwd()
24 })
25 wd3, _ := os.Getwd()
26 assert.Equal(t, wd1, wd3)
27 assert.Equal(t, tmpDir.Path(), wd2)
28 assert.Nil(t, os.RemoveAll(tmpDir.Path()))
29
30 assert.Panics(t, func() {
31 WithWd("non_exist", func(string) {})
32 })
33
34 assert.Nil(t, os.Mkdir(tmpDir.Path(), 0o644))
35 if os.Getuid() != 0 { // root is not subject to this check
36 assert.Panics(t, func() {
37 WithWd(tmpDir.Path(), func(string) {})
38 })
39 }
40 assert.Nil(t, os.Remove(tmpDir.Path()))
41
42 assert.Nil(t, os.Mkdir(tmpDir.Path(), 0o755))
43 assert.Panics(t, func() {
44 WithWd(tmpDir.Path(), func(string) {
45 assert.Nil(t, os.RemoveAll(tmpDir.Path()))
46 WithWd(".", func(string) {})
47 })
48 })
49}

Callers

nothing calls this directly

Calls 4

CleanMethod · 0.95
PathMethod · 0.95
NewTmpDirFunction · 0.85
WithWdFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…