-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage_test.go
37 lines (35 loc) · 1.11 KB
/
page_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
package main
import (
"errors"
"net/url"
"testing"
)
func TestPageString(t *testing.T) {
type fields struct {
location *url.URL
links []*url.URL
err error
}
tests := []struct {
name string
fields fields
want string
}{
{"No Links", fields{URL("https://bbc.co.uk"), []*url.URL{}, nil}, "Page{location:https://bbc.co.uk, links: [], err: <nil>}"},
{"One Link", fields{URL("https://bbc.co.uk"), []*url.URL{URL("/one")}, nil}, "Page{location:https://bbc.co.uk, links: [/one], err: <nil>}"},
{"Many Links", fields{URL("https://bbc.co.uk"), []*url.URL{URL("/one"), URL("/two")}, nil}, "Page{location:https://bbc.co.uk, links: [/one /two], err: <nil>}"},
{"Error", fields{URL("https://bbc.co.uk"), []*url.URL{}, errors.New("some error")}, "Page{location:https://bbc.co.uk, links: [], err: some error}"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
page := &Page{
location: tt.fields.location,
links: tt.fields.links,
err: tt.fields.err,
}
if got := page.String(); got != tt.want {
t.Errorf("Page.String() = %v, want %v", got, tt.want)
}
})
}
}