Browse Source

Add deleted_branch table fixture (#2832)

* Add deleted_branch table fixture

* Fix deleted branches tests

* Remove unneeded global variable
Lauris BH 2 years ago
parent
commit
bd6f24b4ab
2 changed files with 29 additions and 23 deletions
  1. 14 23
      models/branches_test.go
  2. 15 0
      models/fixtures/deleted_branch.yml

+ 14 - 23
models/branches_test.go

@@ -10,30 +10,17 @@ import (
10 10
 	"github.com/stretchr/testify/assert"
11 11
 )
12 12
 
13
-var firstBranch = DeletedBranch{
14
-	ID:          1,
15
-	Name:        "foo",
16
-	Commit:      "1213212312313213213132131",
17
-	DeletedByID: int64(1),
18
-}
19
-
20
-var secondBranch = DeletedBranch{
21
-	ID:          2,
22
-	Name:        "bar",
23
-	Commit:      "5655464564554545466464655",
24
-	DeletedByID: int64(99),
25
-}
26
-
27 13
 func TestAddDeletedBranch(t *testing.T) {
28 14
 	assert.NoError(t, PrepareTestDatabase())
29 15
 	repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
30
-	assert.NoError(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
16
+	firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
17
+
31 18
 	assert.Error(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID))
32
-	assert.NoError(t, repo.AddDeletedBranch(secondBranch.Name, secondBranch.Commit, secondBranch.DeletedByID))
19
+	assert.NoError(t, repo.AddDeletedBranch("test", "5655464564554545466464656", int64(1)))
33 20
 }
21
+
34 22
 func TestGetDeletedBranches(t *testing.T) {
35 23
 	assert.NoError(t, PrepareTestDatabase())
36
-	AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
37 24
 	repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
38 25
 
39 26
 	branches, err := repo.GetDeletedBranches()
@@ -43,11 +30,17 @@ func TestGetDeletedBranches(t *testing.T) {
43 30
 
44 31
 func TestGetDeletedBranch(t *testing.T) {
45 32
 	assert.NoError(t, PrepareTestDatabase())
33
+	firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
34
+
46 35
 	assert.NotNil(t, getDeletedBranch(t, firstBranch))
47 36
 }
48 37
 
49 38
 func TestDeletedBranchLoadUser(t *testing.T) {
50 39
 	assert.NoError(t, PrepareTestDatabase())
40
+
41
+	firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
42
+	secondBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch)
43
+
51 44
 	branch := getDeletedBranch(t, firstBranch)
52 45
 	assert.Nil(t, branch.DeletedBy)
53 46
 	branch.LoadUser()
@@ -63,19 +56,17 @@ func TestDeletedBranchLoadUser(t *testing.T) {
63 56
 
64 57
 func TestRemoveDeletedBranch(t *testing.T) {
65 58
 	assert.NoError(t, PrepareTestDatabase())
66
-
67
-	branch := DeletedBranch{ID: 1}
68
-	AssertExistsAndLoadBean(t, &branch)
69 59
 	repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
70 60
 
61
+	firstBranch := AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
62
+
71 63
 	err := repo.RemoveDeletedBranch(1)
72 64
 	assert.NoError(t, err)
73
-	AssertNotExistsBean(t, &branch)
65
+	AssertNotExistsBean(t, firstBranch)
74 66
 	AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2})
75 67
 }
76 68
 
77
-func getDeletedBranch(t *testing.T, branch DeletedBranch) *DeletedBranch {
78
-	AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1})
69
+func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch {
79 70
 	repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
80 71
 
81 72
 	deletedBranch, err := repo.GetDeletedBranchByID(branch.ID)

+ 15 - 0
models/fixtures/deleted_branch.yml

@@ -0,0 +1,15 @@
1
+-
2
+  id: 1
3
+  repo_id: 1
4
+  name: foo
5
+  commit: 1213212312313213213132131
6
+  deleted_by_id: 1
7
+  deleted_unix: 978307200
8
+
9
+-
10
+  id: 2
11
+  repo_id: 1
12
+  name: bar
13
+  commit: 5655464564554545466464655
14
+  deleted_by_id: 99
15
+  deleted_unix: 978307200