diff --git a/main_test.go b/main_test.go index 714931b35493d27ba25291b17c8401c444ac8c32..bd14e354167776e58d5ac59221c2402fa7752504 100644 --- a/main_test.go +++ b/main_test.go @@ -79,7 +79,7 @@ func TestDeniedClone(t *testing.T) { } func TestAllowedPush(t *testing.T) { - branch := preparePushRepo(t) + preparePushRepo(t) // Prepare the test server and backend ts := testAuthServer(200, `{"GL_ID":"user-123"}`) @@ -94,13 +94,13 @@ func TestAllowedPush(t *testing.T) { } // Perform the git push - pushCmd := exec.Command("git", "push", remote, branch) + pushCmd := exec.Command("git", "push", remote, fmt.Sprintf("master:%s", newBranch())) pushCmd.Dir = checkoutDir runOrFail(t, pushCmd) } func TestDeniedPush(t *testing.T) { - branch := preparePushRepo(t) + preparePushRepo(t) // Prepare the test server and backend ts := testAuthServer(403, "Access denied") @@ -115,7 +115,7 @@ func TestDeniedPush(t *testing.T) { } // Perform the git push - pushCmd := exec.Command("git", "push", remote, branch) + pushCmd := exec.Command("git", "push", "-v", remote, fmt.Sprintf("master:%s", newBranch())) pushCmd.Dir = checkoutDir out, err := pushCmd.CombinedOutput() t.Logf("%s", out) @@ -124,17 +124,17 @@ func TestDeniedPush(t *testing.T) { } } -func preparePushRepo(t *testing.T) string { +func preparePushRepo(t *testing.T) { if err := os.RemoveAll(scratchDir); err != nil { t.Fatal(err) } cloneCmd := exec.Command("git", "clone", path.Join(testRepoRoot, testRepo), checkoutDir) runOrFail(t, cloneCmd) - branch := fmt.Sprintf("branch-%d", time.Now().UnixNano()) - branchCmd := exec.Command("git", "branch", branch) - branchCmd.Dir = checkoutDir - runOrFail(t, branchCmd) - return branch + return +} + +func newBranch() string { + return fmt.Sprintf("branch-%d", time.Now().UnixNano()) } func testAuthServer(code int, body string) *httptest.Server {