gempub/gempub_test.go

55 lines
894 B
Go

package gempub
import (
"embed"
"io/fs"
"testing"
)
//go:embed testdata/*
var testdata embed.FS
func TestGoodMetadata(t *testing.T) {
fnames, err := fs.Glob(testdata, "testdata/metadata/good/*")
if err != nil {
t.Fatal(err)
}
for _, fname := range fnames {
t.Run(fname, func(t *testing.T) {
fin, err := testdata.Open(fname)
if err != nil {
t.Fatal(err)
}
defer fin.Close()
_, err = ReadMetadata(fin)
if err != nil {
t.Fatal(err)
}
})
}
}
func TestBadMetadata(t *testing.T) {
fnames, err := fs.Glob(testdata, "testdata/metadata/bad/*")
if err != nil {
t.Fatal(err)
}
for _, fname := range fnames {
t.Run(fname, func(t *testing.T) {
fin, err := testdata.Open(fname)
if err != nil {
t.Fatal(err)
}
defer fin.Close()
_, err = ReadMetadata(fin)
if err == nil {
t.Fatal("wanted error, but got none")
}
})
}
}