Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

models_test.go 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }