addrs_test.go 757 B

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