conf_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package megauploader
  2. import "testing"
  3. type TestCase struct {
  4. G Global
  5. P string // path
  6. E string // expected
  7. }
  8. var good = []TestCase{
  9. // simplest case
  10. TestCase{G: Global{ViewPathBase: "/", ViewURLBase: "http://localhost/"}, P: "/", E: "http://localhost/"},
  11. // prefix == path
  12. TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/"}, P: "/asd/", E: "http://localhost/"},
  13. // path has something more
  14. TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/"}, P: "/asd/foo", E: "http://localhost/foo"},
  15. // URL has a path
  16. TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost/bla/"}, P: "/asd/foo", E: "http://localhost/bla/foo"},
  17. // removing slashes does not affect the result
  18. TestCase{G: Global{ViewPathBase: "/asd", ViewURLBase: "http://localhost/bla"}, P: "/asd/foo", E: "http://localhost/bla/foo"},
  19. // URL has port
  20. TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost:1234/"}, P: "/asd/foo", E: "http://localhost:1234/foo"},
  21. // URL has params
  22. TestCase{G: Global{ViewPathBase: "/asd/", ViewURLBase: "http://localhost:1234/?k=v"}, P: "/asd/foo", E: "http://localhost:1234/foo?k=v"},
  23. }
  24. func TestViewURL(t *testing.T) {
  25. for _, test := range good {
  26. val, err := test.G.GetViewURL(test.P)
  27. if err != nil {
  28. t.Error(err)
  29. }
  30. if val.String() != test.E {
  31. t.Fail()
  32. }
  33. }
  34. }