Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #81
This warps the the *gorm.DB object in an interface
Transaction. Also the state object has also been wrapped in an interface.This allows mock transactions to be used for unit tests and will make it easier to use different databases, if needed, in the future.
This has required changes in a lot of files. The key changes are in the
datastorepackage, elsewhere they amount todatastore.GetStore().GetTransaction(ctx)changed todatastore.GetTransaction(ctx* )datastore.GetStore().CreateTransaction(ctx)changed todatastore.CreateTransaction(ctx).Errorchanged to.Error()To mock you can derive from MockTransaction and implicate mock code for any transaction methods you need in your test.
Alternately if your unit test makes more use of the database, you can create a new
MyMockStoreobject that implements the Store object with a mock database object, if the mock database object has the same methods as agorm.DBthen you can mostly cut and pastes on thedatastore.storeanddatabase.transactionobjectsand somewhere in your unit test