You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

util_test.go 933 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestURLJoin(t *testing.T) {
  10. type test struct {
  11. Expected string
  12. Base string
  13. Elements []string
  14. }
  15. newTest := func(expected, base string, elements ...string) test {
  16. return test{Expected: expected, Base: base, Elements: elements}
  17. }
  18. for _, test := range []test{
  19. newTest("https://try.gitea.io/a/b/c",
  20. "https://try.gitea.io", "a/b", "c"),
  21. newTest("https://try.gitea.io/a/b/c",
  22. "https://try.gitea.io/", "/a/b/", "/c/"),
  23. newTest("https://try.gitea.io/a/c",
  24. "https://try.gitea.io/", "/a/./b/", "../c/"),
  25. newTest("a/b/c",
  26. "a", "b/c/"),
  27. newTest("a/b/d",
  28. "a/", "b/c/", "/../d/"),
  29. } {
  30. assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...))
  31. }
  32. }