urls_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package flags
  14. import (
  15. "testing"
  16. )
  17. func TestValidateURLsValueBad(t *testing.T) {
  18. tests := []string{
  19. // bad IP specification
  20. ":4001",
  21. "127.0:8080",
  22. "123:456",
  23. // bad port specification
  24. "127.0.0.1:foo",
  25. "127.0.0.1:",
  26. // unix sockets not supported
  27. "unix://",
  28. "unix://tmp/etcd.sock",
  29. // bad strings
  30. "somewhere",
  31. "234#$",
  32. "file://foo/bar",
  33. "http://hello/asdf",
  34. "http://10.1.1.1",
  35. }
  36. for i, in := range tests {
  37. u := URLsValue{}
  38. if err := u.Set(in); err == nil {
  39. t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
  40. }
  41. }
  42. }
  43. func TestValidateURLsValueGood(t *testing.T) {
  44. tests := []string{
  45. "https://1.2.3.4:8080",
  46. "http://10.1.1.1:80",
  47. "http://localhost:80",
  48. "http://:80",
  49. }
  50. for i, in := range tests {
  51. u := URLsValue{}
  52. if err := u.Set(in); err != nil {
  53. t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
  54. }
  55. }
  56. }