models_test.go 678 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func Test_parsePostgreSQLHostPort(t *testing.T) {
  7. testSuites := []struct {
  8. input string
  9. host, port string
  10. }{
  11. {"127.0.0.1:1234", "127.0.0.1", "1234"},
  12. {"127.0.0.1", "127.0.0.1", "5432"},
  13. {"[::1]:1234", "[::1]", "1234"},
  14. {"[::1]", "[::1]", "5432"},
  15. {"/tmp/pg.sock:1234", "/tmp/pg.sock", "1234"},
  16. {"/tmp/pg.sock", "/tmp/pg.sock", "5432"},
  17. }
  18. Convey("Parse PostgreSQL host and port", t, func() {
  19. for _, suite := range testSuites {
  20. host, port := parsePostgreSQLHostPort(suite.input)
  21. So(host, ShouldEqual, suite.host)
  22. So(port, ShouldEqual, suite.port)
  23. }
  24. })
  25. }