Skip to content

Commit

Permalink
Add acc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorrison committed Aug 10, 2017
1 parent 5c41c3a commit 19a9697
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions kubernetes/resource_kubernetes_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"fmt"
"os"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -353,6 +354,31 @@ func TestAccKubernetesPod_with_empty_dir_volume(t *testing.T) {
})
}

func TestAccKubernetesPod_with_nodeSelector(t *testing.T) {
var conf api.Pod

podName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
imageName := "nginx:1.7.9"
region := os.Getenv("GOOGLE_REGION")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesPodDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesPodConfigNodeSelector(podName, imageName, region),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPodExists("kubernetes_pod.test", &conf),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.node_selector.%", "1"),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.node_selector.failure-domain.beta.kubernetes.io/region", region),
),
},
},
})
}

func testAccCheckKubernetesPodDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*kubernetes.Clientset)

Expand Down Expand Up @@ -796,3 +822,23 @@ resource "kubernetes_pod" "test" {
}
`, podName, imageName)
}

func testAccKubernetesPodConfigNodeSelector(podName, imageName, region string) string {
return fmt.Sprintf(`
resource "kubernetes_pod" "test" {
metadata {
name = "%s"
}
spec {
container {
image = "%s"
name = "containername"
}
node_selector {
"failure-domain.beta.kubernetes.io/region" = "%s"
}
}
}
`, podName, imageName, region)
}

0 comments on commit 19a9697

Please sign in to comment.