func TestCWDBuildsAdvance(t *testing.T) {
	examplePath, err := filepath.Abs(filepath.Join("..", "example"))
	if err != nil {
		t.Fatalf("Unable to determine example path: %v", err)
	}
	cmd := exec.Command("hanoverd", "--publish", testPort+":8000")
	cmd.Dir = examplePath
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Start()
	if err != nil {
		t.Fatalf("hanoverd failed to start, is it installed?: %v", err)
	}
	const timeout = 30 * time.Second
	deadline := time.Now().Add(timeout)
	current := ""
	wanted := "Hello from hanoverd-0\r\n"
	next := map[string]string{
		"Hello from hanoverd-0\r\n": "Hello from hanoverd-1\r\n",
		"Hello from hanoverd-1\r\n": "Hello from hanoverd-2\r\n",
		"Hello from hanoverd-2\r\n": "",
	}
	finished := make(chan struct{})
	defer close(finished)
	go func() {
		select {
		case <-time.After(timeout):
			cmd.Process.Signal(syscall.SIGQUIT)
		case <-finished:
		}
	}()
loop:
	for {
		if time.Now().After(deadline) {
			t.Errorf("Took longer than deadline to get a valid response")
			break
		}
		response := simpleGetHTTP("http://localhost:" + testPort)
		switch response {
		default:
			t.Logf("Unexpected response, current = %q wanted = %q, got = %q",
				current, wanted, response)
		case current:
		case wanted:
			deadline = time.Now().Add(timeout)
			current = response
			wanted = next[response]
			sig := syscall.SIGHUP
			if response == "Hello from hanoverd-2\r\n" {
				sig = syscall.SIGTERM
			}
			err := cmd.Process.Signal(sig)
			if err != nil {
				t.Errorf("Failed to signal hanoverd: %v", err)
				break loop
			}
			if sig == syscall.SIGTERM {
				break loop
			}
		}
		time.Sleep(100 * time.Millisecond)
	}
	err = cmd.Wait()
	if err != nil {
		t.Fatalf("waiting on hanoverd: %v", err)
	}
	log.Printf("Success!")
}
TestCWDBuildsAdvance attempts to run hanoverd in CWD-build mode in the
examples directory. It checks that the hostname advances.
package tests
import (
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	"path/filepath"
	"syscall"
	"testing"
	"time"
)
const (
	testPort = "50820"
)
var httpClient = &http.Client{
	Transport: &http.Transport{
		DisableKeepAlives: true,
	},
}
func simpleGetHTTP(url string) string {
	r, err := httpClient.Get(url)
	if r != nil && r.Body != nil {
		defer r.Body.Close()
	}
	if err != nil {
		return ""
	}
	bs, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return ""
	}
	return string(bs)
}