DATA-DOG / go-txdb

Immutable transaction isolated sql driver for golang
Other
667 stars 48 forks source link

Use testcontainers (or similar solution) for tests #57

Closed flimzy closed 3 months ago

flimzy commented 12 months ago

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.

Yiling-J commented 12 months ago

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.

flimzy commented 12 months ago

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.

flimzy commented 12 months ago

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

Yiling-J commented 12 months ago

env and testcontainer? That will be cool. @flimzy