-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskin_test.go
81 lines (66 loc) · 1.55 KB
/
taskin_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package taskin
import (
"github.com/charmbracelet/bubbles/spinner"
"testing"
)
func TestNewRunner(t *testing.T) {
task := Task{
Title: "Test Task",
Task: func(t *Task) error { return nil },
}
cfg := Config{
Spinner: spinner.Dot,
}
runner := NewRunner(task, cfg)
if runner.State != NotStarted {
t.Errorf("Expected runner state to be 'NotStarted', got '%d'", runner.State)
}
if runner.Task.Title != "Test Task" {
t.Errorf("Expected task title to be 'Test Task', got '%s'", runner.Task.Title)
}
}
func TestRunnersRun(t *testing.T) {
tasks := Tasks{
Task{
Title: "Test Task",
Task: func(t *Task) error { return nil },
},
}
cfg := Config{
Spinner: spinner.Dot,
}
runners := New(tasks, cfg)
err := runners.Run()
if err != nil {
t.Errorf("Expected Run to return nil, got '%s'", err.Error())
}
}
func TestNew(t *testing.T) {
tasks := Tasks{
Task{
Title: "Test Task",
Task: func(t *Task) error { return nil },
},
}
cfg := Config{
Spinner: spinner.Dot,
}
runners := New(tasks, cfg)
if len(runners) != 1 {
t.Errorf("Expected New to return 1 runner, got '%d'", len(runners))
}
}
func TestTaskProgress(t *testing.T) {
task := Task{
Title: "Test Task",
Task: func(t *Task) error { return nil },
}
cfg := Config{
Spinner: spinner.Dot,
}
runner := NewRunner(task, cfg)
runner.Task.Progress(1, 10)
if runner.Task.ShowProgress.Current != 1 || runner.Task.ShowProgress.Total != 10 {
t.Errorf("Expected TaskProgress to be 1/10, got %d/%d", runner.Task.ShowProgress.Current, runner.Task.ShowProgress.Total)
}
}