forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilepath_test.go
39 lines (35 loc) · 921 Bytes
/
filepath_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
package util
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCleanRelativePath(t *testing.T) {
testcases := []struct {
input string
expectedPath string
}{
{
input: "",
expectedPath: ".",
},
{
input: filepath.Join(string(filepath.Separator), "test", "test.txt"),
expectedPath: filepath.Join("test", "test.txt"),
},
{
input: filepath.Join("..", "..", "test", "test.txt"),
expectedPath: filepath.Join("test", "test.txt"),
},
{
// since filepath.Join will remove the leading dot, we need to build the path manually
input: "." + string(filepath.Separator) + filepath.Join("..", "test", "test.txt"),
expectedPath: filepath.Join("test", "test.txt"),
},
}
for _, tt := range testcases {
path, err := CleanRelativePath(tt.input)
assert.NoError(t, err)
assert.Equal(t, tt.expectedPath, path)
}
}