package imagestore

import (
	"testing"
	"time"
)

func TestSignURLUsesDynamicPublicBase(t *testing.T) {
	current := "http://localhost:8293"
	store := New(nil, t.TempDir(), func() string { return current }, "test-key", time.Hour)

	if got := store.SignURL("img-1"); !hasPrefix(got, "http://localhost:8293/files/img-1") {
		t.Fatalf("unexpected url: %s", got)
	}

	current = "https://gateway.example.com"
	if got := store.SignURL("img-2"); !hasPrefix(got, "https://gateway.example.com/files/img-2") {
		t.Fatalf("expected updated base url, got: %s", got)
	}
}

func hasPrefix(s, prefix string) bool {
	return len(s) >= len(prefix) && s[:len(prefix)] == prefix
}
