forked from abiosoft/caddy-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_test.go
73 lines (60 loc) · 1.74 KB
/
service_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
package git
import (
"fmt"
"testing"
"time"
"github.com/abiosoft/caddy-git/gittest"
)
func init() {
SetOS(gittest.FakeOS)
}
func TestServices(t *testing.T) {
repo := &Repo{URL: "[email protected]", Interval: time.Second}
Start(repo)
if len(Services.services) != 1 {
t.Errorf("Expected 1 service, found %v", len(Services.services))
}
Services.Stop(repo.URL, 1)
if len(Services.services) != 0 {
t.Errorf("Expected 1 service, found %v", len(Services.services))
}
repos := make([]*Repo, 5)
for i := 0; i < 5; i++ {
repos[i] = &Repo{URL: fmt.Sprintf("test%v", i), Interval: time.Second * 2}
Start(repos[i])
if len(Services.services) != i+1 {
t.Errorf("Expected %v service(s), found %v", i+1, len(Services.services))
}
}
gos.Sleep(time.Second * 5)
Services.Stop(repos[0].URL, 1)
if len(Services.services) != 4 {
t.Errorf("Expected %v service(s), found %v", 4, len(Services.services))
}
repo = &Repo{URL: "[email protected]", Interval: time.Second}
Start(repo)
if len(Services.services) != 5 {
t.Errorf("Expected %v service(s), found %v", 5, len(Services.services))
}
repo = &Repo{URL: "[email protected]", Interval: time.Second * 2}
Start(repo)
if len(Services.services) != 6 {
t.Errorf("Expected %v service(s), found %v", 6, len(Services.services))
}
gos.Sleep(time.Second * 5)
Services.Stop(repo.URL, -1)
if len(Services.services) != 4 {
t.Errorf("Expected %v service(s), found %v", 4, len(Services.services))
}
for _, repo := range repos {
Services.Stop(repo.URL, -1)
}
if len(Services.services) != 0 {
t.Errorf("Expected %v service(s), found %v", 0, len(Services.services))
}
repo.Interval = 0
Start(repo)
if len(Services.services) != 0 {
t.Errorf("Expected %v service(s), found %v", 0, len(Services.services))
}
}