config_test.go 1.1 KB

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