Skip to content

Commit e83c8af

Browse files
appleboylunny
authored andcommitted
refactor: move SearchRepositoryByName testing. (#1083)
1 parent c2eef17 commit e83c8af

File tree

2 files changed

+63
-52
lines changed

2 files changed

+63
-52
lines changed

models/repo_list_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package models
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestSearchRepositoryByName(t *testing.T) {
14+
assert.NoError(t, PrepareTestDatabase())
15+
16+
// test search public repository on explore page
17+
repos, count, err := SearchRepositoryByName(&SearchRepoOptions{
18+
Keyword: "repo_12",
19+
Page: 1,
20+
PageSize: 10,
21+
Searcher: nil,
22+
})
23+
24+
assert.NotNil(t, repos)
25+
assert.NoError(t, err)
26+
assert.Equal(t, "test_repo_12", repos[0].Name)
27+
assert.Equal(t, int64(1), count)
28+
29+
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
30+
Keyword: "test_repo",
31+
Page: 1,
32+
PageSize: 10,
33+
Searcher: nil,
34+
})
35+
36+
assert.NotNil(t, repos)
37+
assert.NoError(t, err)
38+
assert.Equal(t, int64(2), count)
39+
40+
// test search private repository on explore page
41+
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
42+
Keyword: "repo_13",
43+
Page: 1,
44+
PageSize: 10,
45+
Searcher: &User{ID: 14},
46+
})
47+
48+
assert.NotNil(t, repos)
49+
assert.NoError(t, err)
50+
assert.Equal(t, "test_repo_13", repos[0].Name)
51+
assert.Equal(t, int64(1), count)
52+
53+
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
54+
Keyword: "test_repo",
55+
Page: 1,
56+
PageSize: 10,
57+
Searcher: &User{ID: 14},
58+
})
59+
60+
assert.NotNil(t, repos)
61+
assert.NoError(t, err)
62+
assert.Equal(t, int64(3), count)
63+
}

models/repo_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -125,55 +125,3 @@ func TestForkRepository(t *testing.T) {
125125
assert.Error(t, err)
126126
assert.True(t, IsErrRepoAlreadyExist(err))
127127
}
128-
129-
func TestSearchRepositoryByName(t *testing.T) {
130-
assert.NoError(t, PrepareTestDatabase())
131-
132-
// test search public repository on explore page
133-
repos, count, err := SearchRepositoryByName(&SearchRepoOptions{
134-
Keyword: "repo_12",
135-
Page: 1,
136-
PageSize: 10,
137-
Searcher: nil,
138-
})
139-
140-
assert.NotNil(t, repos)
141-
assert.NoError(t, err)
142-
assert.Equal(t, "test_repo_12", repos[0].Name)
143-
assert.Equal(t, int64(1), count)
144-
145-
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
146-
Keyword: "test_repo",
147-
Page: 1,
148-
PageSize: 10,
149-
Searcher: nil,
150-
})
151-
152-
assert.NotNil(t, repos)
153-
assert.NoError(t, err)
154-
assert.Equal(t, int64(2), count)
155-
156-
// test search private repository on explore page
157-
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
158-
Keyword: "repo_13",
159-
Page: 1,
160-
PageSize: 10,
161-
Searcher: &User{ID: 14},
162-
})
163-
164-
assert.NotNil(t, repos)
165-
assert.NoError(t, err)
166-
assert.Equal(t, "test_repo_13", repos[0].Name)
167-
assert.Equal(t, int64(1), count)
168-
169-
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
170-
Keyword: "test_repo",
171-
Page: 1,
172-
PageSize: 10,
173-
Searcher: &User{ID: 14},
174-
})
175-
176-
assert.NotNil(t, repos)
177-
assert.NoError(t, err)
178-
assert.Equal(t, int64(3), count)
179-
}

0 commit comments

Comments
 (0)