-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifier_test.go
More file actions
76 lines (59 loc) · 1.65 KB
/
modifier_test.go
File metadata and controls
76 lines (59 loc) · 1.65 KB
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
package ff_test
import (
"context"
"testing"
"github.com/mmcdole/gofeed"
"github.com/nakatanakatana/ff"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
type modifierFuncTest struct {
key string
value string
expect gofeed.Item
}
func TestCreateModifierInvalidKey(t *testing.T) {
t.Parallel()
modifiersMap := ff.CreateModifierMap()
f := ff.CreateModifier("invalidKey", "value", modifiersMap)
if f != nil {
t.Fail()
}
}
func TestCreateModifier(t *testing.T) {
t.Parallel()
modifiersMap := ff.CreateModifierMap()
testItem := createTestItem()
expectRemoveDescription := *testItem
expectRemoveDescription.Description = ""
expectRemoveContent := *testItem
expectRemoveContent.Content = ""
for _, tt := range []modifierFuncTest{
// remove
{key: "rm.description", value: "", expect: expectRemoveDescription},
{key: "rm.content", value: "", expect: expectRemoveContent},
} {
tt := tt
t.Run(tt.key, func(t *testing.T) {
t.Parallel()
f := ff.CreateModifier(tt.key, tt.value, modifiersMap)
result := f(testItem)
assert.Check(t, is.DeepEqual(tt.expect, *result))
})
}
}
func TestCreateModifierWithNonExistentField(t *testing.T) {
t.Parallel()
modifiersMap := ff.CreateModifierMap()
testItem := createTestItem()
f := ff.CreateModifier("rm.nonexistent", "", modifiersMap)
assert.Assert(t, f == nil)
// check that the item is not modified
modifiers := []ff.ModifierFunc{}
if f != nil {
modifiers = append(modifiers, f)
}
result, err := ff.Apply(context.Background(), &gofeed.Feed{Items: []*gofeed.Item{testItem}}, nil, modifiers)
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(testItem, result.Items[0]))
}