Fix test failure

This commit is contained in:
Neale Pickett 2021-10-14 19:17:38 -06:00
parent 41a0e6dffc
commit d9299f5e59
2 changed files with 25 additions and 8 deletions

View File

@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Writing a new mothball with the same name is now detected and the new mothball loaded (#172)
- Regression test for issue where URL path leading directories were ignored (#144)
### Changed
- Many error messages were changed to start with a lower-case letter,
in order to satisfy a new linter check.
## [v4.2.2] - 2021-09-30
### Added
- `debug.notes` front matter field

View File

@ -9,9 +9,11 @@ import (
"github.com/spf13/afero"
)
var testFiles = []struct {
type testFileContents struct {
Name, Body string
}{
}
var testFiles = []testFileContents{
{"puzzles.txt", "1\n3\n2\n"},
{"answers.txt", "1 answer123\n1 answer456\n2 wat\n"},
{"1/puzzle.json", `{"name": "moo"}`},
@ -21,7 +23,7 @@ var testFiles = []struct {
{"3/moo.txt", `moo`},
}
func (m *Mothballs) createMothballWithMoo1(cat string, moo1 string) {
func (m *Mothballs) createMothballWithFiles(cat string, contents []testFileContents) {
f, _ := m.Create(fmt.Sprintf("%s.mb", cat))
defer f.Close()
@ -32,13 +34,19 @@ func (m *Mothballs) createMothballWithMoo1(cat string, moo1 string) {
of, _ := w.Create(file.Name)
of.Write([]byte(file.Body))
}
of, _ := w.Create("1/moo.txt")
of.Write([]byte(moo1))
for _, file := range contents {
of, _ := w.Create(file.Name)
of.Write([]byte(file.Body))
}
}
func (m *Mothballs) createMothball(cat string) {
m.createMothballWithMoo1(cat, "moo")
m.createMothballWithFiles(
cat,
[]testFileContents{
{"1/moo.txt", "moo"},
},
)
}
func NewTestMothballs() *Mothballs {
@ -105,7 +113,12 @@ func TestMothballs(t *testing.T) {
goofyText := "bozonics"
//time.Sleep(1 * time.Second) // I don't love this, but we need the mtime to increase, and it's only accurate to 1s
m.createMothballWithMoo1("pategory", goofyText)
m.createMothballWithFiles(
"pategory",
[]testFileContents{
{"1/moo.txt", goofyText},
},
)
m.refresh()
if f, _, err := m.Open("pategory", 1, "moo.txt"); err != nil {
t.Error("pategory/1/moo.txt", err)