You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1001 B

  1. package main
  2. import (
  3. "testing"
  4. )
  5. var testCases = []struct {
  6. name string
  7. str string
  8. expected bool
  9. }{
  10. {"Well-formed IPv4 with port", "127.0.0.1:4443", true},
  11. {"Well-formed IPv4 without port", "127.0.0.1", false},
  12. {"Malformed IPv4 with port", "127..0.1:4443", false},
  13. {"Malformed IPv4 without port", "127..0.1", false},
  14. {"Well-formed IPv6 with port - 2", "[::1]:4443", true},
  15. {"Well-formed IPv6 without port", "[fe80::1%25en0]", false},
  16. {"Malformed IPv6 with port", "[::::1]:4443", false},
  17. {"Malformed IPv6 without port", "[::::::::1]", false},
  18. {"Malformed IPv6 : missing square brackets", "::::::::1:4443", false},
  19. {"Well-formed DNS name with port", "toto.circl.lu:4443", true},
  20. {"Well-formed DNS name without port", "toto.circl.lu", false},
  21. {"Malformed DNS name with port", ".:4443", false},
  22. }
  23. func TestIsNet(t *testing.T) {
  24. for _, tc := range testCases {
  25. t.Run(tc.name, func(t *testing.T) {
  26. b, _ := isNet(tc.str)
  27. if b != tc.expected {
  28. t.Fail()
  29. }
  30. })
  31. }
  32. }