123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package config
- import (
- "fmt"
- "testing"
- "github.com/google/go-cmp/cmp"
- )
- func TestShellScriptRunInlineScript(t *testing.T) {
- s := ShellScript{Executable: "echo -n hello world!"}
- doTestShellScriptRun(t, &s)
- }
- func TestShellScriptRunExecutable(t *testing.T) {
- file := writeToTempFile(t, "papero.*.sh", "#!/usr/bin/env sh\necho -n hello world!\n")
- s := ShellScript{Executable: file.Name()}
- doTestShellScriptRun(t, &s)
- }
- func TestShellScriptRunExecutableWithArgs(t *testing.T) {
- file := writeToTempFile(t, "papero.*.sh", "#!/usr/bin/env sh\necho -n ${@}\n")
- s := ShellScript{Executable: fmt.Sprintf("%s %s %s", file.Name(), "hello", "world!")}
- doTestShellScriptRun(t, &s)
- }
- func TestParseFile(t *testing.T) {
- expected := &fileConfig{
- Default: "First Account",
- MailboxPath: "../base/mailbox",
- DefaultMessages: initMaybeInt(50),
- Accounts: []account{
- {
- Name: "First Account",
- MailboxPath: "/other/path",
- ExcludedFolders: []string{"Draft", "Junk"},
- Messages: initMaybeInt(30),
- ConnectionInfo: &connectionInfo{
- Host: "mx.example.com",
- Port: 993,
- Username: "first@example.com",
- Password: "",
- PasswordFile: "",
- PasswordExec: &ShellScript{Executable: "echo -n 123qweasdzxc"},
- },
- },
- {
- Name: "Other Account",
- MailboxPath: "",
- ExcludedFolders: []string{},
- Messages: maybeInt{},
- ConnectionInfo: &connectionInfo{
- Host: "mail.personal.me",
- Port: 666,
- Username: "h4x0R@personal.me",
- Password: "mySup3r5ekre7p4ssw0rd123",
- PasswordFile: "",
- PasswordExec: nil,
- },
- },
- },
- }
- file := writeToTempFile(t, "papero.*.toml", testConfig)
- result, err := parseFile(file.Name())
- if err != nil {
- t.Fatal(err)
- }
- opt := cmp.Comparer(func(a, b maybeInt) bool {
- if a.empty() {
- if b.empty() {
- return true
- }
- return false
- }
- return a.value() == b.value()
- })
- if cmp.Equal(result, expected, opt) {
- t.Errorf("Result and expected result differ: %+v\n", cmp.Diff(*result, *expected))
- }
- }
|