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