Passed
Push — master ( 57f305...4761c3 )
by Valentin
02:06
created

cmd/scancmd/writers/mscsv_test.go   A

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 61
dl 0
loc 104
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A writers.TestTitle 0 27 4
A writers.TestDescription 0 27 4
A writers.TestKeywords 0 31 4
1
package writers
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
	"github.com/vvval/go-metadata-scanner/vars/metadata"
8
	"reflect"
9
	"testing"
10
)
11
12
func TestTitle(t *testing.T) {
13
	type check struct {
14
		f   vars.File
15
		exp string
16
	}
17
18
	set := []check{
19
		{
20
			vars.NewFile("file1.jpg", metadata.Tags{"XMP:Headline": "title test"}),
21
			"title test",
22
		},
23
		{
24
			vars.NewFile("file1.jpg", metadata.Tags{"title": "title test"}),
25
			"",
26
		},
27
		{
28
			vars.NewFile("file1.jpg", metadata.Tags{"XMP:Test": "title test"}),
29
			"",
30
		},
31
	}
32
33
	dict := configuration.Load(config.DictConfig{}, "./../../../dict.yaml").(config.DictConfig)
34
35
	for i, s := range set {
36
		v := title(&s.f, dict)
37
		if v != s.exp {
38
			t.Errorf("title mapping (line `%d`):\ngot `%s`\nexpected `%s`", i, v, s.exp)
39
		}
40
	}
41
}
42
43
func TestDescription(t *testing.T) {
44
	type check struct {
45
		f   vars.File
46
		exp string
47
	}
48
49
	set := []check{
50
		{
51
			vars.NewFile("file1.jpg", metadata.Tags{"EXIF:ImageDescription": "description test"}),
52
			"description test",
53
		},
54
		{
55
			vars.NewFile("file1.jpg", metadata.Tags{"description": "description test"}),
56
			"",
57
		},
58
		{
59
			vars.NewFile("file1.jpg", metadata.Tags{"XMP:ImageDescription": "title test"}),
60
			"",
61
		},
62
	}
63
64
	dict := configuration.Load(config.DictConfig{}, "./../../../dict.yaml").(config.DictConfig)
65
66
	for i, s := range set {
67
		v := description(&s.f, dict)
68
		if v != s.exp {
69
			t.Errorf("description mapping (line `%d`):\ngot `%s`\nexpected `%s`", i, v, s.exp)
70
		}
71
	}
72
}
73
74
func TestKeywords(t *testing.T) {
75
	type check struct {
76
		f   vars.File
77
		exp string
78
	}
79
80
	set := []check{
81
		{
82
			vars.NewFile("file1.jpg", metadata.Tags{"IPTC:Keywords": "keyword1"}),
83
			"keyword1",
84
		},
85
		{
86
			vars.NewFile("file1.jpg", metadata.Tags{"keywords": "keyword2"}),
87
			"",
88
		},
89
		{
90
			vars.NewFile("file1.jpg", metadata.Tags{"XMP:Subject": []string{"keyword1", "keyword2"}}),
91
			"keyword1, keyword2",
92
		},
93
		{
94
			vars.NewFile("file1.jpg", metadata.Tags{"XMP:Subject": 123}),
95
			"123",
96
		},
97
	}
98
99
	dict := configuration.Load(config.DictConfig{}, "./../../../dict.yaml").(config.DictConfig)
100
101
	for i, s := range set {
102
		v := keywords(&s.f, dict)
103
		if !reflect.DeepEqual(v, s.exp) {
104
			t.Errorf("keywords mapping (line `%d`):\ngot `%s`\nexpected `%s`", i, v, s.exp)
105
		}
106
	}
107
}
108