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) {
// Do the git clone
cloneCmd := exec.Command("git", "clone", remote, path.Join(scratchDir, "test"))
if out, err := cloneCmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
runOrFail(t, cloneCmd)
}
func TestAllowedPush(t *testing.T) {
......@@ -55,17 +52,11 @@ func TestAllowedPush(t *testing.T) {
t.Fatal(err)
}
cloneCmd := exec.Command("git", "clone", path.Join(testRepoRoot, testRepo), checkoutDir)
if out, err := cloneCmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
runOrFail(t, cloneCmd)
branch := fmt.Sprintf("branch-%d", time.Now().UnixNano())
branchCmd := exec.Command("git", "branch", branch)
branchCmd.Dir = checkoutDir
if out, err := branchCmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
runOrFail(t, branchCmd)
// Prepare the test server and backend
ts := testAuthServer(200, `{"GL_ID":"user-123"}`)
......@@ -82,10 +73,7 @@ func TestAllowedPush(t *testing.T) {
// Perform the git push
pushCmd := exec.Command("git", "push", remote, branch)
pushCmd.Dir = checkoutDir
if out, err := pushCmd.CombinedOutput(); err != nil {
t.Logf("%s", out)
t.Fatal(err)
}
runOrFail(t, pushCmd)
}
func testAuthServer(code int, body string) *httptest.Server {
......@@ -114,3 +102,10 @@ func waitServer() (err error) {
}
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