-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from rafecolton/fix-server-failure-if-no-basi…
…c-auth-provided Fix bug where server cannot be started w/o basic auth
- Loading branch information
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// +build integration | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/onsi/gocleanup" | ||
) | ||
|
||
func init() { | ||
go func() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGUSR1) | ||
<-c | ||
gocleanup.Exit(166) | ||
}() | ||
} |