Skip to content

Commit

Permalink
test: create a comicinfo file and lint it against schema (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr committed Sep 25, 2023
1 parent b66ae28 commit 67ea261
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

- name: Install libxml2-utils for xmllint
run: sudo apt-get install libxml2-utils

- name: Setup go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ComicInfo.xsd
.DS_Store
schema.xsd
volume
110 changes: 110 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package comicinfo

import (
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

const schemaURL = "https://raw.githubusercontent.com/anansi-project/comicinfo/main/schema/v2.0/ComicInfo.xsd"

func TestFullSchema(t *testing.T) {
// Download the schema from the URL into a temporary file
tmpDir := t.TempDir()
schemaPath := filepath.Join(tmpDir, "schema.xsd")

resp, err := http.Get(schemaURL)
if err != nil {
t.Errorf("error downloading schema: %s", err)
}

defer resp.Body.Close()

out, err := os.Create(schemaPath)
if err != nil {
t.Errorf("error creating schema file: %s", err)
}

defer out.Close()

_, err = io.Copy(out, resp.Body)
if err != nil {
t.Errorf("error writing schema file: %s", err)
}

// Create a new ComicInfo struct with all the fields filled
ci := NewComicInfo()
ci.Title = "Test"
ci.Series = "Test"
ci.Number = "1"
ci.Count = 1
ci.Volume = 1
ci.AlternateSeries = "Test"
ci.AlternateNumber = "1"
ci.AlternateCount = 1
ci.Summary = "Test"
ci.Notes = "Test"
ci.Year = 2021
ci.Month = 1
ci.Day = 1
ci.Writer = "Test"
ci.Penciller = "Test"
ci.Inker = "Test"
ci.Colorist = "Test"
ci.Letterer = "Test"
ci.CoverArtist = "Test"
ci.Editor = "Test"
ci.Publisher = "Test"
ci.Imprint = "Test"
ci.Genre = "Test"
ci.Web = "Test"
ci.PageCount = 1
ci.LanguageISO = "en"
ci.Format = "Test"
ci.BlackAndWhite = Yes
ci.Manga = MangaYes
ci.Characters = "Test"
ci.Teams = "Test"
ci.Locations = "Test"
ci.ScanInformation = "Test"
ci.StoryArc = "Test"
ci.SeriesGroup = "Test"
ci.AgeRating = AgeRatingEveryone
ci.MainCharacterOrTeam = "Test"
ci.Review = "Test"
ci.Pages.Pages = append(ci.Pages.Pages, ComicPageInfo{
Image: 1,
Type: ComicPageTypeEditorial,
DoublePage: false,
ImageSize: 999,
Key: "?",
Bookmark: "yes",
ImageWidth: 20,
ImageHeight: 21,
})
ci.CommunityRating = 5.0
ci.MainCharacterOrTeam = "Test"
ci.Review = "Test"

// Write the ComicInfo struct to a temporary file
ciPath := filepath.Join(tmpDir, "comicinfo.xml")

err = Write(ci, ciPath)
if err != nil {
t.Errorf("error writing ComicInfo: %v", err)
}

// Validate the schema running xmllint in a process for comicinfo.xml
cmd := exec.Command("xmllint", "--noout", "--schema", schemaPath, ciPath)
output, err := cmd.CombinedOutput()
if err != nil {
t.Errorf("error validating ComicInfo: %s\n\nValidator error: %s", err, output)
}

require.NoError(t, cmd.Err, output)
}

0 comments on commit 67ea261

Please sign in to comment.