aboutsummaryrefslogtreecommitdiff
path: root/internal/config/yaml_test.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-19 22:00:56 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-19 22:00:56 +0200
commit9b982a82c150c65a5f72c9b548053553b2c3b0fb (patch)
tree81b203c9500e345710ac26dea6eda690b936d6ff /internal/config/yaml_test.go
parentfe3d64998545eb4fbddb26e79eefeb3fa89bbbdd (diff)
downloadfeed2imap-go-9b982a82c150c65a5f72c9b548053553b2c3b0fb.tar.gz
feed2imap-go-9b982a82c150c65a5f72c9b548053553b2c3b0fb.tar.bz2
feed2imap-go-9b982a82c150c65a5f72c9b548053553b2c3b0fb.zip
Store path as array -- the delimiter is not always '.'
Diffstat (limited to 'internal/config/yaml_test.go')
-rw-r--r--internal/config/yaml_test.go55
1 files changed, 31 insertions, 24 deletions
diff --git a/internal/config/yaml_test.go b/internal/config/yaml_test.go
index 94566c6..1e77700 100644
--- a/internal/config/yaml_test.go
+++ b/internal/config/yaml_test.go
@@ -2,13 +2,20 @@ package config
import (
"reflect"
+ "strings"
"testing"
)
func s(s string) *string { return &s }
func b(b bool) *bool { return &b }
+func t(s string) []string {
+ if s == "" {
+ return []string{}
+ }
+ return strings.Split(s, ".")
+}
-func TestBuildFeeds(t *testing.T) {
+func TestBuildFeeds(tst *testing.T) {
tests := []struct {
name string
wantErr bool
@@ -34,25 +41,25 @@ func TestBuildFeeds(t *testing.T) {
feeds: []configGroupFeed{
{Target: s("foo"), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: "foo"}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("foo")}},
},
{name: "Simple With Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: s("foo"), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: "moep.foo"}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.foo")}},
},
{name: "Simple With Nil Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: nil, Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: "moep.muh"}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep.muh")}},
},
{name: "Simple With Empty Target", wantErr: false, target: "moep",
feeds: []configGroupFeed{
{Target: s(""), Feed: Feed{Name: "muh"}},
},
- result: Feeds{"muh": &Feed{Name: "muh", Target: "moep"}},
+ result: Feeds{"muh": &Feed{Name: "muh", Target: t("moep")}},
},
{name: "Multiple Feeds", wantErr: false, target: "moep",
feeds: []configGroupFeed{
@@ -60,8 +67,8 @@ func TestBuildFeeds(t *testing.T) {
{Target: nil, Feed: Feed{Name: "bar"}},
},
result: Feeds{
- "muh": &Feed{Name: "muh", Target: "moep.foo"},
- "bar": &Feed{Name: "bar", Target: "moep.bar"},
+ "muh": &Feed{Name: "muh", Target: t("moep.foo")},
+ "bar": &Feed{Name: "bar", Target: t("moep.bar")},
},
},
{name: "Empty Group", wantErr: false, target: "",
@@ -79,9 +86,9 @@ func TestBuildFeeds(t *testing.T) {
}}},
},
result: Feeds{
- "F1": &Feed{Name: "F1", Target: "G1.bar"},
- "F2": &Feed{Name: "F2", Target: "G1"},
- "F3": &Feed{Name: "F3", Target: "G1.F3"},
+ "F1": &Feed{Name: "F1", Target: t("G1.bar")},
+ "F2": &Feed{Name: "F2", Target: t("G1")},
+ "F3": &Feed{Name: "F3", Target: t("G1.F3")},
},
},
{name: "Nested Groups", wantErr: false, target: "",
@@ -97,30 +104,30 @@ func TestBuildFeeds(t *testing.T) {
}}},
},
result: Feeds{
- "F0": &Feed{Name: "F0", Target: "G1.F0"},
- "F1": &Feed{Name: "F1", Target: "G1.bar.F1"},
- "F2": &Feed{Name: "F2", Target: "G1.baz"},
- "F3": &Feed{Name: "F3", Target: "G1.G4.F3"},
+ "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")},
},
},
}
for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
+ tst.Run(tt.name, func(tst *testing.T) {
var feeds Feeds = Feeds{}
- err := buildFeeds(tt.feeds, tt.target, feeds)
+ err := buildFeeds(tt.feeds, t(tt.target), feeds)
if (err != nil) != tt.wantErr {
- t.Errorf("buildFeeds() error = %v, wantErr %v", err, tt.wantErr)
+ tst.Errorf("buildFeeds() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !tt.wantErr && !reflect.DeepEqual(feeds, tt.result) {
- t.Errorf("buildFeeds() got = %v, want %v", feeds, tt.result)
+ tst.Errorf("buildFeeds() got = %v, want %v", feeds, tt.result)
}
})
}
}
//noinspection GoNilness,GoNilness
-func TestParse(t *testing.T) {
+func TestParse(tst *testing.T) {
tests := []struct {
name string
inp string
@@ -148,7 +155,7 @@ feeds:
feeds: []configGroupFeed{
{Target: s("bar"), Feed: Feed{
Name: "Foo",
- Target: "",
+ Target: nil,
Url: "whatever",
MinFreq: 0,
InclImages: b(true),
@@ -230,18 +237,18 @@ feeds:
}
for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
+ tst.Run(tt.name, func(tst *testing.T) {
var buf = []byte(tt.inp)
got, err := parse(buf)
if (err != nil) != tt.wantErr {
- t.Errorf("parse() error = %v, wantErr %v", err, tt.wantErr)
+ tst.Errorf("parse() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got.Feeds, tt.feeds) {
- t.Errorf("parse() got = %v, want %v", got.Feeds, tt.feeds)
+ tst.Errorf("parse() got = %v, want %v", got.Feeds, tt.feeds)
}
if !reflect.DeepEqual(got.GlobalConfig, tt.globalConfig) {
- t.Errorf("parse() got = %v, want %v", got.GlobalConfig, tt.globalConfig)
+ tst.Errorf("parse() got = %v, want %v", got.GlobalConfig, tt.globalConfig)
}
})
}
ver-highlight'> 2021-02-16Fix CRLF endingRené 'Necoro' Neumann1-57/+57 2021-02-16Increment go-version to 1.16René 'Necoro' Neumann3-5/+5 2021-02-16Use go-embed for templates instead of inline strings.René 'Necoro' Neumann6-74/+79 They should also use CRLF (cf issue #46). 2021-02-16Issue #46: Fix semantics of `n` resultRené 'Necoro' Neumann2-9/+15 Per contract, the returned number of bytes written should be the number of bytes _from the input_. Therefore, the added bytes (`\r` or `\n`) shall not count into that number. 2021-02-16Issue #46: Move and rename writer; add commentsRené 'Necoro' Neumann3-12/+21 2021-02-15Issue #46: Improvements; add testsRené 'Necoro' Neumann2-1/+48 2021-02-15Bump github.com/google/uuid from 1.1.4 to 1.2.0dependabot[bot]2-3/+3 Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.1.4 to 1.2.0. - [Release notes](https://github.com/google/uuid/releases) - [Commits](https://github.com/google/uuid/compare/v1.1.4...v1.2.0) Signed-off-by: dependabot[bot] <support@github.com> 2021-02-15Issue #46: Make the resulting email body not to include single \r or \n. ↵René 'Necoro' Neumann2-2/+66 This now pleases Cyrus IMAP. 2021-01-20Bump github.com/PuerkitoBio/goquery from 1.6.0 to 1.6.1dependabot[bot]2-3/+3 Bumps [github.com/PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery) from 1.6.0 to 1.6.1. - [Release notes](https://github.com/PuerkitoBio/goquery/releases) - [Commits](https://github.com/PuerkitoBio/goquery/compare/v1.6.0...v1.6.1) Signed-off-by: dependabot[bot] <support@github.com> 2021-01-09Bump github.com/google/uuid from 1.1.2 to 1.1.4dependabot[bot]2-3/+3 Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.1.2 to 1.1.4. - [Release notes](https://github.com/google/uuid/releases) - [Commits](https://github.com/google/uuid/compare/v1.1.2...v1.1.4) Signed-off-by: dependabot[bot] <support@github.com> 2021-01-09Bump github.com/emersion/go-message from 0.14.0 to 0.14.1 (#42)dependabot[bot]2-3/+3 Bumps [github.com/emersion/go-message](https://github.com/emersion/go-message) from 0.14.0 to 0.14.1. - [Release notes](https://github.com/emersion/go-message/releases) - [Commits](https://github.com/emersion/go-message/compare/v0.14.0...v0.14.1) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 2020-11-28Bump github.com/emersion/go-message from 0.13.0 to 0.14.0 (#38)dependabot[bot]2-3/+9 Bumps [github.com/emersion/go-message](https://github.com/emersion/go-message) from 0.13.0 to 0.14.0. - [Release notes](https://github.com/emersion/go-message/releases) - [Commits](https://github.com/emersion/go-message/compare/v0.13.0...v0.14.0) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 2020-11-28Bump github.com/google/go-cmp from 0.5.2 to 0.5.4 (#37)dependabot[bot]2-3/+3 Bumps [github.com/google/go-cmp](https://github.com/google/go-cmp) from 0.5.2 to 0.5.4. - [Release notes](https://github.com/google/go-cmp/releases) - [Commits](https://github.com/google/go-cmp/compare/v0.5.2...v0.5.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 2020-11-23Fix release.ymlv0.5.2René 'Necoro' Neumann1-3/+10 2020-11-23Prepare v0.5.2René 'Necoro' Neumann3-3/+8 2020-11-20Bump github.com/gabriel-vasile/mimetype from 1.1.1 to 1.1.2dependabot[bot]2-3/+3 Bumps [github.com/gabriel-vasile/mimetype](https://github.com/gabriel-vasile/mimetype) from 1.1.1 to 1.1.2. - [Release notes](https://github.com/gabriel-vasile/mimetype/releases) - [Changelog](https://github.com/gabriel-vasile/mimetype/blob/master/CHANGELOG.md) - [Commits](https://github.com/gabriel-vasile/mimetype/compare/v1.1.1...v1.1.2) Signed-off-by: dependabot[bot] <support@github.com> 2020-11-04Clean dependabot.ymlRené 'Necoro' Neumann1-4/+0