refactor: move SearchRepositoryByName testing. (#1083)
This commit is contained in:
parent
c2eef171ff
commit
e83c8afc56
2 changed files with 63 additions and 52 deletions
63
models/repo_list_test.go
Normal file
63
models/repo_list_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSearchRepositoryByName(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// test search public repository on explore page
|
||||
repos, count, err := SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "repo_12",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test_repo_12", repos[0].Name)
|
||||
assert.Equal(t, int64(1), count)
|
||||
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "test_repo",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
// test search private repository on explore page
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "repo_13",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test_repo_13", repos[0].Name)
|
||||
assert.Equal(t, int64(1), count)
|
||||
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "test_repo",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(3), count)
|
||||
}
|
|
@ -125,55 +125,3 @@ func TestForkRepository(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
assert.True(t, IsErrRepoAlreadyExist(err))
|
||||
}
|
||||
|
||||
func TestSearchRepositoryByName(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
// test search public repository on explore page
|
||||
repos, count, err := SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "repo_12",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test_repo_12", repos[0].Name)
|
||||
assert.Equal(t, int64(1), count)
|
||||
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "test_repo",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: nil,
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(2), count)
|
||||
|
||||
// test search private repository on explore page
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "repo_13",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "test_repo_13", repos[0].Name)
|
||||
assert.Equal(t, int64(1), count)
|
||||
|
||||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
|
||||
Keyword: "test_repo",
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
Searcher: &User{ID: 14},
|
||||
})
|
||||
|
||||
assert.NotNil(t, repos)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(3), count)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue