github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/cmd/config/config_test.go (about) 1 package config 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/rclone/rclone/fs/rc" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestArgsToMap(t *testing.T) { 12 for _, test := range []struct { 13 args []string 14 want rc.Params 15 wantErr bool 16 }{ 17 { 18 args: []string{}, 19 want: rc.Params{}, 20 }, 21 { 22 args: []string{"hello", "42"}, 23 want: rc.Params{"hello": "42"}, 24 }, 25 { 26 args: []string{"hello", "42", "bye", "43"}, 27 want: rc.Params{"hello": "42", "bye": "43"}, 28 }, 29 { 30 args: []string{"hello=42", "bye", "43"}, 31 want: rc.Params{"hello": "42", "bye": "43"}, 32 }, 33 { 34 args: []string{"hello", "42", "bye=43"}, 35 want: rc.Params{"hello": "42", "bye": "43"}, 36 }, 37 { 38 args: []string{"hello=42", "bye=43"}, 39 want: rc.Params{"hello": "42", "bye": "43"}, 40 }, 41 { 42 args: []string{"hello", "42", "bye", "43", "unused"}, 43 wantErr: true, 44 }, 45 { 46 args: []string{"hello=42", "bye=43", "unused"}, 47 wantErr: true, 48 }, 49 } { 50 what := fmt.Sprintf("args = %#v", test.args) 51 got, err := argsToMap(test.args) 52 if test.wantErr { 53 assert.Error(t, err, what) 54 } else { 55 assert.NoError(t, err, what) 56 assert.Equal(t, test.want, got, what) 57 } 58 } 59 }