papero/config/helper_test.go

55 lines
1.2 KiB
Go

package config
import (
"io/ioutil"
"os"
"testing"
)
const testConfig = `
default_account = "First Account"
mailbox_path = "../base/mailbox"
default_messages = 50
[[account]]
name = "First Account"
mailbox_path = "/opt"
messages = 30
excluded_folders = ["Draft", "Junk"]
[account.connection]
hostname = "mx.example.com"
port = 993
username = "first@example.com"
password_exec = "echo -n 123qweasdzxc"
[[account]]
name = "Other Account"
[account.connection]
hostname = "mail.personal.me"
port = 666
username = "h4x0R@personal.me"
password = "mySup3r5ekre7p4ssw0rd123"
`
func doTestShellScriptRun(t *testing.T, s *ShellScript) {
if res, err := s.Run(); res != "hello world!" || err != nil {
t.Errorf("Unexpected result:\n\tres -> %s (type: %T)\n\terr -> %s", res, res, err)
}
}
func writeToTempFile(t *testing.T, fileName, content string) *os.File {
dir := t.TempDir()
file, err := ioutil.TempFile(dir, fileName)
if err != nil {
t.Fatal(err)
}
if err = ioutil.WriteFile(file.Name(), []byte(content), 0777); err != nil {
t.Fatal(err)
}
err = os.Chmod(file.Name(), 0777)
if err != nil {
t.Fatal(err)
}
file.Close()
return file
}