-
Notifications
You must be signed in to change notification settings - Fork 51
/
address_test.go
50 lines (38 loc) · 1.01 KB
/
address_test.go
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 main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseAddress_ParseValidDomainAddressWithDefaults(t *testing.T) {
assertions := assert.New(t)
tests := []struct {
Host string
DefaultUser string
DefaultPort int
ExpectedUser string
ExpectedDomain string
ExpectedPort int
}{
{"example.com", "_", 23,
"_", "example.com", 23},
{"[email protected]", "_", 23,
"user", "example.com", 23},
{"example.com:1234", "_", 23,
"_", "example.com", 1234},
{"[email protected]:1234", "_", 23,
"user", "example.com", 1234},
{"example.com:1234", "user", 23,
"user", "example.com", 1234},
{"[email protected]:1234", "user", 23,
"user2", "example.com", 1234},
}
for _, test := range tests {
parsed, err := parseAddress(
test.Host, test.DefaultUser, test.DefaultPort,
)
assertions.Nil(err)
assertions.Equal(test.ExpectedUser, parsed.user)
assertions.Equal(test.ExpectedPort, parsed.port)
assertions.Equal(test.ExpectedDomain, parsed.domain)
}
}