Skip to content

Commit

Permalink
Add test case revealing issue #115 when adding data to a config map r…
Browse files Browse the repository at this point in the history
…esource that didn't have any
  • Loading branch information
pdecat committed Feb 12, 2018
1 parent 9744f20 commit 784924a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions kubernetes/resource_kubernetes_config_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ func TestAccKubernetesConfigMap_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesConfigMapDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesConfigMapConfig_nodata(name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesConfigMapExists("kubernetes_config_map.test", &conf),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.annotations.%", "2"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.annotations.TestAnnotationOne", "one"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.annotations.TestAnnotationTwo", "two"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"TestAnnotationOne": "one", "TestAnnotationTwo": "two"}),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.labels.%", "3"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.labels.TestLabelTwo", "two"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.labels.TestLabelThree", "three"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{"TestLabelOne": "one", "TestLabelTwo": "two", "TestLabelThree": "three"}),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("kubernetes_config_map.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_config_map.test", "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet("kubernetes_config_map.test", "metadata.0.self_link"),
resource.TestCheckResourceAttrSet("kubernetes_config_map.test", "metadata.0.uid"),
resource.TestCheckResourceAttr("kubernetes_config_map.test", "data.%", "0"),
),
},
{
Config: testAccKubernetesConfigMapConfig_basic(name),
Check: resource.ComposeAggregateTestCheckFunc(
Expand Down Expand Up @@ -224,6 +245,25 @@ func testAccCheckKubernetesConfigMapExists(n string, obj *api.ConfigMap) resourc
}
}

func testAccKubernetesConfigMapConfig_nodata(name string) string {
return fmt.Sprintf(`
resource "kubernetes_config_map" "test" {
metadata {
annotations {
TestAnnotationOne = "one"
TestAnnotationTwo = "two"
}
labels {
TestLabelOne = "one"
TestLabelTwo = "two"
TestLabelThree = "three"
}
name = "%s"
}
data {}
}`, name)
}

func testAccKubernetesConfigMapConfig_basic(name string) string {
return fmt.Sprintf(`
resource "kubernetes_config_map" "test" {
Expand Down

0 comments on commit 784924a

Please sign in to comment.