mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 19:00:54 -06:00
8261613b51
See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... ip.go:8:6⚠️ func SplitIpPort should be SplitIPPort (golint) url.go:14:6⚠️ func NewUrlQueryReader should be NewURLQueryReader (golint) url.go:9:6⚠️ type UrlQueryReader should be URLQueryReader (golint) url.go:37:6⚠️ func JoinUrlFragments should be JoinURLFragments (golint)
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package util
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestUrl(t *testing.T) {
|
|
|
|
Convey("When joining two urls where right hand side is empty", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080", "")
|
|
|
|
So(result, ShouldEqual, "http://localhost:8080")
|
|
})
|
|
|
|
Convey("When joining two urls where right hand side is empty and lefthand side has a trailing slash", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080/", "")
|
|
|
|
So(result, ShouldEqual, "http://localhost:8080/")
|
|
})
|
|
|
|
Convey("When joining two urls where neither has a trailing slash", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080", "api")
|
|
|
|
So(result, ShouldEqual, "http://localhost:8080/api")
|
|
})
|
|
|
|
Convey("When joining two urls where lefthand side has a trailing slash", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080/", "api")
|
|
|
|
So(result, ShouldEqual, "http://localhost:8080/api")
|
|
})
|
|
|
|
Convey("When joining two urls where righthand side has preceding slash", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080", "/api")
|
|
|
|
So(result, ShouldEqual, "http://localhost:8080/api")
|
|
})
|
|
|
|
Convey("When joining two urls where righthand side has trailing slash", t, func() {
|
|
result := JoinURLFragments("http://localhost:8080", "api/")
|
|
|
|
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")
|
|
})
|
|
}
|