2022-01-11 10:37:58 -06:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2023-12-19 04:01:48 -06:00
|
|
|
"path/filepath"
|
2022-01-11 10:37:58 -06:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCleanRelativePath(t *testing.T) {
|
|
|
|
testcases := []struct {
|
|
|
|
input string
|
|
|
|
expectedPath string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
expectedPath: ".",
|
|
|
|
},
|
|
|
|
{
|
2023-12-19 04:01:48 -06:00
|
|
|
input: filepath.Join(string(filepath.Separator), "test", "test.txt"),
|
|
|
|
expectedPath: filepath.Join("test", "test.txt"),
|
2022-01-11 10:37:58 -06:00
|
|
|
},
|
|
|
|
{
|
2023-12-19 04:01:48 -06:00
|
|
|
input: filepath.Join("..", "..", "test", "test.txt"),
|
|
|
|
expectedPath: filepath.Join("test", "test.txt"),
|
2022-01-11 10:37:58 -06:00
|
|
|
},
|
|
|
|
{
|
2023-12-19 04:01:48 -06:00
|
|
|
// 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"),
|
2022-01-11 10:37:58 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testcases {
|
|
|
|
path, err := CleanRelativePath(tt.input)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.expectedPath, path)
|
|
|
|
}
|
|
|
|
}
|