|
1
|
|
|
package operations |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"github.com/vvval/go-metadata-scanner/config" |
|
5
|
|
|
"github.com/vvval/go-metadata-scanner/configuration" |
|
6
|
|
|
"github.com/vvval/go-metadata-scanner/vars" |
|
7
|
|
|
"reflect" |
|
8
|
|
|
"testing" |
|
9
|
|
|
) |
|
10
|
|
|
|
|
11
|
|
|
func testMapPayload(t *testing.T) { |
|
12
|
|
|
|
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
func TestReadColumns(t *testing.T) { |
|
16
|
|
|
type tag struct { |
|
17
|
|
|
pos int |
|
18
|
|
|
name string |
|
19
|
|
|
found bool |
|
20
|
|
|
} |
|
21
|
|
|
type check struct { |
|
22
|
|
|
cols []string |
|
23
|
|
|
exp []tag |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
set := []check{ |
|
27
|
|
|
{[]string{"abc", "Keywords"}, []tag{ |
|
28
|
|
|
{1, "keywords", true}, |
|
29
|
|
|
}}, |
|
30
|
|
|
{[]string{"", "keywords "}, []tag{ |
|
31
|
|
|
{1, "IPTC:Keywords", true}, |
|
32
|
|
|
}}, |
|
33
|
|
|
{[]string{"", "XMP:Description"}, []tag{ |
|
34
|
|
|
{1, "description", true}, |
|
35
|
|
|
}}, |
|
36
|
|
|
{[]string{"", "keywords", "", "description", "", ""}, []tag{ |
|
37
|
|
|
{1, "keywords", true}, |
|
38
|
|
|
{3, "description", true}, |
|
39
|
|
|
}}, |
|
40
|
|
|
{[]string{"", "keywords", "test"}, []tag{ |
|
41
|
|
|
{1, "keywords", true}, |
|
42
|
|
|
{2, "test", false}, |
|
43
|
|
|
}}, |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
dict := configuration.Load(config.Dict, "./../../../dict.yaml").(config.DictConfig) |
|
47
|
|
|
|
|
48
|
|
|
for i, s := range set { |
|
49
|
|
|
read := readColumns(s.cols) |
|
50
|
|
|
for j, checkTag := range s.exp { |
|
51
|
|
|
foundCheckTag, found := dict.Find(checkTag.name) |
|
52
|
|
|
if found != checkTag.found { |
|
53
|
|
|
t.Errorf("columns mismatch (line `%d`, column `%d`):\ngot `%t` `%+v`\nexp `%t` `%+v`", i, j, found, foundCheckTag, checkTag.found, checkTag) |
|
54
|
|
|
} else if found { |
|
55
|
|
|
mapTag, ok := read[checkTag.pos] |
|
56
|
|
|
if !ok { |
|
57
|
|
|
t.Errorf("columns not found (line `%d`, column `%d`):\nexp `%+v`", i, j, foundCheckTag) |
|
58
|
|
|
} else if !tagsEqual(foundCheckTag, mapTag) { |
|
59
|
|
|
t.Errorf("column tags not equal (line `%d`, column `%d`):\ngot `%+v`\nexp `%+v`", i, j, mapTag, foundCheckTag) |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
func tagsEqual(t1, t2 vars.Tag) bool { |
|
67
|
|
|
if t1.Key() != t2.Key() { |
|
68
|
|
|
return false |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if !reflect.DeepEqual(t1.Map(), t2.Map()) { |
|
72
|
|
|
return false |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return true |
|
76
|
|
|
} |
|
77
|
|
|
|