models_test.go 934 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2015 - Present, The Gogs Authors. All rights reserved.
  2. // Copyright 2018 - Present, Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package models
  7. import (
  8. "testing"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. func Test_parsePostgreSQLHostPort(t *testing.T) {
  12. testSuites := []struct {
  13. input string
  14. host, port string
  15. }{
  16. {"127.0.0.1:1234", "127.0.0.1", "1234"},
  17. {"127.0.0.1", "127.0.0.1", "5432"},
  18. {"[::1]:1234", "[::1]", "1234"},
  19. {"[::1]", "[::1]", "5432"},
  20. {"/tmp/pg.sock:1234", "/tmp/pg.sock", "1234"},
  21. {"/tmp/pg.sock", "/tmp/pg.sock", "5432"},
  22. }
  23. Convey("Parse PostgreSQL host and port", t, func() {
  24. for _, suite := range testSuites {
  25. host, port := parsePostgreSQLHostPort(suite.input)
  26. So(host, ShouldEqual, suite.host)
  27. So(port, ShouldEqual, suite.port)
  28. }
  29. })
  30. }