Browse Source

test: Add testing for GetUserFork function (#944)

Bo-Yi Wu 2 years ago
parent
commit
43c94d0a6c
3 changed files with 89 additions and 0 deletions
  1. 26 0
      models/fixtures/repository.yml
  2. 30 0
      models/fixtures/user.yml
  3. 33 0
      models/repo_test.go

+ 26 - 0
models/fixtures/repository.yml

@@ -105,3 +105,29 @@
105 105
   num_pulls: 0
106 106
   num_closed_pulls: 0
107 107
   is_mirror: false
108
+
109
+-
110
+  id: 10
111
+  owner_id: 12
112
+  lower_name: repo10
113
+  name: repo10
114
+  is_private: false
115
+  num_issues: 0
116
+  num_closed_issues: 0
117
+  num_pulls: 0
118
+  num_closed_pulls: 0
119
+  is_mirror: false
120
+  num_forks: 1
121
+
122
+-
123
+  id: 11
124
+  fork_id: 10
125
+  owner_id: 13
126
+  lower_name: repo11
127
+  name: repo11
128
+  is_private: false
129
+  num_issues: 0
130
+  num_closed_issues: 0
131
+  num_pulls: 0
132
+  num_closed_pulls: 0
133
+  is_mirror: false

+ 30 - 0
models/fixtures/user.yml

@@ -164,3 +164,33 @@
164 164
   avatar_email: user11@example.com
165 165
   num_repos: 1
166 166
   is_active: true
167
+
168
+-
169
+  id: 12
170
+  lower_name: user12
171
+  name: user12
172
+  full_name: User 12
173
+  email: user12@example.com
174
+  passwd: password
175
+  type: 0 # individual
176
+  salt: salt
177
+  is_admin: false
178
+  avatar: avatar12
179
+  avatar_email: user12@example.com
180
+  num_repos: 1
181
+  is_active: true
182
+
183
+-
184
+  id: 13
185
+  lower_name: user13
186
+  name: user13
187
+  full_name: User 13
188
+  email: user13@example.com
189
+  passwd: password
190
+  type: 0 # individual
191
+  salt: salt
192
+  is_admin: false
193
+  avatar: avatar13
194
+  avatar_email: user13@example.com
195
+  num_repos: 1
196
+  is_active: true

+ 33 - 0
models/repo_test.go

@@ -92,3 +92,36 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
92 92
 	assert.NoError(t, err)
93 93
 	assert.Equal(t, true, act.IsPrivate)
94 94
 }
95
+
96
+func TestGetUserFork(t *testing.T) {
97
+	assert.NoError(t, PrepareTestDatabase())
98
+
99
+	// User13 has repo 11 forked from repo10
100
+	repo, err := GetRepositoryByID(10)
101
+	assert.NoError(t, err)
102
+	assert.NotNil(t, repo)
103
+	repo, err = repo.GetUserFork(13)
104
+	assert.NoError(t, err)
105
+	assert.NotNil(t, repo)
106
+
107
+	repo, err = GetRepositoryByID(9)
108
+	assert.NoError(t, err)
109
+	assert.NotNil(t, repo)
110
+	repo, err = repo.GetUserFork(13)
111
+	assert.NoError(t, err)
112
+	assert.Nil(t, repo)
113
+}
114
+
115
+func TestForkRepository(t *testing.T) {
116
+	assert.NoError(t, PrepareTestDatabase())
117
+
118
+	// User13 has repo 11 forked from repo10
119
+	repo, err := GetRepositoryByID(10)
120
+	assert.NoError(t, err)
121
+	assert.NotNil(t, repo)
122
+
123
+	repo, err = ForkRepository(&User{ID: 13}, repo, "test", "test")
124
+	assert.Nil(t, repo)
125
+	assert.Error(t, err)
126
+	assert.True(t, IsErrRepoAlreadyExist(err))
127
+}