Skip to content

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

License

Notifications You must be signed in to change notification settings

arielizuardi/envase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

Note on using Glide, because github.com/docker/docker change to moby/moby

Add this to your glide.yml file

- package: github.com/docker/docker
  version: v17.05.0-ce-rc3
  subpackages:
  - client