mongotest

package
v1.223.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mongotest provides an ephemeral MongoDB for integration tests. It returns a ready-to-use *db.DB backed by a throwaway database that is dropped when the test ends.

The MongoDB is obtained in one of two ways, in order:

  • if PLEXAMS_TEST_MONGO_URI is set, that server is used (a uniquely named database is created on it and dropped afterwards) — handy for a locally running MongoDB or a CI service container;
  • otherwise a MongoDB testcontainer is started (needs a running Docker daemon).

If neither is available the test is skipped, so `go test ./...` stays green on machines without Docker or a test MongoDB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(t *testing.T) *db.DB

NewDB returns a *db.DB pointing at a fresh, uniquely named database on an ephemeral MongoDB. The database (and, for a container, the container) is cleaned up via t.Cleanup. The test is skipped when no MongoDB can be provided.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL