2020-12-23 20:09:54 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-23 20:09:54 +01:00
|
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-08 23:57:37 +08:00
|
|
|
"net/url"
|
2020-12-23 20:09:54 +01:00
|
|
|
"testing"
|
|
|
|
|
|
2021-07-25 00:03:58 +08:00
|
|
|
"code.gitea.io/gitea/modules/json"
|
|
|
|
|
|
2020-12-23 20:09:54 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMakeAbsoluteAssetURL(t *testing.T) {
|
2026-03-08 23:57:37 +08:00
|
|
|
appURL1, _ := url.Parse("https://localhost:1234")
|
|
|
|
|
appURL2, _ := url.Parse("https://localhost:1234/")
|
|
|
|
|
appURLSub1, _ := url.Parse("https://localhost:1234/foo")
|
|
|
|
|
appURLSub2, _ := url.Parse("https://localhost:1234/foo/")
|
|
|
|
|
|
|
|
|
|
// static URL is an absolute URL, so should be used
|
|
|
|
|
assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL(appURL1, "https://localhost:2345"))
|
|
|
|
|
assert.Equal(t, "https://localhost:2345", MakeAbsoluteAssetURL(appURL1, "https://localhost:2345/"))
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL1, "/foo"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL2, "/foo"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURL1, "/foo/"))
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub1, "/foo"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub2, "/foo"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/foo", MakeAbsoluteAssetURL(appURLSub1, "/foo/"))
|
|
|
|
|
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub1, "/bar"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub2, "/bar"))
|
|
|
|
|
assert.Equal(t, "https://localhost:1234/bar", MakeAbsoluteAssetURL(appURLSub1, "/bar/"))
|
2020-12-23 20:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMakeManifestData(t *testing.T) {
|
|
|
|
|
jsonBytes := MakeManifestData(`Example App '\"`, "https://example.com", "https://example.com/foo/bar")
|
|
|
|
|
assert.True(t, json.Valid(jsonBytes))
|
|
|
|
|
}
|