2022-06-11 21:02:06 +00:00
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
2022-06-13 18:07:32 +00:00
|
|
|
"net/url"
|
2022-06-11 21:02:06 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestJoinURL(t *testing.T) {
|
2022-06-13 18:07:32 +00:00
|
|
|
baseURL := ""
|
|
|
|
assert.EqualValues(t, "/", joinURL(baseURL))
|
|
|
|
assert.EqualValues(t, "/", joinURL(baseURL, "", ""))
|
2022-06-11 21:02:06 +00:00
|
|
|
|
2022-06-13 18:07:32 +00:00
|
|
|
baseURL = "http://wwow.url.com"
|
|
|
|
assert.EqualValues(t, "http://wwow.url.com/a/b/c/d", joinURL(baseURL, "a", "b/c/", "d"))
|
2022-06-11 21:02:06 +00:00
|
|
|
|
2022-06-13 18:07:32 +00:00
|
|
|
baseURL = "http://wow.url.com/subpath/2"
|
|
|
|
assert.EqualValues(t, "http://wow.url.com/subpath/2/content.pdf", joinURL(baseURL, "/content.pdf"))
|
|
|
|
assert.EqualValues(t, "http://wow.url.com/subpath/2/wonderful.jpg", joinURL(baseURL, "wonderful.jpg"))
|
|
|
|
assert.EqualValues(t, "http://wow.url.com/subpath/2/raw/wonderful.jpg?ref=main", joinURL(baseURL, "raw", "wonderful.jpg"+"?ref="+url.QueryEscape("main")))
|
|
|
|
assert.EqualValues(t, "http://wow.url.com/subpath/2/raw/wonderful.jpg%3Fref=main", joinURL(baseURL, "raw", "wonderful.jpg%3Fref=main"))
|
2022-06-11 21:02:06 +00:00
|
|
|
}
|