mirror of https://github.com/pulumi/pulumi.git
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package engine
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAbbreviateFilePath(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
path string
|
|
expected string
|
|
}{
|
|
{
|
|
path: "/Users/username/test-policy",
|
|
expected: "/Users/username/test-policy",
|
|
},
|
|
{
|
|
path: "./..//test-policy",
|
|
expected: "../test-policy",
|
|
},
|
|
{
|
|
path: `/Users/username/averylongpath/one/two/three/four/` +
|
|
`five/six/seven/eight/nine/ten/eleven/twelve/test-policy`,
|
|
expected: "/Users/.../twelve/test-policy",
|
|
},
|
|
{
|
|
path: `nonrootdir/username/averylongpath/one/two/three/four/` +
|
|
`five/six/seven/eight/nine/ten/eleven/twelve/test-policy`,
|
|
expected: "nonrootdir/username/.../twelve/test-policy",
|
|
},
|
|
{
|
|
path: `C:/Documents and Settings/username/My Documents/averylongpath/` +
|
|
`one/two/three/four/five/six/seven/eight/test-policy`,
|
|
expected: "C:/Documents and Settings/.../eight/test-policy",
|
|
},
|
|
{
|
|
path: `C:\Documents and Settings\username\My Documents\averylongpath\` +
|
|
`one\two\three\four\five\six\seven\eight\test-policy`,
|
|
expected: `C:\Documents and Settings\...\eight\test-policy`,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
actual := abbreviateFilePath(tt.path)
|
|
assert.Equal(t, filepath.ToSlash(tt.expected), filepath.ToSlash(actual))
|
|
}
|
|
}
|