megauploader/conf_test.go

39 lines
1.3 KiB
Go
Raw Normal View History

2017-09-23 19:46:58 +02:00
package megauploader
import "testing"
type TestCase struct {
G Global
P string // path
E string // expected
}
2017-09-23 20:01:48 +02:00
var good = []TestCase{
2017-09-23 19:46:58 +02:00
// simplest case
TestCase{G: Global{ViewPathBase: "/", ViewURLBase: "http://localhost/"}, P: "/", E: "http://localhost/"},
// prefix == path
TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/"}, P: "/asd/", E: "http://localhost/"},
// path has something more
TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/"}, P: "/asd/foo", E: "http://localhost/foo"},
// URL has a path
TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/bla/"}, P: "/asd/foo", E: "http://localhost/bla/foo"},
// removing slashes does not affect the result
TestCase{G: Global{ViewPathBase: "/asd", ViewURLBase: "http://localhost/bla"}, P: "/asd/foo", E: "http://localhost/bla/foo"},
// URL has port
TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost:1234/"}, P: "/asd/foo", E: "http://localhost:1234/foo"},
// URL has params
TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost:1234/?k=v"}, P: "/asd/foo", E: "http://localhost:1234/foo?k=v"},
}
func TestViewURL(t *testing.T) {
for _, test := range good {
2017-09-23 20:01:48 +02:00
val, err := test.G.GetViewURL(test.P)
2017-09-23 19:46:58 +02:00
if err != nil {
t.Error(err)
}
2017-09-23 20:01:48 +02:00
if val.String() != test.E {
2017-09-23 19:46:58 +02:00
t.Fail()
}
}
}