mirror of
https://github.com/rclone/rclone.git
synced 2025-08-15 00:02:35 +02:00
Factor ShellExpand from sftp backend to lib/env
This commit is contained in:
31
lib/env/env_test.go
vendored
Normal file
31
lib/env/env_test.go
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
package env
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestShellExpand(t *testing.T) {
|
||||
home, err := homedir.Dir()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.Setenv("EXPAND_TEST", "potato"))
|
||||
defer func() {
|
||||
require.NoError(t, os.Unsetenv("EXPAND_TEST"))
|
||||
}()
|
||||
for _, test := range []struct {
|
||||
in, want string
|
||||
}{
|
||||
{"", ""},
|
||||
{"~", home},
|
||||
{"~/dir/file.txt", home + "/dir/file.txt"},
|
||||
{"/dir/~/file.txt", "/dir/~/file.txt"},
|
||||
{"~/${EXPAND_TEST}", home + "/potato"},
|
||||
} {
|
||||
got := ShellExpand(test.in)
|
||||
assert.Equal(t, test.want, got, test.in)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user