-
Notifications
You must be signed in to change notification settings - Fork 3
/
instances_test.go
40 lines (35 loc) · 1.15 KB
/
instances_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package getaredis
import (
"testing"
"time"
"github.com/fsouza/go-dockerclient"
"github.com/stretchr/testify/assert"
)
func getDockerClient() (*docker.Client, error) {
return docker.NewClient("unix:///var/run/docker.sock")
}
func forceRemoveContainer(ctx *context, id string) {
dockerClient, _ := getDockerClient()
dockerClient.RemoveContainer(docker.RemoveContainerOptions{
ID: id,
Force: true,
})
}
// TODO Add redis authentication check
func TestStartRedisInstance(t *testing.T) {
ctx, _ := Init("config.yml")
containerName := generateRandomString(20)
password := generateRandomString(20)
container, err := startRedisInstance(ctx, "unix:///var/run/docker.sock", containerName, password)
if !assert.NoError(t, err, "Starting docker container should not return an Error.") {
return
}
time.Sleep(time.Second)
dockerClient, _ := getDockerClient()
container, err = dockerClient.InspectContainer(containerName)
if !assert.True(t, container.State.Running, "Container Failed to start.") {
return
}
assert.NotEmpty(t, container.NetworkSettings.Ports["6379/tcp"], "Should have a port mapping for redis port")
forceRemoveContainer(ctx, container.ID)
}