mirror of
https://github.com/go-gitea/gitea
synced 2024-11-28 11:02:57 +01:00
Add deleted_branch table fixture (#2832)
* Add deleted_branch table fixture * Fix deleted branches tests * Remove unneeded global variable
This commit is contained in:
parent
1621069f83
commit
bd6f24b4ab
2 changed files with 29 additions and 23 deletions
|
@ -10,30 +10,17 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestAddDeletedBranch(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
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.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) {
|
func TestGetDeletedBranches(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
|
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||||
|
|
||||||
branches, err := repo.GetDeletedBranches()
|
branches, err := repo.GetDeletedBranches()
|
||||||
|
@ -43,11 +30,17 @@ func TestGetDeletedBranches(t *testing.T) {
|
||||||
|
|
||||||
func TestGetDeletedBranch(t *testing.T) {
|
func TestGetDeletedBranch(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||||
|
|
||||||
assert.NotNil(t, getDeletedBranch(t, firstBranch))
|
assert.NotNil(t, getDeletedBranch(t, firstBranch))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeletedBranchLoadUser(t *testing.T) {
|
func TestDeletedBranchLoadUser(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
|
firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||||
|
secondBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch)
|
||||||
|
|
||||||
branch := getDeletedBranch(t, firstBranch)
|
branch := getDeletedBranch(t, firstBranch)
|
||||||
assert.Nil(t, branch.DeletedBy)
|
assert.Nil(t, branch.DeletedBy)
|
||||||
branch.LoadUser()
|
branch.LoadUser()
|
||||||
|
@ -63,19 +56,17 @@ func TestDeletedBranchLoadUser(t *testing.T) {
|
||||||
|
|
||||||
func TestRemoveDeletedBranch(t *testing.T) {
|
func TestRemoveDeletedBranch(t *testing.T) {
|
||||||
assert.NoError(t, PrepareTestDatabase())
|
assert.NoError(t, PrepareTestDatabase())
|
||||||
|
|
||||||
branch := DeletedBranch{ID: 1}
|
|
||||||
AssertExistsAndLoadBean(t, &branch)
|
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||||
|
|
||||||
|
firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||||
|
|
||||||
err := repo.RemoveDeletedBranch(1)
|
err := repo.RemoveDeletedBranch(1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
AssertNotExistsBean(t, &branch)
|
AssertNotExistsBean(t, firstBranch)
|
||||||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2})
|
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeletedBranch(t *testing.T, branch DeletedBranch) *DeletedBranch {
|
func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch {
|
||||||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
|
|
||||||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||||
|
|
||||||
deletedBranch, err := repo.GetDeletedBranchByID(branch.ID)
|
deletedBranch, err := repo.GetDeletedBranchByID(branch.ID)
|
||||||
|
|
15
models/fixtures/deleted_branch.yml
Normal file
15
models/fixtures/deleted_branch.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
-
|
||||||
|
id: 1
|
||||||
|
repo_id: 1
|
||||||
|
name: foo
|
||||||
|
commit: 1213212312313213213132131
|
||||||
|
deleted_by_id: 1
|
||||||
|
deleted_unix: 978307200
|
||||||
|
|
||||||
|
-
|
||||||
|
id: 2
|
||||||
|
repo_id: 1
|
||||||
|
name: bar
|
||||||
|
commit: 5655464564554545466464655
|
||||||
|
deleted_by_id: 99
|
||||||
|
deleted_unix: 978307200
|
Loading…
Reference in a new issue