Fixing bug in url query reader and added test cases

This commit is contained in:
tariq1890
2018-08-07 18:43:59 -07:00
parent 6f1b125c48
commit e8dfbe94b1
3 changed files with 50 additions and 1 deletions
+27
View File
@@ -4,6 +4,7 @@ import (
"testing"
. "github.com/smartystreets/goconvey/convey"
"net/url"
)
func TestUrl(t *testing.T) {
@@ -43,4 +44,30 @@ func TestUrl(t *testing.T) {
So(result, ShouldEqual, "http://localhost:8080/api/")
})
Convey("When joining two urls where lefthand side has a trailing slash and righthand side has preceding slash", t, func() {
result := JoinUrlFragments("http://localhost:8080/", "/api/")
So(result, ShouldEqual, "http://localhost:8080/api/")
})
}
func TestNewUrlQueryReader(t *testing.T) {
u, _ := url.Parse("http://www.abc.com/foo?bar=baz&bar2=baz2")
uqr, _ := NewUrlQueryReader(u)
Convey("when trying to retrieve the first query value", t, func() {
result := uqr.Get("bar", "foodef")
So(result, ShouldEqual, "baz")
})
Convey("when trying to retrieve the second query value", t, func() {
result := uqr.Get("bar2", "foodef")
So(result, ShouldEqual, "baz2")
})
Convey("when trying to retrieve from a non-existent key, the default value is returned", t, func() {
result := uqr.Get("bar3", "foodef")
So(result, ShouldEqual, "foodef")
})
}