-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspinner_test.go
57 lines (47 loc) · 1.22 KB
/
spinner_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 log
import (
"context"
"errors"
"sync"
"testing"
"time"
)
func TestFrame(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
wg.Add(1)
go frame(ctx, &wg, "waiting on foo", runner)
time.Sleep(2 * time.Second)
cancel()
wg.Wait()
}
func TestWaitSpinner(t *testing.T) {
t.Run("success", func(t *testing.T) {
wg, cancel := WaitSpinner(context.Background(), "waiting on foo", runner)
defer wg.Wait()
time.Sleep(1 * time.Second)
cancel(nil)
})
t.Run("failure", func(t *testing.T) {
wg, cancel := WaitSpinner(context.Background(), "waiting on foo", runner)
defer wg.Wait()
time.Sleep(1 * time.Second)
cancel(errors.New("tired of waiting"))
})
}
func TestShowExample(t *testing.T) {
ctx := context.Background()
wg, cancel := WaitSpinner(ctx, "reticulating splines", runner)
defer wg.Wait()
time.Sleep(2 * time.Second)
cancel(nil)
wg, cancel = WaitSpinner(ctx, "fleebing florbs", runner)
defer wg.Wait()
time.Sleep(2 * time.Second)
cancel(nil)
wg, cancel = WaitSpinner(ctx, "dismantling capitalism", runner)
defer wg.Wait()
time.Sleep(4 * time.Second)
cancel(errors.New("too entrenched, build communicty and try again"))
time.Sleep(2 * time.Second)
}