You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: index_test.go
    path of file: ./repos/gitea/models/db
    
    the code of the file until where you have to start completion: // Copyright 2022 The Gitea Authors. All right
    
func TestGetNextResourceIndex(t *testing.T) {
	assert.NoError(t, unittest.PrepareTestDatabase())
	xe := unittest.GetXORMEngine()
	assert.NoError(t, xe.Sync(&TestIndex{}))

	// create a new record
	maxIndex, err := db.GetNextResourceIndex(db.DefaultContext, "test_index", 20)
	assert.NoError(t, err)
	assert.EqualValues(t, 1, maxIndex)

	// increase the existing record
	maxIndex, err = db.GetNextResourceIndex(db.DefaultContext, "test_index", 20)
	assert.NoError(t, err)
	assert.EqualValues(t, 2, maxIndex)

	// commit transaction
	err = db.WithTx(db.DefaultContext, func(ctx context.Context) error {
		maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20)
		assert.NoError(t, err)
		assert.EqualValues(t, 3, maxIndex)
		return nil
	})
	assert.NoError(t, err)
	maxIndex, err = getCurrentResourceIndex(db.DefaultContext, "test_index", 20)
	assert.NoError(t, err)
	assert.EqualValues(t, 3, maxIndex)

	// rollback transaction
	err = db.WithTx(db.DefaultContext, func(ctx context.Context) error {
		maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20)
		assert.NoError(t, err)
		assert.EqualValues(t, 4, maxIndex)
		return errors.New("test rollback")
	})
	assert.Error(t, err)
	maxIndex, err = getCurrentResourceIndex(db.DefaultContext, "test_index", 20)
	assert.NoError(t, err)
	assert.EqualValues(t, 3, maxIndex) // the max index doesn't change because the transaction was rolled back
}