terraform-provider-docker/docker/resource_docker_config_test.go
Suzuki Shunsuke f213e3a348 style: format with gofumpt
https://github.com/mvdan/gofumpt

```
$ gofumpt -l -s -w docker/*
```
2020-12-12 19:26:11 +09:00

105 lines
2.6 KiB
Go

package docker
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
func TestAccDockerConfig_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckDockerConfigDestroy,
Steps: []resource.TestStep{
{
Config: `
resource "docker_config" "foo" {
name = "foo-config"
data = "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("docker_config.foo", "name", "foo-config"),
resource.TestCheckResourceAttr("docker_config.foo", "data", "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="),
),
},
{
ResourceName: "docker_config.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccDockerConfig_basicUpdatable(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckDockerConfigDestroy,
Steps: []resource.TestStep{
{
Config: `
resource "docker_config" "foo" {
name = "tftest-myconfig-${replace(timestamp(),":", ".")}"
data = "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="
lifecycle {
ignore_changes = ["name"]
create_before_destroy = true
}
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("docker_config.foo", "data", "Ymxhc2RzYmxhYmxhMTI0ZHNkd2VzZA=="),
),
},
{
Config: `
resource "docker_config" "foo" {
name = "tftest-myconfig2-${replace(timestamp(),":", ".")}"
data = "U3VuIDI1IE1hciAyMDE4IDE0OjQ2OjE5IENFU1QK"
lifecycle {
ignore_changes = ["name"]
create_before_destroy = true
}
}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("docker_config.foo", "data", "U3VuIDI1IE1hciAyMDE4IDE0OjQ2OjE5IENFU1QK"),
),
},
{
ResourceName: "docker_config.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
/////////////
// Helpers
/////////////
func testCheckDockerConfigDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ProviderConfig).DockerClient
for _, rs := range s.RootModule().Resources {
if rs.Type != "configs" {
continue
}
id := rs.Primary.Attributes["id"]
_, _, err := client.ConfigInspectWithRaw(context.Background(), id)
if err == nil {
return fmt.Errorf("Config with id '%s' still exists", id)
}
return nil
}
return nil
}