-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_test.go
55 lines (48 loc) · 1.55 KB
/
url_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
51
52
53
54
55
package domain_test
import (
"testing"
"github.com/sokool/domain"
)
func TestURL_UnmarshalJSON(t *testing.T) {
//var u domain.URL
//assert.Error(t, u.UnmarshalJSON([]byte(`""`)))
//assert.Error(t, u.UnmarshalJSON([]byte(`" asdf r"`)))
//assert.Error(t, u.UnmarshalJSON([]byte(`"rollee"`)))
//
//assert.NoError(t, u.UnmarshalJSON(nil))
//assert.NoError(t, u.UnmarshalJSON([]byte(``)))
//assert.NoError(t, u.UnmarshalJSON([]byte(`null`)))
//assert.NoError(t, u.UnmarshalJSON([]byte(`"https://greg:[email protected]:8888/documents/january-invoice.pdf?version=3"`)))
//
//assert.Equal(t, u.Schema, "https")
//assert.Equal(t, u.Username, "greg")
//assert.Equal(t, u.Password, "j6G1Df7")
//assert.Equal(t, u.Host, "rollee.io")
//assert.Equal(t, u.Port, "8888")
//assert.Equal(t, u.Path, []string{"documents", "january-invoice.pdf"})
//assert.Equal(t, u.Query, url.Values{"version": {"3"}})
}
func TestURL_IsZero(t *testing.T) {
//var u domain.URL
//assert.Equal(t, u.IsZero(), true)
}
func TestNewURL(t *testing.T) {
type scenario struct {
description string
url string
err bool
}
cases := []scenario{
{"empty string fails", "", true},
{"host and no schema fails", "wosp.org.pl", true},
{"schema,host is ok", "https://wosp.org.pl", false},
{"schema,host,path is ok", "https://wosp.org.pl/", false},
}
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
if _, err := domain.NewURL(c.url); (err != nil && !c.err) || (err == nil && c.err) {
t.Fatalf("expected error:%v got:%v", c.err, err)
}
})
}
}