Giter Site home page Giter Site logo

nhatthm / testcontainers-go-registry Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 684 KB

Common Image Registry for Testcontainers-Go

License: MIT License

Makefile 11.58% Go 88.42%
go golang test test-integration testcontainers testcontainers-go testcontainers-go-contrib docker container image-registry

testcontainers-go-registry's Introduction

Testcontainers-Go Common Image Registry

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

Common Image Registry for Testcontainers-Go

Prerequisites

  • Go >= 1.21

Install

go get go.nhat.io/testcontainers-registry

Elasticsearch

package example

import (
	"context"

	es "go.nhat.io/testcontainers-registry/elasticsearch"
	testcontainers "go.nhat.io/testcontainers-extra"
)

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

func startElasticsearch() (testcontainers.Container, error) {
	return es.StartGenericContainer(context.Background())
}

Mongo

package example

import (
	"context"

	"go.nhat.io/testcontainers-registry/mongo"
	testcontainers "go.nhat.io/testcontainers-extra"
)

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

func startMongoDB() (testcontainers.Container, error) {
	return mongo.StartGenericContainer(context.Background(),
		mongo.RunMigrations(migrationSource, dbName),
	)
}

MySQL

package example

import (
	"context"

	"go.nhat.io/testcontainers-registry/mysql"
	testcontainers "go.nhat.io/testcontainers-extra"
)

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

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

Postgres

package example

import (
	"context"

	"go.nhat.io/testcontainers-registry/postgres"
	testcontainers "go.nhat.io/testcontainers-extra"
)

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

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

SQL Server

package example

import (
	"context"

	testcontainers "go.nhat.io/testcontainers-extra"
	"go.nhat.io/testcontainers-registry/mssql"
)

const (
	dbName          = "test"
	dbPassword      = "My!StrongPassword"
	migrationSource = "file://./resources/migrations/"
)

func startSQLServer() (testcontainers.Container, error) {
	return mssql.StartGenericContainer(context.Background(),
		dbName, dbPassword,
		mssql.RunMigrations(migrationSource),
	)
}

Options

Change Image Tag

package example

import (
	"context"

	"go.nhat.io/testcontainers-registry/postgres"
	testcontainers "go.nhat.io/testcontainers-extra"
)

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

func startPostgres() (testcontainers.Container, error) {
	return postgres.StartGenericContainer(context.Background(),
		dbName, dbUser, dbPassword,
		testcontainers.WithImageTag("13-alpine"),
	)
}

Change Image Name

package example

import (
	"context"

	testcontainers "go.nhat.io/testcontainers-extra"
	"go.nhat.io/testcontainers-registry/mysql"
)

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

func startMySQL() (testcontainers.Container, error) {
	return mysql.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

testcontainers-go-registry's People

Contributors

dependabot[bot] avatar nhatthm avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

testcontainers-go-registry's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.