Skip to content

Commit 1a74970

Browse files
committed
Added stopper module tests.
1 parent 437d063 commit 1a74970

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package stopper
2+
3+
import (
4+
"context"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
func TestStopperCallsStop(t *testing.T) {
10+
stopWasCalled := false
11+
12+
var stopFunc context.CancelFunc = func() {
13+
stopWasCalled = true
14+
}
15+
16+
ctx, cancel := context.WithCancel(context.Background())
17+
defer cancel()
18+
19+
stopperModule := NewModule(stopFunc)
20+
stopperModule.Start(ctx)
21+
22+
stopperInput, err := stopperModule.Input(InputName)
23+
assert.NoError(t, err)
24+
25+
// Act: send stop signal to stopper
26+
stopperInput.Push(struct{}{})
27+
28+
err = stopperModule.Close()
29+
assert.NoError(t, err)
30+
31+
assert.True(t, stopWasCalled, "stop was never called")
32+
}

0 commit comments

Comments
 (0)