1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2021 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.
package pipeline
import (
"errors"
"os"
"rescribe.xyz/bookpipeline"
"testing"
)
func Test_CheckImages(t *testing.T) {
cases := []struct {
dir string
err error
}{
{"testdata/good", nil},
{"testdata/bad", errors.New("Decoding image testdata/bad/bad.png failed: png: invalid format: invalid checksum")},
{"testdata/notreadable", errors.New("Opening image testdata/notreadable/1.png failed: open testdata/notreadable/1.png: permission denied")},
}
for _, c := range cases {
t.Run(c.dir, func(t *testing.T) {
if c.dir == "testdata/notreadable" {
err := os.Chmod("testdata/notreadable/1.png", 0000)
if err != nil {
t.Fatalf("Error preparing test by setting file to be unreadable: %v", err)
}
}
err := CheckImages(c.dir)
if err == nil && c.err != nil {
t.Fatalf("Expected error '%v', got no error", c.err)
}
if err != nil && c.err == nil {
t.Fatalf("Expected no error, got error '%v'", err)
}
if err != nil && c.err != nil && err.Error() != c.err.Error() {
t.Fatalf("Got an unexpected error, expected '%v', got '%v'", c.err, err)
}
if c.dir == "testdata/notreadable" {
err := os.Chmod("testdata/notreadable/1.png", 0644)
if err != nil {
t.Fatalf("Error resetting test by setting file to be readable: %v", err)
}
}
})
}
}
func Test_DetectQueueType(t *testing.T) {
conn := &bookpipeline.LocalConn{}
cases := []struct {
dir string
qid string
}{
{"testdata/mostlypng", conn.WipeQueueId()},
{"testdata/mostlyjpg", conn.PreQueueId()},
{"testdata/equalpngandjpg", conn.PreQueueId()},
{"testdata/nonexistent", conn.PreQueueId()},
}
for _, c := range cases {
t.Run(c.dir, func(t *testing.T) {
qid := DetectQueueType(c.dir, conn)
if qid != c.qid {
t.Fatalf("Error, expected qid %v, got qid %v", qid, c.qid)
}
})
}
}
|