From 533681e0f83ec4f69b3b8e9f1982ed9f089285b4 Mon Sep 17 00:00:00 2001 From: Clemens Fries Date: Tue, 1 Nov 2016 17:11:58 +0100 Subject: Initial commit --- common/message_test.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 common/message_test.go (limited to 'common/message_test.go') diff --git a/common/message_test.go b/common/message_test.go new file mode 100644 index 0000000..74ed09f --- /dev/null +++ b/common/message_test.go @@ -0,0 +1,82 @@ +/* message_test.go: unit tests for the message module + * + * Copyright (C) 2016 Clemens Fries + * + * 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 . + */ +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) + } + } +} -- cgit