urls_test.go 877 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package flags
  2. import (
  3. "testing"
  4. )
  5. func TestValidateURLsValueBad(t *testing.T) {
  6. tests := []string{
  7. // bad IP specification
  8. ":4001",
  9. "127.0:8080",
  10. "123:456",
  11. // bad port specification
  12. "127.0.0.1:foo",
  13. "127.0.0.1:",
  14. // unix sockets not supported
  15. "unix://",
  16. "unix://tmp/etcd.sock",
  17. // bad strings
  18. "somewhere",
  19. "234#$",
  20. "file://foo/bar",
  21. "http://hello/asdf",
  22. "http://10.1.1.1",
  23. }
  24. for i, in := range tests {
  25. u := URLsValue{}
  26. if err := u.Set(in); err == nil {
  27. t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
  28. }
  29. }
  30. }
  31. func TestValidateURLsValueGood(t *testing.T) {
  32. tests := []string{
  33. "https://1.2.3.4:8080",
  34. "http://10.1.1.1:80",
  35. "http://localhost:80",
  36. "http://:80",
  37. }
  38. for i, in := range tests {
  39. u := URLsValue{}
  40. if err := u.Set(in); err != nil {
  41. t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
  42. }
  43. }
  44. }