urls_test.go 816 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package flags
  2. import (
  3. "testing"
  4. )
  5. func TestValidateURLsBad(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. }
  23. for i, in := range tests {
  24. u := URLs{}
  25. if err := u.Set(in); err == nil {
  26. t.Errorf(`#%d: unexpected nil error for in=%q`, i, in)
  27. }
  28. }
  29. }
  30. func TestValidateURLsGood(t *testing.T) {
  31. tests := []string{
  32. "https://1.2.3.4:8080",
  33. "http://10.1.1.1:80",
  34. "http://10.1.1.1",
  35. }
  36. for i, in := range tests {
  37. u := URLs{}
  38. if err := u.Set(in); err != nil {
  39. t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
  40. }
  41. }
  42. }