Completed
Push — master ( e66762...2df545 )
by Valentin
02:05
created

operations.testMapPayload   A

Complexity

Conditions 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nop 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
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