Add logo feature
This commit is contained in:
@@ -97,17 +97,19 @@ func TestHTMLTemplate(t *testing.T) {
|
||||
|
||||
// Test template execution with sample data
|
||||
data := struct {
|
||||
DirName string
|
||||
Entries []FileEntry
|
||||
DirAppend bool
|
||||
OutputFile string
|
||||
IsRoot bool
|
||||
DirName string
|
||||
Entries []FileEntry
|
||||
DirAppend bool
|
||||
OutputFile string
|
||||
IsRoot bool
|
||||
WatermarkURL string
|
||||
}{
|
||||
DirName: "test-dir",
|
||||
Entries: []FileEntry{},
|
||||
DirAppend: false,
|
||||
OutputFile: "index.html",
|
||||
IsRoot: false,
|
||||
DirName: "test-dir",
|
||||
Entries: []FileEntry{},
|
||||
DirAppend: false,
|
||||
OutputFile: "index.html",
|
||||
IsRoot: false,
|
||||
WatermarkURL: "",
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -159,17 +161,19 @@ func TestHTMLTemplateWithEntries(t *testing.T) {
|
||||
}
|
||||
|
||||
data := struct {
|
||||
DirName string
|
||||
Entries []FileEntry
|
||||
DirAppend bool
|
||||
OutputFile string
|
||||
IsRoot bool
|
||||
DirName string
|
||||
Entries []FileEntry
|
||||
DirAppend bool
|
||||
OutputFile string
|
||||
IsRoot bool
|
||||
WatermarkURL string
|
||||
}{
|
||||
DirName: "test-dir",
|
||||
Entries: entries,
|
||||
DirAppend: false,
|
||||
OutputFile: "index.html",
|
||||
IsRoot: false,
|
||||
DirName: "test-dir",
|
||||
Entries: entries,
|
||||
DirAppend: false,
|
||||
OutputFile: "index.html",
|
||||
IsRoot: false,
|
||||
WatermarkURL: "",
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -196,6 +200,62 @@ func TestHTMLTemplateWithEntries(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLTemplateWithWatermark(t *testing.T) {
|
||||
tmpl := GetHTMLTemplate()
|
||||
if tmpl == nil {
|
||||
t.Fatal("GetHTMLTemplate() returned nil")
|
||||
}
|
||||
|
||||
// Test template execution with watermark
|
||||
data := struct {
|
||||
DirName string
|
||||
Entries []FileEntry
|
||||
DirAppend bool
|
||||
OutputFile string
|
||||
IsRoot bool
|
||||
WatermarkURL string
|
||||
}{
|
||||
DirName: "test-dir",
|
||||
Entries: []FileEntry{},
|
||||
DirAppend: false,
|
||||
OutputFile: "index.html",
|
||||
IsRoot: false,
|
||||
WatermarkURL: "https://example.com/logo.svg",
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := tmpl.Execute(&buf, data)
|
||||
if err != nil {
|
||||
t.Fatalf("Template execution with watermark failed: %v", err)
|
||||
}
|
||||
|
||||
output := buf.String()
|
||||
|
||||
// Check that watermark image is included
|
||||
if !bytes.Contains([]byte(output), []byte(`src="https://example.com/logo.svg"`)) {
|
||||
t.Error("Template output should contain watermark image URL")
|
||||
}
|
||||
|
||||
if !bytes.Contains([]byte(output), []byte(`class="watermark"`)) {
|
||||
t.Error("Template output should contain watermark CSS class")
|
||||
}
|
||||
|
||||
// Test without watermark
|
||||
data.WatermarkURL = ""
|
||||
buf.Reset()
|
||||
err = tmpl.Execute(&buf, data)
|
||||
if err != nil {
|
||||
t.Fatalf("Template execution without watermark failed: %v", err)
|
||||
}
|
||||
|
||||
outputNoWatermark := buf.String()
|
||||
|
||||
// Check that watermark image is NOT included when URL is empty
|
||||
if bytes.Contains([]byte(outputNoWatermark), []byte(`class="watermark"`)) {
|
||||
t.Error("Template output should not contain watermark when URL is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadDirEntries(t *testing.T) {
|
||||
// Create a temporary directory with test files
|
||||
tempDir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user