-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurls_test.go
55 lines (45 loc) · 1.01 KB
/
urls_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 env
import (
"os"
"strings"
"testing"
"net/url"
. "github.com/smartystreets/goconvey/convey"
)
func TestParse_urls(t *testing.T) {
Convey("url", t, func() {
defer resetEnv(os.Environ())
url, err := url.Parse("http://www.google.com")
So(err, ShouldBeNil)
expected := &TestConfig{
MyURL: url,
}
actual := &TestConfig{}
os.Setenv("myurl", url.String())
err = Parse(actual)
So(err, ShouldBeNil)
So(actual, ShouldResemble, expected)
})
Convey("url slice", t, func() {
defer resetEnv(os.Environ())
rawUrls := []string{
"http://www.google.com",
"http://www.reddit.com",
"192.168.0.1",
}
urls := make([]*url.URL, len(rawUrls), len(rawUrls))
for i, rawUrl := range rawUrls {
url, err := url.Parse(rawUrl)
So(err, ShouldBeNil)
urls[i] = url
}
expected := &TestConfig{
MyURLArr: urls,
}
actual := &TestConfig{}
os.Setenv("myurlarr", strings.Join(rawUrls, ", "))
err := Parse(actual)
So(err, ShouldBeNil)
So(actual, ShouldResemble, expected)
})
}