urls_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 CoreOS, Inc.
  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. "testing"
  17. )
  18. func TestValidateURLsValueBad(t *testing.T) {
  19. tests := []string{
  20. // bad IP specification
  21. ":2379",
  22. "127.0:8080",
  23. "123:456",
  24. // bad port specification
  25. "127.0.0.1:foo",
  26. "127.0.0.1:",
  27. // unix sockets not supported
  28. "unix://",
  29. "unix://tmp/etcd.sock",
  30. // bad strings
  31. "somewhere",
  32. "234#$",
  33. "file://foo/bar",
  34. "http://hello/asdf",
  35. "http://10.1.1.1",
  36. }
  37. for i, in := range tests {
  38. u := URLsValue{}
  39. if err := u.Set(in); err == nil {
  40. t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
  41. }
  42. }
  43. }
  44. func TestValidateURLsValueGood(t *testing.T) {
  45. tests := []string{
  46. "https://1.2.3.4:8080",
  47. "http://10.1.1.1:80",
  48. "http://localhost:80",
  49. "http://:80",
  50. }
  51. for i, in := range tests {
  52. u := URLsValue{}
  53. if err := u.Set(in); err != nil {
  54. t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
  55. }
  56. }
  57. }