mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: consolidate Go tests (#39962)
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -42,7 +42,10 @@ func TestTxContext(t *testing.T) {
|
||||
assert.NoError(t, committer.Commit())
|
||||
}
|
||||
|
||||
{ // reuse the transaction created by TxContext and commit it
|
||||
for _, finish := range []func(db.Committer) error{
|
||||
db.Committer.Commit, // reuse the transaction created by TxContext and commit it
|
||||
db.Committer.Close, // reuse the transaction created by TxContext and close it
|
||||
} {
|
||||
ctx, committer, err := db.TxContext(t.Context())
|
||||
engine := db.GetEngine(ctx)
|
||||
assert.NoError(t, err)
|
||||
@@ -52,24 +55,9 @@ func TestTxContext(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, db.InTransaction(ctx))
|
||||
assert.Equal(t, engine, db.GetEngine(ctx))
|
||||
assert.NoError(t, committer.Commit())
|
||||
assert.NoError(t, finish(committer))
|
||||
}
|
||||
assert.NoError(t, committer.Commit())
|
||||
}
|
||||
|
||||
{ // reuse the transaction created by TxContext and close it
|
||||
ctx, committer, err := db.TxContext(t.Context())
|
||||
engine := db.GetEngine(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, db.InTransaction(ctx))
|
||||
{
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, db.InTransaction(ctx))
|
||||
assert.Equal(t, engine, db.GetEngine(ctx))
|
||||
assert.NoError(t, committer.Close())
|
||||
}
|
||||
assert.NoError(t, committer.Close())
|
||||
assert.NoError(t, finish(committer))
|
||||
}
|
||||
|
||||
{ // reuse the transaction created by WithTx
|
||||
|
||||
+16
-21
@@ -35,27 +35,22 @@ func TestSyncMaxResourceIndex(t *testing.T) {
|
||||
xe := unittest.GetXORMEngine()
|
||||
assert.NoError(t, xe.Sync(&TestIndex{}))
|
||||
|
||||
err := db.SyncMaxResourceIndex(t.Context(), "test_index", 10, 51)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// sync new max index
|
||||
maxIndex, err := getCurrentResourceIndex(t.Context(), "test_index", 10)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 51, maxIndex)
|
||||
|
||||
// smaller index doesn't change
|
||||
err = db.SyncMaxResourceIndex(t.Context(), "test_index", 10, 30)
|
||||
assert.NoError(t, err)
|
||||
maxIndex, err = getCurrentResourceIndex(t.Context(), "test_index", 10)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 51, maxIndex)
|
||||
|
||||
// larger index changes
|
||||
err = db.SyncMaxResourceIndex(t.Context(), "test_index", 10, 62)
|
||||
assert.NoError(t, err)
|
||||
maxIndex, err = getCurrentResourceIndex(t.Context(), "test_index", 10)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 62, maxIndex)
|
||||
var maxIndex int64
|
||||
var err error
|
||||
for _, test := range []struct {
|
||||
index int64
|
||||
expected int
|
||||
}{
|
||||
{51, 51}, // sync new max index
|
||||
{30, 51}, // smaller index doesn't change
|
||||
{62, 62}, // larger index changes
|
||||
} {
|
||||
err = db.SyncMaxResourceIndex(t.Context(), "test_index", 10, test.index)
|
||||
assert.NoError(t, err)
|
||||
maxIndex, err = getCurrentResourceIndex(t.Context(), "test_index", 10)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, test.expected, maxIndex)
|
||||
}
|
||||
|
||||
// commit transaction
|
||||
err = db.WithTx(t.Context(), func(ctx context.Context) error {
|
||||
|
||||
Reference in new issue
Block a user