Test Failed
Push — master ( 48539b...98b3e2 )
by Valentin
02:01
created

cmd/scancmd/writers/csv_test.go   A

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 38
dl 0
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writers.convertMap 0 8 3
B writers.TestPackLine 0 32 7
1
package writers
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"github.com/vvval/go-metadata-scanner/vars"
7
	"github.com/vvval/go-metadata-scanner/vars/metadata"
8
	"reflect"
9
	"testing"
10
)
11
12
func TestPackLine(t *testing.T) {
13
	type check struct {
14
		f      vars.File
15
		groups []string
16
		exp    map[string]map[string]string
17
		ok     bool
18
	}
19
20
	set := []check{
21
		{
22
			vars.NewFile("file1.jpg", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "XMP:tag2": "xmp tag2", "iptc:tag3": "iptc tag3"}),
23
			[]string{"filename", "XMP", "iptc"},
24
			map[string]map[string]string{"XMP": {"tag1": "xmp tag1", "tag2": "xmp tag2"}, "iptc": {"tag3": "iptc tag3"}},
25
			true,
26
		},
27
		{
28
			vars.NewFile("file2.png", metadata.Tags{"test:tag": "some test tag", "XMP:tag1": "xmp tag1", "XMP:tag2": "xmp tag2", "iptc:tag2": "iptc tag2"}),
29
			[]string{"filename", "XMP", "iptc"},
30
			map[string]map[string]string{"xmp": {"tag1": "xmp tag1"}, "IPTC": {"tag2": "iptc tag2"}},
31
			false,
32
		},
33
	}
34
35
	//Case sensitive comparison
36
	for i, s := range set {
37
		p := packCSVLine(&s.f, s.groups)
38
		fmt.Printf("ppp %+v\n", p)
39
		exp := convertMap(s.exp)
40
		if !reflect.DeepEqual(p[1:], exp) && s.ok {
41
			t.Errorf("grouping tags failed (line `%d`) (wrong inequality):\ngot `%v`\nexpected `%t` `%v`", i, p, s.ok, exp)
42
		} else if reflect.DeepEqual(p[1:], exp) && !s.ok {
43
			t.Errorf("grouping tags failed (line `%d`) (wrong equality):\ngot `%v`\nexpected `%t` `%v`", i, p, s.ok, exp)
44
		}
45
	}
46
}
47
48
func convertMap(i map[string]map[string]string) []string {
49
	var o []string
50
	for _, v := range i {
51
		s, _ := json.Marshal(v)
52
		o = append(o, string(s))
53
	}
54
55
	return o
56
}
57