envase

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2017 License: Apache-2.0 Imports: 4 Imported by: 1

README

envase

Envase means container, is a docker-invoker testing-helper for Go language

Why ?

Sometimes it is really hard to mock and test your code against the implementation of several engine like RDBMS (mysql, oracle, sql-server), fluentd, etc. So with the help of docker engine, we can test the real implementation of our code against the engine. For example: In MySQL if you want to make sure your query is working like expected.

Hopefully, this library will make testing easier.

Installation

go get github.com/arielizuardi/envase

Example

Start fluentd Container

ctx := context.Background()
dockerClient, err := client.NewEnvClient()
if err != nil {
    panic(err)
}

fluentdImage := `fluent/fluentd:v0.12.32`
fluentHost := `127.0.0.1`
containerPort := `24224`
exposedPort := `24224`
containerName := `fluent_test`

envConfig := []string{}

envConfig := []string{}
container := envase.NewDockerContainer(ctx, dockerClient, fluentdImage , fluentHost, containerPort, exposedPort, containerName, envConfig)

err := container.Start()

if err != nil {
    panic(err)
}
  

Start mysql Container

dockerClient, err := client.NewEnvClient()
if err != nil {
    panic(err)
}
   
envConfig := []string{
	"MYSQL_USER="your_user",
	"MYSQL_ROOT_PASSWORD="your_password",
	"MYSQL_DATABASE="your_database",
}

mysqlImage := `mysql:5.7`
mysqlHost := `127.0.0.1`
containerPort := `3306`
exposedPort := `33060` 
containerName := `mysql_test`
  
container := envase.NewDockerContainer(ctx, dockerClient, mysqlImage, mysqlHost, containerPort, exposedPort, containerName, envConfig)
  
if err != nil {
   panic(err)
}
Stop Your Container
err := container.Stop()
if err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerContract

type ContainerContract interface {
	Start() error
	Stop() error
}

ContainerContract defines container interface

func NewDefaultContainer

func NewDefaultContainer(imageProvider provider.ImageProvider, containerID string) ContainerContract

NewDefaultContainer returns new instance of default container

func NewDockerContainer

func NewDockerContainer(ctx context.Context, dockerClient *client.Client, imageName string, host string, containerPort string, exposedPort string, containerName string, envConfig []string) ContainerContract

NewDockerContainer returns new instance of dockerContainer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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