0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/middleware/git/service_test.go

61 lines
1.4 KiB
Go
Raw Normal View History

2015-05-25 22:44:47 -05:00
package git
import (
"fmt"
"testing"
"time"
"github.com/mholt/caddy/middleware/git/gittest"
)
func init() {
SetOS(gittest.FakeOS)
}
func Test(t *testing.T) {
repo := &Repo{URL: "git@github.com", Interval: time.Second}
Start(repo)
if len(Services.services) != 1 {
t.Errorf("Expected 1 service, found %v", len(Services.services))
2015-05-25 22:44:47 -05:00
}
Services.Stop(repo.URL, 1)
if len(Services.services) != 0 {
t.Errorf("Expected 1 service, found %v", len(Services.services))
2015-05-25 22:44:47 -05:00
}
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))
2015-05-25 22:44:47 -05:00
}
}
2015-05-28 02:21:10 -05:00
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))
2015-05-25 22:44:47 -05:00
}
repo = &Repo{URL: "git@github.com", Interval: time.Second}
Start(repo)
if len(Services.services) != 5 {
t.Errorf("Expected %v service(s), found %v", 5, len(Services.services))
2015-05-25 22:44:47 -05:00
}
repo = &Repo{URL: "git@github.com", Interval: time.Second * 2}
Start(repo)
if len(Services.services) != 6 {
t.Errorf("Expected %v service(s), found %v", 6, len(Services.services))
2015-05-25 22:44:47 -05:00
}
2015-05-28 02:21:10 -05:00
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))
2015-05-25 22:44:47 -05:00
}
}