summaryrefslogtreecommitdiffstats
path: root/modules/test/context_tests.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2018-04-28 23:21:33 -0700
committerLunny Xiao <xiaolunwen@gmail.com>2018-04-29 14:21:33 +0800
commit7ea4bfc56172faf588142ee5637f35c0344f7534 (patch)
treef4d47e2d4209b90d340dead5e3abb7b4a02cb475 /modules/test/context_tests.go
parent5a62eb30df3a04e76e465824f525b4ffd920b562 (diff)
downloadgitea-7ea4bfc56172faf588142ee5637f35c0344f7534.tar.gz
gitea-7ea4bfc56172faf588142ee5637f35c0344f7534.zip
API endpoint for testing webhook (#3550)
* API endpoint for testing webhook * Empty commit to rerun CI
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)