DATA-DOG / go-txdb

Immutable transaction isolated sql driver for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use testcontainers (or similar solution) for tests

flimzy opened this issue · comments

The current test suite depends on locally running MySQL and PostgreSQL instances, and fails rather spectacularly when it cannot connect:

    db_test.go:322: mysql_txdb: could not prepare - Error 1698 (28000): Access denied for user 'root'@'localhost'
--- FAIL: TestShouldReopenAfterClose (0.00s)
    db_test.go:387: mysql_txdb: could not prepare - Error 1698 (28000): Access denied for user 'root'@'localhost'
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x545f18]

I suggest we use go-testcontainers, or a similar tool, to run these tests so to ease the maintenence and writing of tests.

How about adding an env variable to choose databases? For example TXDB_TEST_DB=sqlite. Then you don't need any docker things on local machine. Github action will always run with postgres and mysql to make sure everything works.

I'm in favor of env variables, but I see that as a great addition to the use of testcontainers. Testcontainers also works great in GitHub actions, so could serve to simplify and unify test running both in local development and in CI.

I'm happy to throw together a PoC PR for your review, @Yiling-J.

env and testcontainer? That will be cool. @flimzy