1
mirror of https://github.com/rclone/rclone synced 2024-11-21 22:50:16 +01:00
rclone/fs/mount_helper_test.go
Hugal31 a36fef8a66
rclone.mount: ignore _netdev mount argument - FIxes #5808
Do not trigger an error upon parsing argument starting with underscores.

_netdev was already ignored after parsing.
2022-05-12 20:27:13 +01:00

54 lines
1.1 KiB
Go

package fs
import (
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMountHelperArgs(t *testing.T) {
type testCase struct {
src []string
dst []string
env string
err string
}
normalCases := []testCase{{
src: []string{},
dst: []string{"mount", "--daemon"},
}, {
src: []string{"-o", `x-systemd.automount,vvv,env.HTTPS_PROXY="a b;c,d?EF",ro,rw,args2env,_netdev`},
dst: []string{"mount", "--read-only", "--verbose=3", "--daemon"},
env: "HTTPS_PROXY=a b;c,d?EF",
}}
for _, tc := range normalCases {
exe := []string{"rclone"}
src := append(exe, tc.src...)
res, err := convertMountHelperArgs(src)
if tc.err != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.err)
continue
}
require.NoError(t, err)
require.Greater(t, len(res), 1)
assert.Equal(t, exe[0], res[0])
dst := res[1:]
//log.Printf("%q -> %q", tc.src, dst)
assert.Equal(t, tc.dst, dst)
if tc.env != "" {
idx := strings.Index(tc.env, "=")
name, value := tc.env[:idx], tc.env[idx+1:]
assert.Equal(t, value, os.Getenv(name))
}
}
}