From 54cefc8500136ca60f294bbb3360faeccaaf52b1 Mon Sep 17 00:00:00 2001
From: Niall Sheridan <nsheridan@gmail.com>
Date: Sun, 19 Feb 2017 02:20:04 +0000
Subject: [PATCH] enable race detection

---
 run_tests.sh            |  4 ++--
 server/handlers_test.go | 23 ++++++++---------------
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/run_tests.sh b/run_tests.sh
index b506438c..3b271930 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -6,8 +6,8 @@
 
 set -xue
 
-go install -v ./cmd/cashier ./cmd/cashierd
-go list ./... |grep -v vendor/ |xargs go test
+go install -race -v ./cmd/cashier ./cmd/cashierd
+go list ./... |grep -v vendor/ |xargs go test -race
 gofmt -d $(find * -type f -name '*.go' -not -path 'vendor/*')
 go list ./... |grep -v vendor/ |xargs go vet
 if ! type -f golint > /dev/null; then
diff --git a/server/handlers_test.go b/server/handlers_test.go
index a08d638d..1670f2f7 100644
--- a/server/handlers_test.go
+++ b/server/handlers_test.go
@@ -26,23 +26,20 @@ import (
 	"github.com/stripe/krl"
 )
 
-func newContext(t *testing.T) *appContext {
-	f, err := ioutil.TempFile(os.TempDir(), "signing_key_")
-	if err != nil {
-		t.Error(err)
-	}
+var ctx *appContext
+
+func init() {
+	f, _ := ioutil.TempFile(os.TempDir(), "signing_key_")
 	defer os.Remove(f.Name())
 	f.Write(testdata.Priv)
 	f.Close()
-	if keysigner, err = signer.New(&config.SSH{
+	keysigner, _ = signer.New(&config.SSH{
 		SigningKey: f.Name(),
 		MaxAge:     "1h",
-	}); err != nil {
-		t.Error(err)
-	}
+	})
 	authprovider = testprovider.New()
 	certstore = store.NewMemoryStore()
-	return &appContext{
+	ctx = &appContext{
 		cookiestore: sessions.NewCookieStore([]byte("secret")),
 		authsession: &auth.Session{AuthURL: "https://www.example.com/auth"},
 	}
@@ -51,7 +48,7 @@ func newContext(t *testing.T) *appContext {
 func TestLoginHandler(t *testing.T) {
 	req, _ := http.NewRequest("GET", "/auth/login", nil)
 	resp := httptest.NewRecorder()
-	loginHandler(newContext(t), resp, req)
+	loginHandler(ctx, resp, req)
 	if resp.Code != http.StatusFound && resp.Header().Get("Location") != "https://www.example.com/auth" {
 		t.Error("Unexpected response")
 	}
@@ -61,7 +58,6 @@ func TestCallbackHandler(t *testing.T) {
 	req, _ := http.NewRequest("GET", "/auth/callback", nil)
 	req.Form = url.Values{"state": []string{"state"}, "code": []string{"abcdef"}}
 	resp := httptest.NewRecorder()
-	ctx := newContext(t)
 	ctx.setAuthStateCookie(resp, req, "state")
 	callbackHandler(ctx, resp, req)
 	if resp.Code != http.StatusFound && resp.Header().Get("Location") != "/" {
@@ -72,7 +68,6 @@ func TestCallbackHandler(t *testing.T) {
 func TestRootHandler(t *testing.T) {
 	req, _ := http.NewRequest("GET", "/", nil)
 	resp := httptest.NewRecorder()
-	ctx := newContext(t)
 	tok := &oauth2.Token{
 		AccessToken: "XXX_TEST_TOKEN_STRING_XXX",
 		Expiry:      time.Now().Add(1 * time.Hour),
@@ -87,7 +82,6 @@ func TestRootHandler(t *testing.T) {
 func TestRootHandlerNoSession(t *testing.T) {
 	req, _ := http.NewRequest("GET", "/", nil)
 	resp := httptest.NewRecorder()
-	ctx := newContext(t)
 	rootHandler(ctx, resp, req)
 	if resp.Code != http.StatusSeeOther {
 		t.Errorf("Unexpected status: %s, wanted %s", http.StatusText(resp.Code), http.StatusText(http.StatusSeeOther))
@@ -101,7 +95,6 @@ func TestSignRevoke(t *testing.T) {
 	})
 	req, _ := http.NewRequest("POST", "/sign", bytes.NewReader(s))
 	resp := httptest.NewRecorder()
-	ctx := newContext(t)
 	req.Header.Set("Authorization", "Bearer abcdef")
 	signHandler(ctx, resp, req)
 	if resp.Code != http.StatusOK {
-- 
GitLab