diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/config.go | 6 | ||||
-rw-r--r-- | pkg/config/yaml.go | 1 | ||||
-rw-r--r-- | pkg/config/yaml_test.go | 18 | ||||
-rw-r--r-- | pkg/version/version.go | 2 |
4 files changed, 22 insertions, 5 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index 31012a1..bfaefdf 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -104,7 +104,7 @@ func (opt GlobalOptions) WithPartHtml() bool { return util.StrContains(opt.Parts, "html") } -// Load configuration from file +// Load configuration from file and validate it func Load(path string) (*Config, error) { log.Printf("Reading configuration file '%s'", path) @@ -118,6 +118,10 @@ func Load(path string) (*Config, error) { return nil, fmt.Errorf("while parsing: %w", err) } + if err = cfg.Validate(); err != nil { + return nil, fmt.Errorf("Configuration invalid: %w", err) + } + return cfg, nil } diff --git a/pkg/config/yaml.go b/pkg/config/yaml.go index 9dd74a9..c82a57e 100644 --- a/pkg/config/yaml.go +++ b/pkg/config/yaml.go @@ -133,6 +133,7 @@ func (cfg *Config) parse(in io.Reader) error { } func appTarget(target []string, app string) []string { + app = strings.TrimSpace(app) switch { case len(target) == 0 && app == "": return []string{} diff --git a/pkg/config/yaml_test.go b/pkg/config/yaml_test.go index 09f721d..b4d5c9c 100644 --- a/pkg/config/yaml_test.go +++ b/pkg/config/yaml_test.go @@ -45,7 +45,7 @@ func TestBuildOptions(tst *testing.T) { tst.Run(tt.name, func(tst *testing.T) { out, unk := buildOptions(&tt.opts, tt.inp) - if diff := cmp.Diff(out, tt.out); diff != "" { + if diff := cmp.Diff(tt.out, out); diff != "" { tst.Error(diff) } @@ -94,6 +94,12 @@ func TestBuildFeeds(tst *testing.T) { }, result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}}, }, + {name: "Simple With Target and Whitespace", wantErr: false, target: "moep", + feeds: []configGroupFeed{ + {Target: n("\r\nfoo "), Feed: feed{Name: "muh"}}, + }, + result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}}, + }, {name: "Simple With Target and NoAutoTarget", wantErr: false, target: "moep", noAutoTarget: true, feeds: []configGroupFeed{ {Target: n("foo"), Feed: feed{Name: "muh"}}, @@ -124,6 +130,12 @@ func TestBuildFeeds(tst *testing.T) { }, result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}}, }, + {name: "Simple With Blank Target", wantErr: false, target: "moep", + feeds: []configGroupFeed{ + {Target: n(" "), Feed: feed{Name: "muh"}}, + }, + result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}}, + }, {name: "Multiple Feeds", wantErr: false, target: "moep", feeds: []configGroupFeed{ {Target: n("foo"), Feed: feed{Name: "muh"}}, @@ -197,7 +209,7 @@ func TestBuildFeeds(tst *testing.T) { tst.Errorf("buildFeeds() error = %v, wantErr %v", err, tt.wantErr) return } - if diff := cmp.Diff(feeds, tt.result); !tt.wantErr && diff != "" { + if diff := cmp.Diff(tt.result, feeds); !tt.wantErr && diff != "" { tst.Error(diff) } }) @@ -373,7 +385,7 @@ feeds: } if err == nil { - if diff := cmp.Diff(got, tt.config, eqNode); diff != "" { + if diff := cmp.Diff(tt.config, got, eqNode); diff != "" { tst.Error(diff) } } diff --git a/pkg/version/version.go b/pkg/version/version.go index 5fdad9c..e8b970b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -2,7 +2,7 @@ package version // this is set by the linker during build var ( - version = "0.5.2-post" + version = "0.6.0-post" commit = "" ) |