summaryrefslogtreecommitdiffstats
path: root/modules/test/context_tests.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/test/context_tests.go')
-rw-r--r--modules/test/context_tests.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index bd5ea3fd38..b2b96fff9d 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -13,10 +13,11 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "net/http/httptest"
+
"github.com/go-macaron/session"
"github.com/stretchr/testify/assert"
"gopkg.in/macaron.v1"
- "net/http/httptest"
)
// MockContext mock context for unit tests
@@ -48,6 +49,16 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
ctx.Repo.RepoLink = ctx.Repo.Repository.Link()
}
+// LoadRepoCommit loads a repo's commit into a test context.
+func LoadRepoCommit(t *testing.T, ctx *context.Context) {
+ gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
+ assert.NoError(t, err)
+ branch, err := gitRepo.GetHEADBranch()
+ assert.NoError(t, err)
+ ctx.Repo.Commit, err = gitRepo.GetBranchCommit(branch.Name)
+ assert.NoError(t, err)
+}
+
// LoadUser load a user into a test context.
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
ctx.User = models.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)