unique_strings_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package flags
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestNewUniqueStrings(t *testing.T) {
  20. tests := []struct {
  21. s string
  22. exp map[string]struct{}
  23. rs string
  24. }{
  25. { // non-URL but allowed by exception
  26. s: "*",
  27. exp: map[string]struct{}{"*": {}},
  28. rs: "*",
  29. },
  30. {
  31. s: "",
  32. exp: map[string]struct{}{},
  33. rs: "",
  34. },
  35. {
  36. s: "example.com",
  37. exp: map[string]struct{}{"example.com": {}},
  38. rs: "example.com",
  39. },
  40. {
  41. s: "localhost,localhost",
  42. exp: map[string]struct{}{"localhost": {}},
  43. rs: "localhost",
  44. },
  45. {
  46. s: "b.com,a.com",
  47. exp: map[string]struct{}{"a.com": {}, "b.com": {}},
  48. rs: "a.com,b.com",
  49. },
  50. {
  51. s: "c.com,b.com",
  52. exp: map[string]struct{}{"b.com": {}, "c.com": {}},
  53. rs: "b.com,c.com",
  54. },
  55. }
  56. for i := range tests {
  57. uv := NewUniqueStringsValue(tests[i].s)
  58. if !reflect.DeepEqual(tests[i].exp, uv.Values) {
  59. t.Fatalf("#%d: expected %+v, got %+v", i, tests[i].exp, uv.Values)
  60. }
  61. if uv.String() != tests[i].rs {
  62. t.Fatalf("#%d: expected %q, got %q", i, tests[i].rs, uv.String())
  63. }
  64. }
  65. }