aboutsummaryrefslogtreecommitdiff
path: root/internal/yaml/yaml_test.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/yaml/yaml_test.go (renamed from internal/config/yaml_test.go)154
1 files changed, 81 insertions, 73 deletions
diff --git a/internal/config/yaml_test.go b/internal/yaml/yaml_test.go
index 1e77700..0e9ef08 100644
--- a/internal/config/yaml_test.go
+++ b/internal/yaml/yaml_test.go
@@ -1,9 +1,12 @@
-package config
+package yaml
import (
"reflect"
"strings"
"testing"
+
+ C "github.com/Necoro/feed2imap-go/internal/config"
+ F "github.com/Necoro/feed2imap-go/internal/feed"
)
func s(s string) *string { return &s }
@@ -21,99 +24,99 @@ func TestBuildFeeds(tst *testing.T) {
wantErr bool
target string
feeds []configGroupFeed
- result Feeds
+ result F.Feeds
}{
- {name: "Empty input", wantErr: false, target: "", feeds: nil, result: Feeds{}},
+ {name: "Empty input", wantErr: false, target: "", feeds: nil, result: F.Feeds{}},
{name: "Empty Feed", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Target: s("foo"), Feed: Feed{Url: "google.de"}},
- }, result: Feeds{}},
+ {Target: s("foo"), Feed: feed{Url: "google.de"}},
+ }, result: F.Feeds{}},
{name: "Empty Feed", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{Url: "google.de"}},
- }, result: Feeds{}},
+ {Target: nil, Feed: feed{Url: "google.de"}},
+ }, result: F.Feeds{}},
{name: "Duplicate Feed Name", wantErr: true, target: "",
feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{Name: "Dup"}},
- {Target: nil, Feed: Feed{Name: "Dup"}},
- }, result: Feeds{}},
+ {Target: nil, Feed: feed{Name: "Dup"}},
+ {Target: nil, Feed: feed{Name: "Dup"}},
+ }, result: F.Feeds{}},
{name: "Simple", wantErr: false, target: "",
feeds: []configGroupFeed{
- {Target: s("foo"), Feed: Feed{Name: "muh"}},
+ {Target: s("foo"), Feed: feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: t("foo")}},
+ result: F.Feeds{"muh": &F.Feed{Name: "muh", Target: t("foo")}},
},
{name: "Simple With Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: s("foo"), Feed: Feed{Name: "muh"}},
+ {Target: s("foo"), Feed: feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}},
+ result: F.Feeds{"muh": &F.Feed{Name: "muh", Target: t("moep.foo")}},
},
{name: "Simple With Nil Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{Name: "muh"}},
+ {Target: nil, Feed: feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.muh")}},
+ result: F.Feeds{"muh": &F.Feed{Name: "muh", Target: t("moep.muh")}},
},
{name: "Simple With Empty Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: s(""), Feed: Feed{Name: "muh"}},
+ {Target: s(""), Feed: feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}},
+ result: F.Feeds{"muh": &F.Feed{Name: "muh", Target: t("moep")}},
},
{name: "Multiple Feeds", wantErr: false, target: "moep",
feeds: []configGroupFeed{
- {Target: s("foo"), Feed: Feed{Name: "muh"}},
- {Target: nil, Feed: Feed{Name: "bar"}},
+ {Target: s("foo"), Feed: feed{Name: "muh"}},
+ {Target: nil, Feed: feed{Name: "bar"}},
},
- result: Feeds{
- "muh": &Feed{Name: "muh", Target: t("moep.foo")},
- "bar": &Feed{Name: "bar", Target: t("moep.bar")},
+ result: F.Feeds{
+ "muh": &F.Feed{Name: "muh", Target: t("moep.foo")},
+ "bar": &F.Feed{Name: "bar", Target: t("moep.bar")},
},
},
{name: "Empty Group", wantErr: false, target: "",
feeds: []configGroupFeed{
- {Target: nil, Group: Group{Group: "G1"}},
+ {Target: nil, Group: group{Group: "G1"}},
},
- result: Feeds{},
+ result: F.Feeds{},
},
{name: "Simple Group", wantErr: false, target: "",
feeds: []configGroupFeed{
- {Target: nil, Group: Group{Group: "G1", Feeds: []configGroupFeed{
- {Target: s("bar"), Feed: Feed{Name: "F1"}},
- {Target: s(""), Feed: Feed{Name: "F2"}},
- {Target: nil, Feed: Feed{Name: "F3"}},
+ {Target: nil, Group: group{Group: "G1", Feeds: []configGroupFeed{
+ {Target: s("bar"), Feed: feed{Name: "F1"}},
+ {Target: s(""), Feed: feed{Name: "F2"}},
+ {Target: nil, Feed: feed{Name: "F3"}},
}}},
},
- result: Feeds{
- "F1": &Feed{Name: "F1", Target: t("G1.bar")},
- "F2": &Feed{Name: "F2", Target: t("G1")},
- "F3": &Feed{Name: "F3", Target: t("G1.F3")},
+ result: F.Feeds{
+ "F1": &F.Feed{Name: "F1", Target: t("G1.bar")},
+ "F2": &F.Feed{Name: "F2", Target: t("G1")},
+ "F3": &F.Feed{Name: "F3", Target: t("G1.F3")},
},
},
{name: "Nested Groups", wantErr: false, target: "",
feeds: []configGroupFeed{
- {Target: nil, Group: Group{Group: "G1", Feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{Name: "F0"}},
- {Target: s("bar"), Group: Group{Group: "G2",
- Feeds: []configGroupFeed{{Target: nil, Feed: Feed{Name: "F1"}}}}},
- {Target: s(""), Group: Group{Group: "G3",
- Feeds: []configGroupFeed{{Target: s("baz"), Feed: Feed{Name: "F2"}}}}},
- {Target: nil, Group: Group{Group: "G4",
- Feeds: []configGroupFeed{{Target: nil, Feed: Feed{Name: "F3"}}}}},
+ {Target: nil, Group: group{Group: "G1", Feeds: []configGroupFeed{
+ {Target: nil, Feed: feed{Name: "F0"}},
+ {Target: s("bar"), Group: group{Group: "G2",
+ Feeds: []configGroupFeed{{Target: nil, Feed: feed{Name: "F1"}}}}},
+ {Target: s(""), Group: group{Group: "G3",
+ Feeds: []configGroupFeed{{Target: s("baz"), Feed: feed{Name: "F2"}}}}},
+ {Target: nil, Group: group{Group: "G4",
+ Feeds: []configGroupFeed{{Target: nil, Feed: feed{Name: "F3"}}}}},
}}},
},
- result: Feeds{
- "F0": &Feed{Name: "F0", Target: t("G1.F0")},
- "F1": &Feed{Name: "F1", Target: t("G1.bar.F1")},
- "F2": &Feed{Name: "F2", Target: t("G1.baz")},
- "F3": &Feed{Name: "F3", Target: t("G1.G4.F3")},
+ result: F.Feeds{
+ "F0": &F.Feed{Name: "F0", Target: t("G1.F0")},
+ "F1": &F.Feed{Name: "F1", Target: t("G1.bar.F1")},
+ "F2": &F.Feed{Name: "F2", Target: t("G1.baz")},
+ "F3": &F.Feed{Name: "F3", Target: t("G1.G4.F3")},
},
},
}
for _, tt := range tests {
tst.Run(tt.name, func(tst *testing.T) {
- var feeds Feeds = Feeds{}
+ var feeds F.Feeds = F.Feeds{}
err := buildFeeds(tt.feeds, t(tt.target), feeds)
if (err != nil) != tt.wantErr {
tst.Errorf("buildFeeds() error = %v, wantErr %v", err, tt.wantErr)
@@ -133,13 +136,13 @@ func TestParse(tst *testing.T) {
inp string
wantErr bool
feeds []configGroupFeed
- globalConfig Map
+ globalConfig C.Map
}{
{name: "Empty",
inp: "", wantErr: false, feeds: nil, globalConfig: nil},
{name: "Trash", inp: "Something", wantErr: true},
{name: "Simple config",
- inp: "something: 1\nsomething_else: 2", wantErr: false, feeds: nil, globalConfig: Map{"something": 1, "something_else": 2}},
+ inp: "something: 1\nsomething_else: 2", wantErr: false, feeds: nil, globalConfig: C.Map{"something": 1, "something_else": 2}},
{name: "Config with feed",
inp: `
something: 1
@@ -151,14 +154,15 @@ feeds:
unknown-option: foo
`,
wantErr: false,
- globalConfig: Map{"something": 1},
+ globalConfig: C.Map{"something": 1},
feeds: []configGroupFeed{
- {Target: s("bar"), Feed: Feed{
- Name: "Foo",
- Target: nil,
- Url: "whatever",
- MinFreq: 0,
- InclImages: b(true),
+ {Target: s("bar"), Feed: feed{
+ Name: "Foo",
+ Url: "whatever",
+ Options: C.Options{
+ MinFreq: 0,
+ InclImages: b(true),
+ },
}}}},
{name: "Feeds",
@@ -174,17 +178,21 @@ feeds:
`,
wantErr: false,
feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{
- Name: "Foo",
- Url: "whatever",
- MinFreq: 2,
- InclImages: nil,
+ {Target: nil, Feed: feed{
+ Name: "Foo",
+ Url: "whatever",
+ Options: C.Options{
+ MinFreq: 2,
+ InclImages: nil,
+ },
}},
- {Target: s("bla"), Feed: Feed{
- Name: "Shrubbery",
- Url: "google.de",
- MinFreq: 0,
- InclImages: b(false),
+ {Target: s("bla"), Feed: feed{
+ Name: "Shrubbery",
+ Url: "google.de",
+ Options: C.Options{
+ MinFreq: 0,
+ InclImages: b(false),
+ },
}},
},
},
@@ -195,7 +203,7 @@ feeds:
target: bla
`,
wantErr: false,
- feeds: []configGroupFeed{{Target: s("bla"), Group: Group{"Foo", nil}}},
+ feeds: []configGroupFeed{{Target: s("bla"), Group: group{"Foo", nil}}},
},
{name: "Feeds and Groups",
inp: `
@@ -215,21 +223,21 @@ feeds:
`,
wantErr: false,
feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{
+ {Target: nil, Feed: feed{
Name: "Foo",
Url: "whatever",
}},
- {Target: s("target"), Group: Group{
+ {Target: s("target"), Group: group{
Group: "G1",
Feeds: []configGroupFeed{
- {Target: s(""), Group: Group{
+ {Target: s(""), Group: group{
Group: "G2",
Feeds: []configGroupFeed{
- {Target: nil, Feed: Feed{Name: "F1", Url: "google.de"}},
+ {Target: nil, Feed: feed{Name: "F1", Url: "google.de"}},
}},
},
- {Target: nil, Feed: Feed{Name: "F2"}},
- {Target: nil, Group: Group{Group: "G3"}},
+ {Target: nil, Feed: feed{Name: "F2"}},
+ {Target: nil, Group: group{Group: "G3"}},
}},
},
},