-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpaths_test.go
More file actions
62 lines (48 loc) · 1.58 KB
/
paths_test.go
File metadata and controls
62 lines (48 loc) · 1.58 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package utils
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_MakeRelativePathsAbsolute(t *testing.T) {
baseDir := t.TempDir()
differentAbsDir := t.TempDir()
t.Run("resolves relative paths", func(t *testing.T) {
input := []string{".snyk.env", ".envrc"}
result := MakeRelativePathsAbsolute(baseDir, input)
assert.Equal(t, []string{
filepath.Join(baseDir, ".snyk.env"),
filepath.Join(baseDir, ".envrc"),
}, result)
})
t.Run("leaves absolute paths unchanged", func(t *testing.T) {
absPath := filepath.Join(differentAbsDir, "config.env")
input := []string{absPath}
result := MakeRelativePathsAbsolute(baseDir, input)
assert.Equal(t, []string{absPath}, result)
})
t.Run("handles mix of relative and absolute", func(t *testing.T) {
absPath := filepath.Join(differentAbsDir, "config.env")
input := []string{absPath, ".snyk.env"}
result := MakeRelativePathsAbsolute(baseDir, input)
assert.Equal(t, []string{
absPath,
filepath.Join(baseDir, ".snyk.env"),
}, result)
})
t.Run("returns empty slice for empty input", func(t *testing.T) {
result := MakeRelativePathsAbsolute(baseDir, []string{})
assert.Empty(t, result)
})
t.Run("returns empty slice for nil input", func(t *testing.T) {
result := MakeRelativePathsAbsolute(baseDir, nil)
assert.Empty(t, result)
})
t.Run("does not modify original slice", func(t *testing.T) {
input := []string{".snyk.env", ".envrc"}
original := make([]string, len(input))
copy(original, input)
MakeRelativePathsAbsolute(baseDir, input)
assert.Equal(t, original, input)
})
}