config_test.go 816 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestSplitProto(t *testing.T) {
  6. var tests = []struct {
  7. input string
  8. proto string
  9. addr string
  10. }{
  11. {
  12. input: "localhost",
  13. proto: "",
  14. addr: "localhost",
  15. },
  16. {
  17. input: "tls://my.local.domain",
  18. proto: "tls",
  19. addr: "my.local.domain",
  20. },
  21. {
  22. input: "starttls://my.local.domain",
  23. proto: "starttls",
  24. addr: "my.local.domain",
  25. },
  26. }
  27. for i, test := range tests {
  28. testName := test.input
  29. t.Run(testName, func(t *testing.T) {
  30. pa := splitProto(test.input)
  31. if pa.protocol != test.proto {
  32. t.Errorf("Testcase %d: Incorrect proto: expected %v, got %v",
  33. i, test.proto, pa.protocol)
  34. }
  35. if pa.address != test.addr {
  36. t.Errorf("Testcase %d: Incorrect addr: expected %v, got %v",
  37. i, test.addr, pa.address)
  38. }
  39. })
  40. }
  41. }