Skip to content

takecy/gockertest

Repository files navigation

gockertest

Build Status Go Report Card


About

Run docker container in testing for golang.


Prepare

You should run docker on local.
Check this command.

$ docker version

If this command occurred error, you should install docker in your PC beforehand.
Install Docker

On CI

ex. travis
.travis.yml

language: go

go: 
    - tip

sudo: false

services:
    - docker # here

script:
    go test -v ./...

Usage in your test code

$ go get -u github.com/takecy/gockertest

for public registry. [see redis example](./example/redis/redis.go)
args := gockertest.Arguments{
    Ports: map[int]int{6379: 6379},
}
cli := gockertest.Run("redis:3.2-alpine", args)
defer cli.Cleanup()

for private registy with basic authentication.
see redis example

args := gockertest.Arguments{
    Ports:        map[int]int{6379: 6379},
    RequireLogin: true, // require basic authentication
    Login: gockertest.Login{
        User:     "yourname",          // change to your username
        Password: "pass",              // change to your password
        Registry: "registry.yours.io", // change to your registy domain
    },
}
cli := gockertest.Run("registry.yours.io/redis:3.2-alpine", args)
defer cli.Cleanup()

Supported options of docker run

  • --net
  • -p
  • --name
  • --rm
  • -d

Why not support --link ?

Because --link is legacy.
Official Docs
You should use network features.


Testing

$ make test

License

MIT