How to test functions that use InfluxDB without creating a database?

A bit of a simple question which may have an answer that I’m missing - if I’ve created functions that call upon an InfluxDB Client library (for writing, not querying), and I wanted to test those functions without having to spin up a database for the functions to operate properly, how would I go about doing that? Is such a thing possible?

(Functions are written in Golang, and I’m using the InfluxDB 2.0 Client for Golang.)

The idea of testing without a database would be so that it could be done in a containerised pipeline.

You can possibly use the GoMock library to substitute parts of the InfluxDB client with mock functions to ensure that they are being called and also skip them actually trying to write to a database.

I ended up using something like this but constructed the mock myself (without GoMock).

Essentially made a type FakeWriter struct {} which had the same methods as api.WriteApi, like

func (fakeWr *FakeWriter) WriteRecord(line string) {}

and so on. For the error-channel-returning method, I created something like:

func (fakeWr *FakeWriter) Errors() <-chan error {

  errorChannel := make(chan error)


  return errorChannel


And then finally, I created the writer I was to import into the testing function like:

var writerToUse api.WriteApi = &FakeWriter{}