papero/config/config_test.go

58 lines
1.4 KiB
Go
Raw Permalink Normal View History

2021-01-09 17:06:13 +01:00
package config
import (
"testing"
2021-04-01 18:09:04 +02:00
"git.sr.ht/~blallo/papero/worker"
2021-01-09 17:06:13 +01:00
"github.com/google/go-cmp/cmp"
)
func TestParseConfig(t *testing.T) {
expected := &MemConfig{
Default: "First Account",
2021-01-09 17:06:13 +01:00
Accounts: map[string]*AccountData{
"First Account": {
2021-01-09 17:06:13 +01:00
Host: "mx.example.com",
Port: 993,
Username: "first@example.com",
Password: "123qweasdzxc",
ExcludedFolders: []string{"Draft", "Junk"},
MailboxPath: "/opt",
Messages: 30,
},
"Other Account": {
2021-01-09 17:06:13 +01:00
Host: "mail.personal.me",
Port: 666,
Username: "h4x0R@personal.me",
Password: "mySup3r5ekre7p4ssw0rd123",
ExcludedFolders: []string{},
MailboxPath: "../base/mailbox/Other Account",
Messages: 50,
},
},
Workers: map[string]*worker.Worker{
"First Account": {},
"Other Account": {},
2021-01-09 17:06:13 +01:00
},
}
file := writeToTempFile(t, "papero.*.toml", testConfig)
fileConfig, err := parseFile(file.Name())
if err != nil {
t.Fatal(err)
}
result, errs := parseConfig(fileConfig)
if !errs.Check() {
t.Fatal(errs)
}
if result.Default != expected.Default {
t.Errorf("Default account does not match. Expected: %s\tResult:\t%s\n", expected.Default, result.Default)
}
2021-01-09 17:06:13 +01:00
if !cmp.Equal(result.Accounts, expected.Accounts) {
t.Errorf("Result and expected result differ: %+v\n", cmp.Diff(result.Accounts, expected.Accounts))
}
}