Skip to content

Commit b21e811

Browse files
vanadium23claude
andcommitted
test(metadata): restore Cover and ISBN validation for EPUB
Re-added Cover image comparison using reference files from test_data/covers/ and ISBN field validation. FB2 description skipped due to mojibake in test file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bdf78da commit b21e811

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

pkg/metadata/metadata_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metadata_test
22

33
import (
4+
"io"
45
"os"
56
"path/filepath"
67
"runtime"
@@ -15,12 +16,23 @@ func getProjectRoot() string {
1516
return filepath.Join(filepath.Dir(b), "..", "..")
1617
}
1718

19+
func readAll(path string) []byte {
20+
file, err := os.Open(path)
21+
if err != nil {
22+
return nil
23+
}
24+
defer file.Close()
25+
b, _ := io.ReadAll(file)
26+
return b
27+
}
28+
1829
// epubDescription contains typographic quotes (U+201C, U+201D) and apostrophe (U+2019)
1930
const epubDescription = "(From Wikipedia): Crime and Punishment (Russian: Преступл\u00e9ние и наказ\u00e1ние, Prestupleniye i nakazaniye) is a novel by the Russian author Fyodor Dostoyevsky. It was first published in the literary journal The Russian Messenger in twelve monthly installments during 1866. It was later published in a single volume. It is the second of Dostoyevsky\u2019s full-length novels following his return from ten years of exile in Siberia. Crime and Punishment is the first great novel of his \u201cmature\u201d period of writing. Crime and Punishment focuses on the mental anguish and moral dilemmas of Rodion Raskolnikov, an impoverished ex-student in St. Petersburg who formulates and executes a plan to kill an unscrupulous pawnbroker for her cash. Raskolnikov argues that with the pawnbroker\u2019s money he can perform good deeds to counterbalance the crime, while ridding the world of a worthless vermin. He also commits this murder to test his own hypothesis that some people are naturally capable of such things, and even have the right to do them. Several times throughout the novel, Raskolnikov justifies his actions by comparing himself with Napoleon Bonaparte, believing that murder is permissible in pursuit of a higher purpose."
2031

2132
func TestExtractBookMetadata(t *testing.T) {
2233
projectRoot := getProjectRoot()
2334
booksPath := filepath.Join(projectRoot, "test", "test_data", "books")
35+
coversPath := filepath.Join(projectRoot, "test", "test_data", "covers")
2436

2537
tests := []struct {
2638
name string
@@ -45,8 +57,10 @@ func TestExtractBookMetadata(t *testing.T) {
4557
Language: "en-us",
4658
Publisher: "BB eBooks Co., Ltd.",
4759
Date: "2016-01-03",
48-
Format: "epub",
60+
ISBN: "urn:uuid:12c6fed8-ec29-4343-ab36-9a48312ee01d",
4961
Description: epubDescription,
62+
Format: "epub",
63+
Cover: readAll(filepath.Join(coversPath, "CrimePunishment-EPUB2.jpg")),
5064
},
5165
},
5266
{
@@ -55,6 +69,7 @@ func TestExtractBookMetadata(t *testing.T) {
5569
want: metadata.Metadata{
5670
Title: "Great Expectations",
5771
Format: "fb2",
72+
Cover: readAll(filepath.Join(coversPath, "Great Expectations -- Charles Dickens.jpg")),
5873
},
5974
},
6075
}
@@ -73,6 +88,8 @@ func TestExtractBookMetadata(t *testing.T) {
7388
require.Equal(t, tt.want.Title, got.Title)
7489
require.Equal(t, tt.want.Author, got.Author)
7590
require.Equal(t, tt.want.Format, got.Format)
91+
require.Equal(t, tt.want.ISBN, got.ISBN)
92+
require.Equal(t, tt.want.Cover, got.Cover)
7693
if tt.want.Description != "" {
7794
require.Equal(t, tt.want.Description, got.Description)
7895
}

0 commit comments

Comments
 (0)