papero/config/config_test.go
2021-01-09 17:06:13 +01:00

52 lines
1.3 KiB
Go

package config
import (
"testing"
"git.lattuga.net/blallo/papero/worker"
"github.com/google/go-cmp/cmp"
)
func TestParseConfig(t *testing.T) {
expected := &MemConfig{
Accounts: map[string]*AccountData{
"First Account": &AccountData{
Host: "mx.example.com",
Port: 993,
Username: "first@example.com",
Password: "123qweasdzxc",
ExcludedFolders: []string{"Draft", "Junk"},
MailboxPath: "/opt",
Messages: 30,
},
"Other Account": &AccountData{
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": &worker.Worker{},
"Other Account": &worker.Worker{},
},
}
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 !cmp.Equal(result.Accounts, expected.Accounts) {
t.Errorf("Result and expected result differ: %+v\n", cmp.Diff(result.Accounts, expected.Accounts))
}
}