-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
progress_test.go
110 lines (88 loc) · 1.97 KB
/
progress_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
package zenity_test
import (
"context"
"errors"
"testing"
"time"
"github.com/ncruces/zenity"
"go.uber.org/goleak"
)
func ExampleProgress() {
dlg, err := zenity.Progress(
zenity.Title("Update System Logs"))
if err != nil {
return
}
defer dlg.Close()
dlg.Text("Scanning mail logs...")
dlg.Value(0)
time.Sleep(time.Second)
dlg.Value(25)
time.Sleep(time.Second)
dlg.Text("Updating mail logs...")
dlg.Value(50)
time.Sleep(time.Second)
dlg.Text("Resetting cron jobs...")
dlg.Value(75)
time.Sleep(time.Second)
dlg.Text("Rebooting system...")
dlg.Value(100)
time.Sleep(time.Second)
dlg.Complete()
time.Sleep(time.Second)
}
func ExampleProgress_pulsate() {
dlg, err := zenity.Progress(
zenity.Title("Update System Logs"),
zenity.Pulsate())
if err != nil {
return
}
defer dlg.Close()
dlg.Text("Scanning mail logs...")
time.Sleep(time.Second)
dlg.Text("Updating mail logs...")
time.Sleep(time.Second)
dlg.Text("Resetting cron jobs...")
time.Sleep(time.Second)
dlg.Text("Rebooting system...")
time.Sleep(time.Second)
dlg.Complete()
time.Sleep(time.Second)
}
func TestProgress_cancel(t *testing.T) {
defer goleak.VerifyNone(t)
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := zenity.Progress(zenity.Context(ctx))
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
}
func TestProgress_cancelAfter(t *testing.T) {
defer goleak.VerifyNone(t)
ctx, cancel := context.WithCancel(context.Background())
dlg, err := zenity.Progress(zenity.Context(ctx))
if skip, err := skip(err); skip {
t.Skip("skipping:", err)
}
if err != nil {
t.Fatal(err)
}
go cancel()
<-dlg.Done()
err = dlg.Close()
if !errors.Is(err, context.Canceled) {
t.Error("was not canceled:", err)
}
}
func TestProgress_examples(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
ExampleProgress()
ExampleProgress_pulsate()
}