Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tapdb+mssmt: update mssmt unit tests to run against all registered db backends #770

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tapdb/mssmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,38 @@ func (t *taprootAssetTreeStoreTx) UpdateRoot(rootNode *mssmt.BranchNode) error {
Namespace: t.namespace,
})
}

func init() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be in the non-test code? Since it's only used by unit tests and does spin up an ephemeral container in the Postgres case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point re test code vs non test code. I'd need to double check, but I don't think an init is run in a _test.go when a package is imported.

Re postgres container: this'll only happen if the New method of the driver is called (won't be created unconditionally).

driver := mssmt.TreeStoreDriver{
Name: activeTestDB,
New: func(args ...interface{}) (mssmt.TreeStore, error) {
dbPath, ok := args[0].(string)
if !ok {
return nil, fmt.Errorf("invalid db path: "+
"want string, got %T", args[0])
}
namespace, ok := args[1].(string)
if !ok {
return nil, fmt.Errorf("invalid db path: "+
"want string, got %T", args[0])
}

sqlDB, err := NewDbHandleFromPath(dbPath)
if err != nil {
return nil, err
}

txCreator := func(tx *sql.Tx) TreeStore {
return sqlDB.WithTx(tx)
}

treeDB := NewTransactionExecutor(sqlDB, txCreator)

return NewTaprootAssetTreeStore(treeDB, namespace), nil
},
}
if err := mssmt.RegisterTreeStore(&driver); err != nil {
panic(fmt.Errorf("failed to register db=%v): %v",
activeTestDB, err))
}
}