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.

55 lines
1.0 KiB

  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. tests := []struct {
  11. HostPort string
  12. Host string
  13. Port string
  14. }{
  15. {
  16. HostPort: "127.0.0.1:1234",
  17. Host: "127.0.0.1",
  18. Port: "1234",
  19. },
  20. {
  21. HostPort: "127.0.0.1",
  22. Host: "127.0.0.1",
  23. Port: "5432",
  24. },
  25. {
  26. HostPort: "[::1]:1234",
  27. Host: "[::1]",
  28. Port: "1234",
  29. },
  30. {
  31. HostPort: "[::1]",
  32. Host: "[::1]",
  33. Port: "5432",
  34. },
  35. {
  36. HostPort: "/tmp/pg.sock:1234",
  37. Host: "/tmp/pg.sock",
  38. Port: "1234",
  39. },
  40. {
  41. HostPort: "/tmp/pg.sock",
  42. Host: "/tmp/pg.sock",
  43. Port: "5432",
  44. },
  45. }
  46. for _, test := range tests {
  47. host, port := parsePostgreSQLHostPort(test.HostPort)
  48. assert.Equal(t, test.Host, host)
  49. assert.Equal(t, test.Port, port)
  50. }
  51. }