33 lines
996 B
Go
33 lines
996 B
Go
package asset
|
|
|
|
import "testing"
|
|
|
|
func TestResolvePublicFileURLs(t *testing.T) {
|
|
params := map[string]any{
|
|
"image": "/api/v1/user/files/1?exp=1&sig=abc",
|
|
"prompt": "cat",
|
|
"refs": []any{"/api/v1/user/files/2?exp=1&sig=def"},
|
|
}
|
|
ResolvePublicFileURLs(params, "https://atlas.example.com")
|
|
if params["image"] != "https://atlas.example.com/api/v1/user/files/1?exp=1&sig=abc" {
|
|
t.Fatalf("unexpected image url: %v", params["image"])
|
|
}
|
|
if params["prompt"] != "cat" {
|
|
t.Fatalf("prompt should be unchanged")
|
|
}
|
|
refs, ok := params["refs"].([]any)
|
|
if !ok || refs[0] != "https://atlas.example.com/api/v1/user/files/2?exp=1&sig=def" {
|
|
t.Fatalf("unexpected refs: %v", params["refs"])
|
|
}
|
|
}
|
|
|
|
func TestResolvePublicFileURLsSkipsAbsolute(t *testing.T) {
|
|
params := map[string]any{
|
|
"image": "https://cdn.example.com/a.png",
|
|
}
|
|
ResolvePublicFileURLs(params, "https://atlas.example.com")
|
|
if params["image"] != "https://cdn.example.com/a.png" {
|
|
t.Fatalf("absolute url should be unchanged")
|
|
}
|
|
}
|