From ee1d8b157e1f207ab181cf81ee7ab8f7c39fbeab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 2 Jun 2021 23:05:58 +0200 Subject: More tests --- pkg/config/yaml_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go index b4d5c9c..e649175 100644 --- a/pkg/config/yaml_test.go +++ b/pkg/config/yaml_test.go @@ -20,6 +20,8 @@ func n(s string) (n yaml.Node) { return } +var null = yaml.Node{Tag: nullTag} + func TestBuildOptions(tst *testing.T) { tests := []struct { name string @@ -120,7 +122,7 @@ func TestBuildFeeds(tst *testing.T) { }, {name: "Simple With Nil Target", wantErr: false, target: "moep", feeds: []configGroupFeed{ - {Target: yaml.Node{Tag: "!!null"}, Feed: feed{Name: "muh"}}, + {Target: null, Feed: feed{Name: "muh"}}, }, result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}}, }, @@ -345,6 +347,8 @@ feeds: - name: F1 url: google.de - name: F2 + - name: F3 + target: - group: G3 `, wantErr: false, @@ -363,6 +367,7 @@ feeds: }}, }, {Feed: feed{Name: "F2"}}, + {Feed: feed{Name: "F3"}, Target: null}, {Group: group{Group: "G3"}}, }}, }, @@ -392,3 +397,53 @@ feeds: }) } } + +func TestCompleteFeed(tst *testing.T) { + inp := ` +feeds: + - name: Foo + url: whatever + - group: G1 + target: target + feeds: + - group: G2 + target: "" + feeds: + - name: F1 + url: google.de + - name: F2 + - name: F3 + target: + - name: F4 + target: "G4" + - name: F5 + target: ~ + - name: F6 + target: "" + - group: G3 + - group: G4 + feeds: + - name: F7 +` + res := Feeds{ + "Foo": &Feed{Name: "Foo", Target: t("Foo"), Url: "whatever"}, + "F1": &Feed{Name: "F1", Target: t("target.F1"), Url: "google.de"}, + "F2": &Feed{Name: "F2", Target: t("target.F2")}, + "F3": &Feed{Name: "F3", Target: t("target")}, + "F4": &Feed{Name: "F4", Target: t("target.G4")}, + "F5": &Feed{Name: "F5", Target: t("target")}, + "F6": &Feed{Name: "F6", Target: t("target")}, + "F7": &Feed{Name: "F7", Target: t("target.G4.F7")}, + } + + 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) + } + } +} -- cgit v1.2.3