Commit 5d3d5373 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Factor out 'run or fail' test pattern

parent 29d303c5
...@@ -42,10 +42,7 @@ func TestAllowedClone(t *testing.T) { ...@@ -42,10 +42,7 @@ func TestAllowedClone(t *testing.T) {
// Do the git clone // Do the git clone
cloneCmd := exec.Command("git", "clone", remote, path.Join(scratchDir, "test")) cloneCmd := exec.Command("git", "clone", remote, path.Join(scratchDir, "test"))
if out, err := cloneCmd.CombinedOutput(); err != nil { runOrFail(t, cloneCmd)
t.Logf("%s", out)
t.Fatal(err)
}
} }
func TestAllowedPush(t *testing.T) { func TestAllowedPush(t *testing.T) {
...@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) { ...@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
cloneCmd := exec.Command("git", "clone", path.Join(testRepoRoot, testRepo), checkoutDir) cloneCmd := exec.Command("git", "clone", path.Join(testRepoRoot, testRepo), checkoutDir)
if out, err := cloneCmd.CombinedOutput(); err != nil { runOrFail(t, cloneCmd)
t.Logf("%s", out)
t.Fatal(err)
}
branch := fmt.Sprintf("branch-%d", time.Now().UnixNano()) branch := fmt.Sprintf("branch-%d", time.Now().UnixNano())
branchCmd := exec.Command("git", "branch", branch) branchCmd := exec.Command("git", "branch", branch)
branchCmd.Dir = checkoutDir branchCmd.Dir = checkoutDir
if out, err := branchCmd.CombinedOutput(); err != nil { runOrFail(t, branchCmd)
t.Logf("%s", out)
t.Fatal(err)
}
// Prepare the test server and backend // Prepare the test server and backend
ts := testAuthServer(200, `{"GL_ID":"user-123"}`) ts := testAuthServer(200, `{"GL_ID":"user-123"}`)
...@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) { ...@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) {
// Perform the git push // Perform the git push
pushCmd := exec.Command("git", "push", remote, branch) pushCmd := exec.Command("git", "push", remote, branch)
pushCmd.Dir = checkoutDir pushCmd.Dir = checkoutDir
if out, err := pushCmd.CombinedOutput(); err != nil { runOrFail(t, pushCmd)
t.Logf("%s", out)
t.Fatal(err)
}
} }
func testAuthServer(code int, body string) *httptest.Server { func testAuthServer(code int, body string) *httptest.Server {
...@@ -114,3 +102,10 @@ func waitServer() (err error) { ...@@ -114,3 +102,10 @@ func waitServer() (err error) {
} }
return return
} }
func runOrFail(t *testing.T, cmd *exec.Cmd) {
if out, err := cmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment