aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_list_test.go
blob: 1fbfa935e9e413df864289be435f9070189c00e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)
}