more tests
This commit is contained in:
parent
ad5a864a17
commit
42662efec5
|
@ -248,6 +248,10 @@ func TestNewDateFromString(t *testing.T) {
|
|||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
test.Equals(t, task.Date{}, task.NewDateFromString("test"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestDateDaysBetween(t *testing.T) {
|
||||
|
@ -321,6 +325,11 @@ func TestDateString(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDateIsZero(t *testing.T) {
|
||||
test.Equals(t, true, task.Date{}.IsZero())
|
||||
test.Equals(t, false, task.NewDate(2021, 6, 24).IsZero())
|
||||
}
|
||||
|
||||
func TestDateAfter(t *testing.T) {
|
||||
day := task.NewDate(2021, 1, 31)
|
||||
for _, tc := range []struct {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package task_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.ewintr.nl/go-kit/test"
|
||||
"git.ewintr.nl/gte/internal/task"
|
||||
"git.ewintr.nl/gte/pkg/msend"
|
||||
)
|
||||
|
||||
func TestDispatcherDispatch(t *testing.T) {
|
||||
mem := msend.NewMemory()
|
||||
disp := task.NewDispatcher(mem)
|
||||
tsk := &task.Task{
|
||||
Id: "id",
|
||||
Version: 3,
|
||||
Action: "action",
|
||||
Project: "project",
|
||||
Due: task.NewDate(2021, 6, 24),
|
||||
}
|
||||
|
||||
t.Run("err", func(t *testing.T) {
|
||||
expErr := fmt.Errorf("not good")
|
||||
mem.Err = expErr
|
||||
actErr := disp.Dispatch(tsk)
|
||||
|
||||
test.Equals(t, expErr, actErr)
|
||||
})
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
mem.Err = nil
|
||||
|
||||
test.OK(t, disp.Dispatch(tsk))
|
||||
test.Equals(t, 1, len(mem.Messages))
|
||||
|
||||
actMsg := mem.Messages[0]
|
||||
test.Equals(t, tsk.FormatSubject(), actMsg.Subject)
|
||||
test.Equals(t, tsk.FormatBody(), actMsg.Body)
|
||||
})
|
||||
}
|
|
@ -2,6 +2,7 @@ package msend
|
|||
|
||||
type Memory struct {
|
||||
Messages []*Message
|
||||
Err error
|
||||
}
|
||||
|
||||
func NewMemory() *Memory {
|
||||
|
@ -11,6 +12,10 @@ func NewMemory() *Memory {
|
|||
}
|
||||
|
||||
func (mem *Memory) Send(msg *Message) error {
|
||||
if mem.Err != nil {
|
||||
return mem.Err
|
||||
}
|
||||
|
||||
mem.Messages = append(mem.Messages, msg)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package msend_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"git.ewintr.nl/go-kit/test"
|
||||
|
@ -18,4 +19,9 @@ func TestMemorySend(t *testing.T) {
|
|||
msg2 := &msend.Message{Subject: "sub2", Body: "body2"}
|
||||
test.OK(t, mem.Send(msg2))
|
||||
test.Equals(t, []*msend.Message{msg1, msg2}, mem.Messages)
|
||||
|
||||
expErr := fmt.Errorf("oh no")
|
||||
mem.Err = expErr
|
||||
actErr := mem.Send(msg1)
|
||||
test.Equals(t, expErr, actErr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue