RSSAmplifier

kubuzetto's blog · Jun 17, 2025

Implementing MongoDB Test Fixtures in Go

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

Introduction At some point in the recent past; I needed to port the integration tests of a Go service using PostgreSQL to MongoDB. I was surprised by the lack of resources for loading test fixtures, so I decided to document my approach here. For PostgreSQL, we use go-testfixtures to describe our test data as .yml files, which (naturally) does not support MongoDB. I wanted a similar approach for…

Introduction

At some point in the recent past; I needed to port the integration tests of a Go service using PostgreSQL to MongoDB. I was surprised by the lack of resources for loading test fixtures, so I decided to document my approach here.

For PostgreSQL, we use go-testfixtures to describe our test data as .yml files, which (naturally) does not support MongoDB. I wanted a similar approach for MongoDB.

Test fixtures

In Ruby on Rails, applications with database access are tested using test fixtures described in YAML files. Before the test, each table is populated with the data described in the corresponding YAML file:

Read on /posts/go-mongo-fixtures/

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.