How to bootstrap Nakama in Go tests and get real nk, logger, db, and initializer

I’m trying to run integration tests for my Go runtime code and need access to the real Nakama runtime context — specifically nk, logger, db, and initializer — the same way Nakama provides them to InitModule.

Mocking these interfaces works fine for unit tests, but for integration tests I want to run against an actual Nakama runtime so that all calls (StorageWrite, WalletUpdate, etc.) go through the real system.

Is there a supported or recommended way to bootstrap Nakama directly inside go test so I can get these real runtime components?

Ideally I’d like to be able to run go test ./… (or “Run All” in my IDE) and have it:

  • start a real Nakama runtime programmatically,

  • load my Go module,

  • and let me call my functions directly (not necessarily through RPC).

In short, I’m looking for a way to initialize Nakama from within tests and obtain the same runtime context objects that Nakama passes to modules.

Has anyone done this, or is there an official approach for setting up integration tests like this?

What if you make a test.go file with your test functions, and call it inside your InitModule() function to do the tests before it is initialized, or afterwards if you need to wait until it is finished initializing?

I think you can also call RPC from the server, so you could define a “test” RPC and make the module call “itself” to start the tests, maybe that would work?

Or maybe make a “tests” nakama module that only does the testing when it is initialized and imports the source files from the other modules you want to test?

1 Like