-
Notifications
You must be signed in to change notification settings - Fork 4
/
item_test.go
85 lines (75 loc) · 2.12 KB
/
item_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// item_test.go
// ~~~~~~~~~
// This module implements the Item tests.
// :authors: Konstantin Bokarius.
// :copyright: (c) 2015 by Fanout, Inc.
// :license: MIT, see LICENSE for more details.
package pubcontrol
import (
"github.com/stretchr/testify/assert"
"testing"
)
type FormatTestStruct1 struct {
value string
}
func (format *FormatTestStruct1) Name() string {
return "test-format"
}
func (format *FormatTestStruct1) Export() interface{} {
return format.value
}
type FormatTestStruct2 struct {
value string
}
func (format *FormatTestStruct2) Name() string {
return "test-format2"
}
func (format *FormatTestStruct2) Export() interface{} {
return format.value
}
var fmt1a Formatter = &FormatTestStruct1{value: "value1a"}
var fmt1b Formatter = &FormatTestStruct1{value: "value1b"}
var fmt2 Formatter = &FormatTestStruct2{value: "value2"}
func TestItemInitialize(t *testing.T) {
formats := make([]Formatter, 0)
formats = append(formats, fmt1a)
item := NewItem(formats, "id", "prev-id")
assert.Equal(t, item.id, "id")
assert.Equal(t, item.prevId, "prev-id")
assert.Equal(t, item.formats[0], fmt1a)
}
func TestItemExport(t *testing.T) {
formats := make([]Formatter, 0)
formats = append(formats, fmt1a)
formats = append(formats, fmt2)
item := NewItem(formats, "id", "prev-id")
export, err := item.Export()
assert.Nil(t, err)
assert.Equal(t, export["id"], "id")
assert.Equal(t, export["prev-id"], "prev-id")
assert.Equal(t, export["test-format"], "value1a")
assert.Equal(t, export["test-format2"], "value2")
formats = make([]Formatter, 0)
formats = append(formats, fmt1b)
item = NewItem(formats, "", "")
export, err = item.Export()
assert.Nil(t, err)
assert.Equal(t, export["test-format"], "value1b")
if _, ok := export["id"]; ok {
t.Log("id not set")
t.FailNow()
}
if _, ok := export["prev-id"]; ok {
t.Log("prev-id not set")
t.FailNow()
}
}
func TestItemExportError(t *testing.T) {
formats := make([]Formatter, 0)
formats = append(formats, fmt1a)
formats = append(formats, fmt1b)
item := NewItem(formats, "id", "prev-id")
export, err := item.Export()
assert.Nil(t, export)
assert.NotNil(t, err)
}