Skip to content

Commit

Permalink
Merge pull request #68 from getamis/link-and-entrypoint-option
Browse files Browse the repository at this point in the history
test: add DB link and entrypoint option
  • Loading branch information
markya0616 authored Apr 23, 2019
2 parents 49919f4 + bc5adc7 commit c777fa0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ type Container struct {
exposedPorts map[docker.Port]struct{}

ports []string
entrypoint []string
runArgs []string
envs []string
links []string
container *docker.Container
healthChecker ContainerCallback
initializer ContainerCallback
Expand Down Expand Up @@ -66,6 +68,7 @@ func NewDockerContainer(opts ...Option) *Container {
healthChecker: func(c *Container) error {
return nil
},
links: []string{},
}

for _, opt := range opts {
Expand All @@ -84,12 +87,14 @@ func NewDockerContainer(opts ...Option) *Container {
Name: c.name + generateNameSuffix(),
Config: &docker.Config{
Image: c.imageRespository + ":" + c.imageTag,
Entrypoint: c.entrypoint,
Cmd: c.runArgs,
ExposedPorts: c.exposedPorts,
Env: c.envs,
},
HostConfig: &docker.HostConfig{
PortBindings: c.portBindings,
Links: c.links,
},
Context: context.TODO(),
})
Expand Down
16 changes: 16 additions & 0 deletions test/docker_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func Ports(ports ...int) Option {
}
}

func Entrypoint(entrypoint []string) Option {
return func(c *Container) {
c.entrypoint = entrypoint
}
}

func RunOptions(args []string) Option {
return func(c *Container) {
c.runArgs = args
Expand All @@ -95,6 +101,16 @@ func DockerEnv(env []string) Option {
}
}

func DockerRunLink(link string) Option {
return func(c *Container) {
if c.links == nil {
c.links = []string{link}
} else {
c.links = append(c.links, link)
}
}
}

func HealthChecker(checker ContainerCallback) Option {
return func(c *Container) {
c.healthChecker = checker
Expand Down
6 changes: 6 additions & 0 deletions test/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type MigrationOptions struct {
// this command will override the default command.
// "bundle" "exec" "rake" "db:migrate"
Command []string
// override default entrypoint
Entrypoint []string
}

// RunMigrationContainer creates the migration container and connects to the
Expand Down Expand Up @@ -67,6 +69,8 @@ func RunMigrationContainer(dbContainer *SQLContainer, options MigrationOptions)
},
),
RunOptions(command),
DockerRunLink(dbContainer.container.ID+":DB"),
Entrypoint(options.Entrypoint),
)

if err := container.Start(); err != nil {
Expand Down Expand Up @@ -128,6 +132,8 @@ func RunGoMigrationContainer(dbContainer *SQLContainer, options MigrationOptions
ImageRepository(options.ImageRepository),
ImageTag(options.ImageTag),
RunOptions(command),
DockerRunLink(dbContainer.container.ID+":DB"),
Entrypoint(options.Entrypoint),
)

if err := container.Start(); err != nil {
Expand Down

0 comments on commit c777fa0

Please sign in to comment.