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.

25 lines
727 B

  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func Test_parsePostgreSQLHostPort(t *testing.T) {
  10. test := func(input, expectedHost, expectedPort string) {
  11. host, port := parsePostgreSQLHostPort(input)
  12. assert.Equal(t, expectedHost, host)
  13. assert.Equal(t, expectedPort, port)
  14. }
  15. test("127.0.0.1:1234", "127.0.0.1", "1234")
  16. test("127.0.0.1", "127.0.0.1", "5432")
  17. test("[::1]:1234", "[::1]", "1234")
  18. test("[::1]", "[::1]", "5432")
  19. test("/tmp/pg.sock:1234", "/tmp/pg.sock", "1234")
  20. test("/tmp/pg.sock", "/tmp/pg.sock", "5432")
  21. }