Browse Source

Cleaner IMO (#1361)

Kim "BKC" Carlbäcker 2 years ago
parent
commit
d349f059af
1 changed files with 40 additions and 10 deletions
  1. 40 10
      models/models_test.go

+ 40 - 10
models/models_test.go

@@ -11,15 +11,45 @@ import (
11 11
 )
12 12
 
13 13
 func Test_parsePostgreSQLHostPort(t *testing.T) {
14
-	test := func(input, expectedHost, expectedPort string) {
15
-		host, port := parsePostgreSQLHostPort(input)
16
-		assert.Equal(t, expectedHost, host)
17
-		assert.Equal(t, expectedPort, port)
14
+	tests := []struct {
15
+		HostPort string
16
+		Host     string
17
+		Port     string
18
+	}{
19
+		{
20
+			HostPort: "127.0.0.1:1234",
21
+			Host:     "127.0.0.1",
22
+			Port:     "1234",
23
+		},
24
+		{
25
+			HostPort: "127.0.0.1",
26
+			Host:     "127.0.0.1",
27
+			Port:     "5432",
28
+		},
29
+		{
30
+			HostPort: "[::1]:1234",
31
+			Host:     "[::1]",
32
+			Port:     "1234",
33
+		},
34
+		{
35
+			HostPort: "[::1]",
36
+			Host:     "[::1]",
37
+			Port:     "5432",
38
+		},
39
+		{
40
+			HostPort: "/tmp/pg.sock:1234",
41
+			Host:     "/tmp/pg.sock",
42
+			Port:     "1234",
43
+		},
44
+		{
45
+			HostPort: "/tmp/pg.sock",
46
+			Host:     "/tmp/pg.sock",
47
+			Port:     "5432",
48
+		},
49
+	}
50
+	for _, test := range tests {
51
+		host, port := parsePostgreSQLHostPort(test.HostPort)
52
+		assert.Equal(t, test.Host, host)
53
+		assert.Equal(t, test.Port, port)
18 54
 	}
19
-	test("127.0.0.1:1234", "127.0.0.1", "1234")
20
-	test("127.0.0.1", "127.0.0.1", "5432")
21
-	test("[::1]:1234", "[::1]", "1234")
22
-	test("[::1]", "[::1]", "5432")
23
-	test("/tmp/pg.sock:1234", "/tmp/pg.sock", "1234")
24
-	test("/tmp/pg.sock", "/tmp/pg.sock", "5432")
25 55
 }