-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
integration_test.go
71 lines (64 loc) · 1.77 KB
/
integration_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
package main_test
import (
"os"
"os/exec"
"syscall"
"testing"
"time"
)
func TestServer(t *testing.T) {
cmd := exec.Cmd{
Path: os.Getenv("GOPATH") + "/bin/docker-builder",
Args: []string{"docker-builder", "serve"},
}
if err := cmd.Start(); err != nil {
t.Errorf("error start server: %s\n", err.Error())
}
go func() {
time.Sleep(100 * time.Millisecond)
syscall.Kill(cmd.Process.Pid, syscall.SIGUSR1)
time.Sleep(100 * time.Millisecond)
syscall.Kill(cmd.Process.Pid, syscall.SIGTERM)
}()
if err := cmd.Wait(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
if status.ExitStatus() != 166 {
t.Errorf("server exited unexpectedly and/or did not start correctly")
}
} else {
t.Errorf("unable to get process exit code")
}
} else {
t.Errorf("error waiting on server: %s\n", err.Error())
}
}
}
func TestServerWithBasicAuth(t *testing.T) {
cmd := exec.Cmd{
Path: os.Getenv("GOPATH") + "/bin/docker-builder",
Args: []string{"docker-builder", "serve", "--username", "foo", "--password", "bar"},
}
if err := cmd.Start(); err != nil {
t.Errorf("error start server: %s\n", err.Error())
}
go func() {
time.Sleep(100 * time.Millisecond)
syscall.Kill(cmd.Process.Pid, syscall.SIGUSR1)
time.Sleep(100 * time.Millisecond)
syscall.Kill(cmd.Process.Pid, syscall.SIGTERM)
}()
if err := cmd.Wait(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
if status.ExitStatus() != 166 {
t.Errorf("server exited unexpectedly and/or did not start correctly")
}
} else {
t.Errorf("unable to get process exit code")
}
} else {
t.Errorf("error waiting on server: %s\n", err.Error())
}
}
}