testcontainersregistry

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 0 Imported by: 0

README

Testcontainers-Go Common Image Registry

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

Common Image Registry for Testcontainers-Go

Prerequisites

  • Go >= 1.16

Install

go get github.com/nhatthm/testcontainers-go-registry

MySQL

package example

import (
	"context"

	testcontainersmysql "github.com/nhatthm/testcontainers-go-registry/sql/mysql"
	testcontainers "github.com/nhatthm/testcontainers-go-extra"
)

const (
	dbName          = "test"
	dbUser          = "test"
	dbPassword      = "test"
	migrationSource = "file://./resources/migrations/"
)

func startMySQL() (testcontainers.Container, error) {
	return testcontainersmysql.StartGenericContainer(context.Background(),
		dbName, dbUser, dbPassword,
		testcontainersmysql.RunMigrations(migrationSource),
	)
}

Postgres

package example

import (
	"context"

	testcontainerspostgres "github.com/nhatthm/testcontainers-go-registry/sql/postgres"
	testcontainers "github.com/nhatthm/testcontainers-go-extra"
)

const (
	dbName          = "test"
	dbUser          = "test"
	dbPassword      = "test"
	migrationSource = "file://./resources/migrations/"
)

func startMySQL() (testcontainers.Container, error) {
	return testcontainerspostgres.StartGenericContainer(context.Background(),
		dbName, dbUser, dbPassword,
		testcontainerspostgres.RunMigrations(migrationSource),
	)
}

Options

Change Image Tag
package example

import (
	"context"

	testcontainerspostgres "github.com/nhatthm/testcontainers-go-registry/sql/postgres"
	testcontainers "github.com/nhatthm/testcontainers-go-extra"
)

const (
	dbName     = "test"
	dbUser     = "test"
	dbPassword = "test"
)

func startMySQL() (testcontainers.Container, error) {
	return testcontainerspostgres.StartGenericContainer(context.Background(),
		dbName, dbUser, dbPassword,
		testcontainers.WithImageTag("13-alpine"),
	)
}
Change Image Name
package example

import (
	"context"

	testcontainers "github.com/nhatthm/testcontainers-go-extra"
	testcontainersmysql "github.com/nhatthm/testcontainers-go-registry/sql/mysql"
)

const (
	dbName     = "test"
	dbUser     = "test"
	dbPassword = "test"
)

func startMySQL() (testcontainers.Container, error) {
	return testcontainersmysql.StartGenericContainer(context.Background(),
		dbName, dbUser, dbPassword,
		testcontainers.WithImageName("mariadb"),
		testcontainers.WithImageTag("10.7"),
	)
}

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this

Documentation

Overview

Package testcontainersregistry provides common container requests.

Directories

Path Synopsis
Package database provides common functions for database images.
Package database provides common functions for database images.
mongo
Package mongo provides setup for spinning up a mongodb container.
Package mongo provides setup for spinning up a mongodb container.
mysql
Package mysql provides setup for spinning up a mysql container.
Package mysql provides setup for spinning up a mysql container.
postgres
Package postgres provides setup for spinning up a postgres container.
Package postgres provides setup for spinning up a postgres container.
Package elasticsearch provides setup for spinning up an elasticsearch container.
Package elasticsearch provides setup for spinning up an elasticsearch container.

Jump to

Keyboard shortcuts

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