forked from sajari/docconv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_ocr_test.go
46 lines (42 loc) · 939 Bytes
/
image_ocr_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
// +build ocr
package docconv
import (
"os"
"path"
"reflect"
"testing"
)
func TestConvertImage(t *testing.T) {
tests := []struct {
image string
wantText string
wantMeta map[string]string
wantErr bool
}{
{
image: "001-helloworld.png",
wantText: "Hello, World!",
wantMeta: map[string]string{},
},
}
for _, tt := range tests {
t.Run(tt.image, func(t *testing.T) {
image, err := os.Open(path.Join("testdata", tt.image))
if err != nil {
t.Fatal(err)
}
defer image.Close()
gotText, gotMeta, err := ConvertImage(image)
if (err != nil) != tt.wantErr {
t.Errorf("ConvertImage() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotText != tt.wantText {
t.Errorf("ConvertImage() text = %v, want %v", gotText, tt.wantText)
}
if !reflect.DeepEqual(gotMeta, tt.wantMeta) {
t.Errorf("ConvertImage() meta = %v, want %v", gotMeta, tt.wantMeta)
}
})
}
}