-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_test.go
executable file
·47 lines (37 loc) · 1.14 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
package scaffold
import (
"net/http"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestURL(t *testing.T) {
Convey("Given a request", t, func() {
req, err := http.NewRequest("POST", "http://www.example.com/some/path/here", nil)
So(err, ShouldBeNil)
Convey("When the url is split", func() {
ctx, parts := URLParts(nil, req)
Convey("Then the parts should be correct", func() {
So(parts, ShouldResemble, []string{"some", "path", "here"})
})
Convey("Then the parts should exist in the context", func() {
parts, ok := ctx.Value("scaffold_url_parts").([]string)
So(ok, ShouldBeTrue)
So(parts, ShouldResemble, []string{"some", "path", "here"})
})
})
Convey("When a url part is a accessed", func() {
_, part, ok := URLPart(nil, req, 1)
Convey("Then the part should be correct", func() {
So(ok, ShouldBeTrue)
So(part, ShouldEqual, "path")
})
})
Convey("When a url part that does not exist is a accessed", func() {
_, part, ok := URLPart(nil, req, 10)
Convey("Then the part should be correct", func() {
So(ok, ShouldBeFalse)
So(part, ShouldEqual, "")
})
})
})
}