mysqltestcontainer

package
v0.0.0-...-e538546 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DB DbConfig
}

type DbConfig

type DbConfig struct {
	RootPassword string
	ExposedPorts []string
	Name         string
	Image        string
}

type DbInfo

type DbInfo struct {
	Username string
	Password string
	Ip       string
	Port     string
	DbName   string
}

type MySqlTestContainer

type MySqlTestContainer struct {
	// contains filtered or unexported fields
}

func Create

func Create(name string) (*MySqlTestContainer, error)

Create creates a container containing MySQL in Docker & returns the connection info along with the created database.

Example
package main

import (
	"github.com/andylongstaffe/go-mysql-test-container/mysqltestcontainer"
	"github.com/containerd/containerd/log"
)

func main() {
	mySql, _ := mysqltestcontainer.Create("test")
	db := mySql.GetDb()
	err := db.Ping()
	if err != nil {
		log.L.Errorln(err.Error())
	}
}
Output:

func CreateWithConfig

func CreateWithConfig(cfg Config) (*MySqlTestContainer, error)

CreateWithConfig creates a container containing MySQL in Docker & returns the connection info along with the created database. You are responsible for calling GetContainer().Terminate() to tear down the container since the reaper for testcontainers has been turned off

func CreateWithMigrate

func CreateWithMigrate(databaseName string, migrationURL string) (*MySqlTestContainer, error)

func (*MySqlTestContainer) GetContainer

func (m *MySqlTestContainer) GetContainer() testcontainers.Container

func (*MySqlTestContainer) GetDb

func (m *MySqlTestContainer) GetDb() *sql.DB

func (*MySqlTestContainer) GetDbInfo

func (m *MySqlTestContainer) GetDbInfo() *DbInfo

Directories

Path Synopsis
examples
gorm Module

Jump to

Keyboard shortcuts

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