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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* message_test.go: unit tests for the message module
*
* Copyright (C) 2016 Clemens Fries <github-clockrotz@xenoworld.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package common
import (
"github.com/stretchr/testify/assert"
"path/filepath"
"sort"
"testing"
)
func TestReadMessagesAndVerify(t *testing.T) {
workdir := "testdata"
conf := NewConfiguration()
conf.Set("from", "me@example.com")
messages := NewMessagesFromDirectory(filepath.Join(workdir, "todo"))
for _, message := range messages {
// If we don't to this, it will fail because "from" is missing
message.Conf.MergeWith(conf)
if err := message.Verify(); err != nil {
t.Errorf("Verification of message '%s' failed with %s", message.Name, err)
}
}
}
func TestMessage_Get(t *testing.T) {
message := Message{Conf: *NewConfiguration()}
message.Conf.Set("foo", "bar")
assert.Equal(t, "bar", message.Get("foo"))
}
func TestMessagesSort(t *testing.T) {
messages := []Message{
{
Name: "1",
Conf: Configuration{
Data: map[string]string{
"date": "2000-01-01",
}}},
{
Name: "2",
Conf: Configuration{
Data: map[string]string{
"date": "2010-01-01",
}}},
{
Name: "3",
Conf: Configuration{
Data: map[string]string{
"date": "2005-01-01",
}}},
}
sort.Sort(Messages(messages))
for i, k := range []string{"1", "3", "2"} {
if messages[i].Name != k {
t.Errorf("expected: %s, but was %s", k, messages[i].Name)
}
}
}
|