This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontroller_test.go
128 lines (118 loc) · 2.89 KB
/
controller_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package tomato
import (
"bytes"
"log"
"strings"
"testing"
"time"
"github.com/smartystreets/assertions/should"
"github.com/smartystreets/gunit"
)
func TestControllerFixture(t *testing.T) {
gunit.RunSequential(new(ControllerFixture), t)
}
type ControllerFixture struct {
*gunit.Fixture
controller *Controller
output *bytes.Buffer
}
func (this *ControllerFixture) Setup() {
this.output = new(bytes.Buffer)
log.SetFlags(0)
log.SetOutput(this.output)
}
func (this *ControllerFixture) initializeController(sessions int) {
consoleInput := strings.NewReader(strings.Repeat("\n", sessions))
this.controller = NewController(consoleInput, new(NopSystem), sessions, time.Nanosecond)
}
func (this *ControllerFixture) TestSessionInteractionsAndOutput() {
this.initializeController(8)
this.controller.Run()
this.So(this.output.String(), should.Equal, expectedTomatoSession)
}
type NopSystem struct{}
func (NopSystem) Notify(message string) { log.Println("[Notify]", message) }
func (NopSystem) FocusApp(name string) { log.Println("[FocusApp]", name) }
func (NopSystem) LockScreen() { log.Println("[LockScreen]") }
func (NopSystem) Sleep(duration time.Duration) { log.Println("[Sleep]", duration) }
const expectedTomatoSession = `--- Tomato #1: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #2: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #3: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #4: 25ns ---
[Sleep] 24ns
1ns remaining until 15ns break...
[Notify] 1ns remaining until 15ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 15ns
[LockScreen]
[Sleep] 15ns
Press <ENTER> to continue...
--- Tomato #5: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #6: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #7: 25ns ---
[Sleep] 24ns
1ns remaining until 5ns break...
[Notify] 1ns remaining until 5ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 5ns
[LockScreen]
[Sleep] 5ns
Press <ENTER> to continue...
--- Tomato #8: 25ns ---
[Sleep] 24ns
1ns remaining until 15ns break...
[Notify] 1ns remaining until 15ns break...
[Sleep] 1ns
[FocusApp] Terminal
Break: 15ns
[LockScreen]
[Sleep] 15ns
Press <ENTER> to continue...
`