Slight performance changes to integrations/git_test.go (#11227)
* switch to use pseudorandom generator and stop cloning in pushcreate Signed-off-by: Andrew Thornton <art27@cantab.net> * Add some logging of BranchProtectPRMerge Signed-off-by: Andrew Thornton <art27@cantab.net> * Stop running prepareTestEnv so often for TestAPIGetBranch Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
0e799c26ba
commit
d26aee3830
|
@ -14,8 +14,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
|
func testAPIGetBranch(t *testing.T, branchName string, exists bool) {
|
||||||
defer prepareTestEnv(t)()
|
|
||||||
|
|
||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
token := getTokenForLoggedInUser(t, session)
|
token := getTokenForLoggedInUser(t, session)
|
||||||
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
|
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branches/%s?token=%s", branchName, token)
|
||||||
|
@ -88,6 +86,7 @@ func testAPIDeleteBranch(t *testing.T, branchName string, expectedHTTPStatus int
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIGetBranch(t *testing.T) {
|
func TestAPIGetBranch(t *testing.T) {
|
||||||
|
defer prepareTestEnv(t)()
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
BranchName string
|
BranchName string
|
||||||
Exists bool
|
Exists bool
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -70,6 +70,7 @@ func testGit(t *testing.T, u *url.URL) {
|
||||||
|
|
||||||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
|
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&httpContext, dstPath))
|
||||||
t.Run("MergeFork", func(t *testing.T) {
|
t.Run("MergeFork", func(t *testing.T) {
|
||||||
|
defer PrintCurrentTest(t)()
|
||||||
t.Run("CreatePRAndMerge", doMergeFork(httpContext, forkedUserCtx, "master", httpContext.Username+":master"))
|
t.Run("CreatePRAndMerge", doMergeFork(httpContext, forkedUserCtx, "master", httpContext.Username+":master"))
|
||||||
rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
||||||
mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
||||||
|
@ -109,6 +110,7 @@ func testGit(t *testing.T, u *url.URL) {
|
||||||
|
|
||||||
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
|
t.Run("BranchProtectMerge", doBranchProtectPRMerge(&sshContext, dstPath))
|
||||||
t.Run("MergeFork", func(t *testing.T) {
|
t.Run("MergeFork", func(t *testing.T) {
|
||||||
|
defer PrintCurrentTest(t)()
|
||||||
t.Run("CreatePRAndMerge", doMergeFork(sshContext, forkedUserCtx, "master", sshContext.Username+":master"))
|
t.Run("CreatePRAndMerge", doMergeFork(sshContext, forkedUserCtx, "master", sshContext.Username+":master"))
|
||||||
rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
rawTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
||||||
mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
mediaTest(t, &forkedUserCtx, little, big, littleLFS, bigLFS)
|
||||||
|
@ -291,17 +293,34 @@ func doCommitAndPush(t *testing.T, size int, repoPath, prefix string) string {
|
||||||
|
|
||||||
func generateCommitWithNewData(size int, repoPath, email, fullName, prefix string) (string, error) {
|
func generateCommitWithNewData(size int, repoPath, email, fullName, prefix string) (string, error) {
|
||||||
//Generate random file
|
//Generate random file
|
||||||
data := make([]byte, size)
|
bufSize := 4 * 1024
|
||||||
_, err := rand.Read(data)
|
if bufSize > size {
|
||||||
if err != nil {
|
bufSize = size
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer := make([]byte, bufSize)
|
||||||
|
|
||||||
tmpFile, err := ioutil.TempFile(repoPath, prefix)
|
tmpFile, err := ioutil.TempFile(repoPath, prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer tmpFile.Close()
|
defer tmpFile.Close()
|
||||||
_, err = tmpFile.Write(data)
|
written := 0
|
||||||
|
for written < size {
|
||||||
|
n := size - written
|
||||||
|
if n > bufSize {
|
||||||
|
n = bufSize
|
||||||
|
}
|
||||||
|
_, err := rand.Read(buffer[:n])
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
n, err = tmpFile.Write(buffer[:n])
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
written += n
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -411,6 +430,7 @@ func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string)
|
||||||
|
|
||||||
func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) func(t *testing.T) {
|
func doMergeFork(ctx, baseCtx APITestContext, baseBranch, headBranch string) func(t *testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
|
defer PrintCurrentTest(t)()
|
||||||
var pr api.PullRequest
|
var pr api.PullRequest
|
||||||
var err error
|
var err error
|
||||||
t.Run("CreatePullRequest", func(t *testing.T) {
|
t.Run("CreatePullRequest", func(t *testing.T) {
|
||||||
|
@ -485,9 +505,6 @@ func doPushCreate(ctx APITestContext, u *url.URL) func(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir("", ctx.Reponame)
|
tmpDir, err := ioutil.TempDir("", ctx.Reponame)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = git.NewCommand("clone", u.String()).RunInDir(tmpDir)
|
|
||||||
assert.Error(t, err)
|
|
||||||
|
|
||||||
err = git.InitRepository(tmpDir, false)
|
err = git.InitRepository(tmpDir, false)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue