diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-03-22 15:30:40 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-03-22 22:30:40 +0800 |
commit | d349f059afa7dc3597ab565d4bb9d4c0271806fc (patch) | |
tree | eb92a6662637caaf77494e87a8b591bf74528a4e | |
parent | bbbd08edc126adadc121d956d2d0a7a061b5ed02 (diff) | |
download | gitea-d349f059afa7dc3597ab565d4bb9d4c0271806fc.tar.gz gitea-d349f059afa7dc3597ab565d4bb9d4c0271806fc.zip |
Cleaner IMO (#1361)
-rw-r--r-- | models/models_test.go | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/models/models_test.go b/models/models_test.go index 01d723182a..649b1e02e5 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -11,15 +11,45 @@ import ( ) func Test_parsePostgreSQLHostPort(t *testing.T) { - test := func(input, expectedHost, expectedPort string) { - host, port := parsePostgreSQLHostPort(input) - assert.Equal(t, expectedHost, host) - assert.Equal(t, expectedPort, port) + tests := []struct { + HostPort string + Host string + Port string + }{ + { + HostPort: "127.0.0.1:1234", + Host: "127.0.0.1", + Port: "1234", + }, + { + HostPort: "127.0.0.1", + Host: "127.0.0.1", + Port: "5432", + }, + { + HostPort: "[::1]:1234", + Host: "[::1]", + Port: "1234", + }, + { + HostPort: "[::1]", + Host: "[::1]", + Port: "5432", + }, + { + HostPort: "/tmp/pg.sock:1234", + Host: "/tmp/pg.sock", + Port: "1234", + }, + { + HostPort: "/tmp/pg.sock", + Host: "/tmp/pg.sock", + Port: "5432", + }, + } + for _, test := range tests { + host, port := parsePostgreSQLHostPort(test.HostPort) + assert.Equal(t, test.Host, host) + assert.Equal(t, test.Port, port) } - test("127.0.0.1:1234", "127.0.0.1", "1234") - test("127.0.0.1", "127.0.0.1", "5432") - test("[::1]:1234", "[::1]", "1234") - test("[::1]", "[::1]", "5432") - test("/tmp/pg.sock:1234", "/tmp/pg.sock", "1234") - test("/tmp/pg.sock", "/tmp/pg.sock", "5432") } |