summaryrefslogtreecommitdiffstats
path: root/models/branches_test.go
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-11-04 15:31:59 +0200
committerGitHub <noreply@github.com>2017-11-04 15:31:59 +0200
commitbd6f24b4abcd932d55e9d01af3b6992843901d89 (patch)
treef2e517f9223a8312fd64d296ab3d5c84f3af2fbb /models/branches_test.go
parent1621069f833bb5c5531b926a1f9db0873f901d82 (diff)
downloadgitea-bd6f24b4abcd932d55e9d01af3b6992843901d89.tar.gz
gitea-bd6f24b4abcd932d55e9d01af3b6992843901d89.zip
Add deleted_branch table fixture (#2832)
* Add deleted_branch table fixture * Fix deleted branches tests * Remove unneeded global variable
Diffstat (limited to 'models/branches_test.go')
-rw-r--r--models/branches_test.go37
1 files changed, 14 insertions, 23 deletions
diff --git a/models/branches_test.go b/models/branches_test.go
index 512104cdd0..b7984331ed 100644
--- a/models/branches_test.go
+++ b/models/branches_test.go
@@ -10,30 +10,17 @@ import (
"github.com/stretchr/testify/assert"
)
-var firstBranch = DeletedBranch{
- ID: 1,
- Name: "foo",
- Commit: "1213212312313213213132131",
- DeletedByID: int64(1),
-}
-
-var secondBranch = DeletedBranch{
- ID: 2,
- Name: "bar",
- Commit: "5655464564554545466464655",
- DeletedByID: int64(99),
-}
-
func TestAddDeletedBranch(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
- assert.NoError(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
+ firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
+
assert.Error(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
- assert.NoError(t, repo.AddDeletedBranch(secondBranch.Name, secondBranch.Commit, secondBranch.DeletedByID))
+ assert.NoError(t, repo.AddDeletedBranch("test", "5655464564554545466464656", int64(1)))
}
+
func TestGetDeletedBranches(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
- AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
branches, err := repo.GetDeletedBranches()
@@ -43,11 +30,17 @@ func TestGetDeletedBranches(t *testing.T) {
func TestGetDeletedBranch(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
+ firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
+
assert.NotNil(t, getDeletedBranch(t, firstBranch))
}
func TestDeletedBranchLoadUser(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
+
+ firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
+ secondBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch)
+
branch := getDeletedBranch(t, firstBranch)
assert.Nil(t, branch.DeletedBy)
branch.LoadUser()
@@ -63,19 +56,17 @@ func TestDeletedBranchLoadUser(t *testing.T) {
func TestRemoveDeletedBranch(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
-
- branch := DeletedBranch{ID: 1}
- AssertExistsAndLoadBean(t, &branch)
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
+ firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
+
err := repo.RemoveDeletedBranch(1)
assert.NoError(t, err)
- AssertNotExistsBean(t, &branch)
+ AssertNotExistsBean(t, firstBranch)
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2})
}
-func getDeletedBranch(t *testing.T, branch DeletedBranch) *DeletedBranch {
- AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
+func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch {
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
deletedBranch, err := repo.GetDeletedBranchByID(branch.ID)