-
Notifications
You must be signed in to change notification settings - Fork 0
/
chdir_test.go
40 lines (29 loc) · 970 Bytes
/
chdir_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pathutil
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestChdir(t *testing.T) {
tempdir, err := NewTempDir()
assert.NoError(t, err)
cwd, err := Cwd()
assert.NoError(t, err)
assert.NotEqual(t, tempdir, cwd, "Current working directory isn't same as tempdir")
oldCwd, err := tempdir.Chdir()
assert.NoError(t, err)
// return cwd back
defer func() {
_, err = oldCwd.Chdir()
assert.NoError(t, err)
}()
assert.NotEqual(t, tempdir, cwd, "Old current working directory isn't same as tempdir")
assert.Equal(t, oldCwd, cwd, "Old current working directory is same as returned oldCwd after Chdir")
actualCwd, err := Cwd()
assert.NoError(t, err)
tempdirStr, err := filepath.EvalSymlinks(tempdir.String())
assert.NoError(t, err)
actualCwdStr, err := filepath.EvalSymlinks(actualCwd.String())
assert.NoError(t, err)
assert.Equal(t, tempdirStr, actualCwdStr, "Actual current working directory is tempdir")
}