88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func TestAllEmailAccounts_Empty(t *testing.T) {
|
|
orig := Cfg
|
|
defer func() { Cfg = orig }()
|
|
Cfg = Config{}
|
|
|
|
accounts := AllEmailAccounts()
|
|
if len(accounts) != 0 {
|
|
t.Errorf("erwartet 0 Accounts, got %d", len(accounts))
|
|
}
|
|
}
|
|
|
|
func TestAllEmailAccounts_LegacyFallback(t *testing.T) {
|
|
orig := Cfg
|
|
defer func() { Cfg = orig }()
|
|
Cfg = Config{}
|
|
Cfg.Email.Host = "imap.example.de"
|
|
Cfg.Email.Port = 143
|
|
Cfg.Email.User = "user@example.de"
|
|
Cfg.Email.Password = "geheim"
|
|
Cfg.Email.Folder = "INBOX"
|
|
Cfg.Email.ProcessedFolder = "Processed"
|
|
Cfg.Email.Model = "testmodel"
|
|
|
|
accounts := AllEmailAccounts()
|
|
if len(accounts) != 1 {
|
|
t.Fatalf("erwartet 1 Account, got %d", len(accounts))
|
|
}
|
|
a := accounts[0]
|
|
if a.Host != "imap.example.de" {
|
|
t.Errorf("Host: got %q", a.Host)
|
|
}
|
|
if a.Port != 143 {
|
|
t.Errorf("Port: got %d", a.Port)
|
|
}
|
|
if a.User != "user@example.de" {
|
|
t.Errorf("User: got %q", a.User)
|
|
}
|
|
if a.ProcessedFolder != "Processed" {
|
|
t.Errorf("ProcessedFolder: got %q", a.ProcessedFolder)
|
|
}
|
|
if a.Model != "testmodel" {
|
|
t.Errorf("Model: got %q", a.Model)
|
|
}
|
|
}
|
|
|
|
func TestAllEmailAccounts_MultipleAccounts(t *testing.T) {
|
|
orig := Cfg
|
|
defer func() { Cfg = orig }()
|
|
Cfg = Config{}
|
|
Cfg.EmailAccounts = []EmailAccount{
|
|
{Name: "Privat", Host: "imap1.de", Port: 143},
|
|
{Name: "Arbeit", Host: "imap2.de", Port: 993, TLS: true},
|
|
}
|
|
|
|
accounts := AllEmailAccounts()
|
|
if len(accounts) != 2 {
|
|
t.Fatalf("erwartet 2 Accounts, got %d", len(accounts))
|
|
}
|
|
if accounts[0].Host != "imap1.de" {
|
|
t.Errorf("Account 0 Host: got %q", accounts[0].Host)
|
|
}
|
|
if accounts[1].Host != "imap2.de" {
|
|
t.Errorf("Account 1 Host: got %q", accounts[1].Host)
|
|
}
|
|
}
|
|
|
|
func TestAllEmailAccounts_NewTakesPrecedence(t *testing.T) {
|
|
orig := Cfg
|
|
defer func() { Cfg = orig }()
|
|
Cfg = Config{}
|
|
Cfg.Email.Host = "legacy.de"
|
|
Cfg.EmailAccounts = []EmailAccount{
|
|
{Name: "Neu", Host: "new.de"},
|
|
}
|
|
|
|
accounts := AllEmailAccounts()
|
|
if len(accounts) != 1 {
|
|
t.Fatalf("erwartet 1 Account, got %d", len(accounts))
|
|
}
|
|
if accounts[0].Host != "new.de" {
|
|
t.Errorf("email_accounts sollte Vorrang haben, got host %q", accounts[0].Host)
|
|
}
|
|
}
|