Skip to content

Commit

Permalink
Add test case revealing issue hashicorp#115 when add adding labels to…
Browse files Browse the repository at this point in the history
… a resource that didn't have any
  • Loading branch information
pdecat committed Feb 12, 2018
1 parent fe29856 commit 220ec3b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kubernetes/resource_kubernetes_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ func TestAccKubernetesNamespace_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccKubernetesNamespaceConfig_basic(nsName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesNamespaceExists("kubernetes_namespace.test", &conf),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.annotations.%", "2"),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.annotations.TestAnnotationOne", "one"),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.annotations.TestAnnotationTwo", "two"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"TestAnnotationOne": "one", "TestAnnotationTwo": "two"}),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.labels.%", "0"),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.name", nsName),
resource.TestCheckResourceAttrSet("kubernetes_namespace.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_namespace.test", "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet("kubernetes_namespace.test", "metadata.0.self_link"),
resource.TestCheckResourceAttrSet("kubernetes_namespace.test", "metadata.0.uid"),
),
},
{
Config: testAccKubernetesNamespaceConfig_addLabels(nsName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesNamespaceExists("kubernetes_namespace.test", &conf),
resource.TestCheckResourceAttr("kubernetes_namespace.test", "metadata.0.annotations.%", "2"),
Expand Down Expand Up @@ -260,6 +276,19 @@ func testAccCheckKubernetesNamespaceExists(n string, obj *api.Namespace) resourc

func testAccKubernetesNamespaceConfig_basic(nsName string) string {
return fmt.Sprintf(`
resource "kubernetes_namespace" "test" {
metadata {
annotations {
TestAnnotationOne = "one"
TestAnnotationTwo = "two"
}
name = "%s"
}
}`, nsName)
}

func testAccKubernetesNamespaceConfig_addLabels(nsName string) string {
return fmt.Sprintf(`
resource "kubernetes_namespace" "test" {
metadata {
annotations {
Expand Down

0 comments on commit 220ec3b

Please # to comment.