-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
57 lines (51 loc) · 1.11 KB
/
main_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"testing"
"time"
"github.com/TilliboyF/tuido/common"
"github.com/TilliboyF/tuido/handler"
"github.com/TilliboyF/tuido/types"
"github.com/stretchr/testify/assert"
)
func TestMain(t *testing.T) {
handler, err := handler.NewTodoHandler(true)
assert.NoError(t, err)
rootCmd := NewRootCmd(handler)
tests := []struct {
name string
command func() []string
expected func() string
}{
{
name: "Version print",
command: func() []string {
return []string{"version"}
},
expected: func() string {
return fmt.Sprintf("tuido app version %s\n", version)
},
},
{
name: "Add Todo",
command: func() []string {
return []string{"add", "Task 1"}
},
expected: func() string {
return common.TableStringFromTodo(types.Todo{
Name: "Task 1",
ID: 1,
Status: types.TODO,
CreatedAt: time.Now(),
})
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
out, err := common.ExecuteCommand(rootCmd, test.command()...)
assert.NoError(t, err)
assert.Equal(t, test.expected(), out)
})
}
}