host_test.go 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package host
  2. import (
  3. "net"
  4. "os"
  5. "testing"
  6. )
  7. func TestHost(t *testing.T) {
  8. host := New()
  9. var ips []net.IP
  10. hostname, _ := os.Hostname()
  11. if err := host.SetService(""); err == nil {
  12. t.Fatal("Not expecting empty service name to be valid")
  13. }
  14. if err := host.SetService("service"); err != nil {
  15. t.Fatal(err)
  16. }
  17. if err := host.SetHostname(hostname); err == nil {
  18. t.Fatal("Hostname should contain trailing .")
  19. }
  20. if err := host.SetHostname(hostname + "."); err != nil {
  21. t.Fatal(err)
  22. }
  23. if err := host.SetDomain("local"); err == nil {
  24. t.Fatal("Domain should contain trailing .")
  25. }
  26. if err := host.SetDomain("local."); err != nil {
  27. t.Fatal(err)
  28. }
  29. if err := host.SetIPs(ips); err != nil {
  30. t.Fatal(err)
  31. }
  32. if err := host.SetPort(0); err == nil {
  33. t.Fatal("Port should not be 0 or less")
  34. }
  35. if err := host.SetPort(4545); err != nil {
  36. t.Fatal(err)
  37. }
  38. t.Log(host.String())
  39. }