diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-17 17:04:06 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-18 18:36:04 +0200 |
commit | 5c29e49f9f422c8889ce2ed6b5b5a2914b55cace (patch) | |
tree | 20b2d8725fa0bc763d32b6f59d796143a453548e /pkg/config/yaml_test.go | |
parent | 44ff3d08a0e1f3b49e07795a9fdb0ad3af4c7540 (diff) | |
download | feed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.tar.gz feed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.tar.bz2 feed2imap-go-5c29e49f9f422c8889ce2ed6b5b5a2914b55cace.zip |
Support feed targets per feed
Diffstat (limited to 'pkg/config/yaml_test.go')
-rw-r--r-- | pkg/config/yaml_test.go | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go index e649175..78a3243 100644 --- a/pkg/config/yaml_test.go +++ b/pkg/config/yaml_test.go @@ -148,6 +148,29 @@ func TestBuildFeeds(tst *testing.T) { "bar": &Feed{Name: "bar", Target: t("moep.bar")}, }, }, + {name: "URL Target", wantErr: false, target: "", + feeds: []configGroupFeed{ + {Target: n("imap://foo.bar:443/INBOX/Feed"), Feed: feed{Name: "muh"}}, + }, + result: Feeds{"muh": &Feed{Name: "muh", Target: t("INBOX.Feed")}}, + }, + {name: "Multiple URL Targets", wantErr: false, target: "", + feeds: []configGroupFeed{ + {Target: n("imap://foo.bar:443/INBOX/Feed"), Feed: feed{Name: "muh"}}, + {Target: n("imap://foo.bar:443/INBOX/Feed2"), Feed: feed{Name: "bar"}}, + }, + result: Feeds{ + "muh": &Feed{Name: "muh", Target: t("INBOX.Feed")}, + "bar": &Feed{Name: "bar", Target: t("INBOX.Feed2")}, + }, + }, + {name: "Mixed URL Targets", wantErr: true, target: "", + feeds: []configGroupFeed{ + {Target: n("imap://foo.bar:443/INBOX/Feed"), Feed: feed{Name: "muh"}}, + {Target: n("imap://other.bar:443/INBOX/Feed"), Feed: feed{Name: "bar"}}, + }, + result: Feeds{}, + }, {name: "Empty Group", wantErr: false, target: "", feeds: []configGroupFeed{ {Group: group{Group: "G1"}}, @@ -206,7 +229,8 @@ func TestBuildFeeds(tst *testing.T) { tst.Run(tt.name, func(tst *testing.T) { var feeds = Feeds{} var opts = Options{} - err := buildFeeds(tt.feeds, t(tt.target), feeds, &opts, !tt.noAutoTarget) + var globalTarget = Url{} + err := buildFeeds(tt.feeds, t(tt.target), feeds, &opts, !tt.noAutoTarget, &globalTarget) if (err != nil) != tt.wantErr { tst.Errorf("buildFeeds() error = %v, wantErr %v", err, tt.wantErr) return @@ -447,3 +471,75 @@ feeds: } } } + +func TestURLFeedWithoutGlobalTarget(tst *testing.T) { + inp := ` +feeds: + - name: Foo + target: imap://foo.bar:443/INBOX/Feed +` + res := Feeds{ + "Foo": &Feed{Name: "Foo", Target: t("INBOX.Feed")}, + } + + c := WithDefault() + c.FeedOptions = Options{} + + if err := c.parse(strings.NewReader(inp)); err != nil { + tst.Error(err) + } else { + if diff := cmp.Diff(res, c.Feeds); diff != "" { + tst.Error(diff) + } + if diff := cmp.Diff("imap://foo.bar:443", c.Target.String()); diff != "" { + tst.Error(diff) + } + } +} + +func TestURLFeedWithGlobalTarget(tst *testing.T) { + inp := ` +target: imaps://foo.bar/INBOX/Feeds +feeds: + - name: Foo + target: imaps://foo.bar:993/Some/Other/Path +` + res := Feeds{ + "Foo": &Feed{Name: "Foo", Target: t("Some.Other.Path")}, + } + + c := WithDefault() + c.FeedOptions = Options{} + + if err := c.parse(strings.NewReader(inp)); err != nil { + tst.Error(err) + } else { + if diff := cmp.Diff(res, c.Feeds); diff != "" { + tst.Error(diff) + } + if diff := cmp.Diff("imaps://foo.bar:993/INBOX/Feeds", c.Target.String()); diff != "" { + tst.Error(diff) + } + } +} + +func TestURLFeedWithDifferentGlobalTarget(tst *testing.T) { + inp := ` +target: imaps://foo.bar/INBOX/Feeds +feeds: + - name: Foo + target: imaps://other.bar/INBOX/Feeds +` + errorText := "while parsing: Line 5: Given URL endpoint 'imaps://other.bar:993' does not match previous endpoint 'imaps://foo.bar:993'." + c := WithDefault() + c.FeedOptions = Options{} + + err := c.parse(strings.NewReader(inp)) + if err == nil { + tst.Error("Expected error.") + } else { + if diff := cmp.Diff(errorText, err.Error()); diff != "" { + tst.Error(diff) + } + } +}
\ No newline at end of file |