-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor issue indexer, add some testing and fix a bug (#6131)
* refactor issue indexer, add some testing and fix a bug * fix error copyright year on comment header * issues indexer package import keep consistent
- Loading branch information
Showing
11 changed files
with
231 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2019 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 issues | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func fatalTestError(fmtStr string, args ...interface{}) { | ||
fmt.Fprintf(os.Stderr, fmtStr, args...) | ||
os.Exit(1) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
models.MainTest(m, filepath.Join("..", "..", "..")) | ||
} | ||
|
||
func TestSearchIssues(t *testing.T) { | ||
assert.NoError(t, models.PrepareTestDatabase()) | ||
|
||
os.RemoveAll(setting.Indexer.IssueIndexerQueueDir) | ||
os.RemoveAll(setting.Indexer.IssuePath) | ||
if err := InitIssueIndexer(true); err != nil { | ||
fatalTestError("Error InitIssueIndexer: %v\n", err) | ||
} | ||
|
||
time.Sleep(10 * time.Second) | ||
|
||
ids, err := SearchIssuesByKeyword(1, "issue2") | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, []int64{2}, ids) | ||
|
||
ids, err = SearchIssuesByKeyword(1, "first") | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, []int64{1}, ids) | ||
|
||
ids, err = SearchIssuesByKeyword(1, "for") | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, []int64{1, 2, 3, 5}, ids) | ||
} |
Oops, something went wrong.