-
Notifications
You must be signed in to change notification settings - Fork 3
/
config_test.go
42 lines (37 loc) · 1.22 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/mpapi/failmail/configure"
"io/ioutil"
"os"
"testing"
)
func TestConfigStoreDisk(t *testing.T) {
tmp, err := ioutil.TempDir("", "maildir")
if err != nil {
t.Fatalf("unable to create a test directory: %v", err)
}
defer os.RemoveAll(tmp)
config := Defaults()
configure.ParseArgs(config, "test", []string{"test", "--message-store", tmp})
if store, err := config.Store(); err != nil {
t.Errorf("unexpected error getting configured store: %v", err)
} else if _, ok := store.(*DiskStore); !ok {
t.Errorf("expected a disk-backed store, got %#v", store)
}
}
func TestConfigStoreMemory(t *testing.T) {
config := Defaults()
configure.ParseArgs(config, "test", []string{"test", "--memory-store"})
if store, err := config.Store(); err != nil {
t.Errorf("unexpected error getting configured store: %v", err)
} else if _, ok := store.(*MemoryStore); !ok {
t.Errorf("expected a memory-backed store, got %#v", store)
}
}
func TestConfigStoreErrorNoDiskOrMemory(t *testing.T) {
config := Defaults()
configure.ParseArgs(config, "test", []string{"test", "--message-store", ""})
if _, err := config.Store(); err == nil {
t.Errorf("expected an error asking for neither memory nor disk stores")
}
}