Skip to content

dbtesting: Reduce unintended sideeffects by not setting an actor

Warren Gifford requested to merge dbtesting/less-sideffects into master

Created by: mrnugget

We (@tsenart and I) ran into an issue where the user we created in our GraphQL test was automatically the CurrentUser in the resolver, even though we never set it.

Turns out that by it was the current user by accident because the previous dbtesting.TestContext set an actor with the same UID on the context. Finding that took a long time.

So we decided to get rid of the side-effect and not set the actor in the function. Only 4 tests broke and we could easily fix those by setting an actor manually.

Then we realized that the ctx returned by TestContext doesn't have any test specific test information anymore and is just context.Background(), so we changed TestContext to not return a ctx anymore.

After that, the only thing TestContext did was (1) setup a test database and (2) set the global state so this test database is used. So we renamed it.

Testplan: go test ./...

Merge request reports

Loading