Signed-off-by: Boris HUISGEN <bhuisgen@hbis.fr>
This commit is contained in:
Boris HUISGEN 2018-10-08 20:14:30 +02:00
parent 661b8580b8
commit a39c7a2825

View file

@ -613,6 +613,23 @@ func TestAccDockerContainer_multiple_ports(t *testing.T) {
})
}
func TestAccDockerContainer_nostart(t *testing.T) {
var c types.ContainerJSON
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDockerContainerNoStartConfig,
Check: resource.ComposeTestCheckFunc(
testAccContainerNotRunning("docker_container.foo", &c),
),
},
},
})
}
func testAccContainerRunning(n string, container *types.ContainerJSON) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
@ -645,6 +662,33 @@ func testAccContainerRunning(n string, container *types.ContainerJSON) resource.
}
}
func testAccContainerNotRunning(n string, container *types.ContainerJSON) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
containers, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
return err
}
for _, c := range containers {
if c.ID == rs.Primary.ID {
return fmt.Errorf("Container found: %s", rs.Primary.ID)
}
}
return nil
}
}
func testValueHigherEqualThan(name, key string, value int) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
@ -885,3 +929,16 @@ resource "docker_container" "foo" {
]
}
`
const testAccDockerContainerNoStartConfig = `
resource "docker_image" "foo" {
name = "nginx:latest"
keep_locally = true
}
resource "docker_container" "foo" {
name = "tf-test"
image = "nginx:latest"
start = false
must_run = false
}
`