mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
ef60c90dfa
* make path handling OS agnostic * PR feedback * fix input for test case
40 lines
921 B
Go
40 lines
921 B
Go
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)
|
|
}
|
|
}
|