From 784924a10d9a1006f51809edaaf199f6c04bade2 Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Mon, 12 Feb 2018 23:18:46 +0100 Subject: [PATCH] Add test case revealing issue #115 when adding data to a config map resource that didn't have any --- .../resource_kubernetes_config_map_test.go | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/kubernetes/resource_kubernetes_config_map_test.go b/kubernetes/resource_kubernetes_config_map_test.go index c11d2e374f..f02ab43355 100644 --- a/kubernetes/resource_kubernetes_config_map_test.go +++ b/kubernetes/resource_kubernetes_config_map_test.go @@ -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( @@ -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" {