-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimilar_test.go
103 lines (99 loc) · 2.47 KB
/
similar_test.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package ma_test
import (
"fmt"
"io/fs"
"testing"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
"github.com/bzimmer/ma"
)
func TestSimilar(t *testing.T) {
a := assert.New(t)
tests := []harness{
{
name: "similar files",
args: []string{"similar", "/foo/bar"},
counters: map[string]int{
"similar.analyze.true": 1,
"similar.analyze.false": 2,
"similar.path": 4,
"similar.icon.skipped": 1,
},
before: func(c *cli.Context) error {
afs := runtime(c).Fs
a.NoError(afs.MkdirAll("/foo/bar", 0755))
for name, file := range map[string]string{
"/foo/bar/A.jpg": "testdata/Nikon_D70.jpg",
"/foo/bar/B.jpg": "testdata/Fujifilm_FinePix6900ZOOM.jpg",
"/foo/bar/C.jpg": "testdata/Fujifilm_FinePix6900ZOOM.jpg",
"/foo/bar/user_cmac.json": "testdata/user_cmac.json",
} {
fp, err := afs.Create(name)
if err != nil {
a.NoError(err)
}
if err = copyFile(fp, file); err != nil {
a.NoError(err)
}
a.NoError(fp.Close())
}
return nil
},
},
{
name: "permission denied",
args: []string{"similar", "/foo/bar"},
err: "permission denied",
counters: map[string]int{
"similar.path": 1,
"similar.icon.error": 1,
},
before: func(c *cli.Context) error {
afs := runtime(c).Fs
a.NoError(runtime(c).Fs.MkdirAll("/foo/bar", 0755))
fp, err := afs.Create("/foo/bar/user_foo.json")
if err != nil {
a.NoError(err)
}
if err = copyFile(fp, "testdata/user_cmac.json"); err != nil {
a.NoError(err)
}
a.NoError(fp.Close())
runtime(c).Fs = &ErrFs{
Fs: runtime(c).Fs,
err: fs.ErrPermission,
name: "/foo/bar/user_foo.json"}
return nil
},
},
{
name: "no image files",
args: []string{"similar", "-c", "4", "/foo/bar"},
counters: map[string]int{
"similar.path": 10,
"similar.icon.skipped": 10,
},
before: func(c *cli.Context) error {
afs := runtime(c).Fs
a.NoError(runtime(c).Fs.MkdirAll("/foo/bar", 0755))
for i := 0; i < 10; i++ {
fp, err := afs.Create(fmt.Sprintf("/foo/bar/user_foo_%02d.json", i))
if err != nil {
a.NoError(err)
}
if err = copyFile(fp, "testdata/user_cmac.json"); err != nil {
a.NoError(err)
}
a.NoError(fp.Close())
}
return nil
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
run(t, &tt, nil, ma.CommandSimilar)
})
}
}