forked from ttacon/uri
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdefault_ports_test.go
More file actions
50 lines (45 loc) · 1.06 KB
/
default_ports_test.go
File metadata and controls
50 lines (45 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package uri
import (
"testing"
"github.com/stretchr/testify/require"
)
type defautPortTest struct {
uriRaw string
comment string
expectIsDefault bool
expectedDefault int
}
func TestDefaultPorts(t *testing.T) {
for _, toPin := range []defautPortTest{
{
uriRaw: "http://host:80",
comment: "default http port",
expectIsDefault: true,
expectedDefault: 80,
},
{
uriRaw: "http://host:8080",
comment: "non-default http port",
expectIsDefault: false,
expectedDefault: 80,
},
{
uriRaw: "postgresql://host:6532",
comment: "non-default posgresql port",
expectIsDefault: false,
expectedDefault: 5432,
},
} {
test := toPin
u, err := Parse(test.uriRaw)
require.NoError(t, err)
t.Run(test.comment, func(t *testing.T) {
t.Run("with IsDefaultPort", func(t *testing.T) {
require.Equal(t, test.expectIsDefault, u.IsDefaultPort())
})
t.Run("with DefaultPort", func(t *testing.T) {
require.Equal(t, test.expectedDefault, u.DefaultPort())
})
})
}
}