Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Add more test coverage of basic resources #219

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/acceptance/cronjob_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_CronJob(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t, "batch/v1beta1", "cronjobs", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "CronJob/cronjob.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t, "batch/v1beta1", "cronjobs", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,

"kubernetes_manifest.test.object.spec.schedule": "0 * * * *",
"kubernetes_manifest.test.object.spec.jobTemplate.spec.template.spec.containers.0.name": "busybox",
"kubernetes_manifest.test.object.spec.jobTemplate.spec.template.spec.containers.0.image": "busybox",
"kubernetes_manifest.test.object.spec.jobTemplate.spec.template.spec.containers.0.command": []interface{}{"sleep", "30"},
"kubernetes_manifest.test.object.spec.jobTemplate.spec.template.spec.restartPolicy": "Never",
})
}
45 changes: 45 additions & 0 deletions test/acceptance/daemonset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_DaemonSet(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t, "apps/v1", "daemonsets", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "DaemonSet/daemonset.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t, "apps/v1", "daemonsets", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,
"kubernetes_manifest.test.object.spec.template.spec.containers.0.name": "nginx",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.image": "nginx:1",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.ports.0.containerPort": "80",
})
}
78 changes: 78 additions & 0 deletions test/acceptance/hpa_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_HPA(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t,
"autoscaling/v2beta2", "horizontalpodautoscalers", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "HPA/hpa.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t,
"autoscaling/v2beta2", "horizontalpodautoscalers", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,

"kubernetes_manifest.test.object.spec.scaleTargetRef.apiVersion": "apps/v1",
"kubernetes_manifest.test.object.spec.scaleTargetRef.kind": "Deployment",
"kubernetes_manifest.test.object.spec.scaleTargetRef.name": "nginx",

"kubernetes_manifest.test.object.spec.maxReplicas": "10",
"kubernetes_manifest.test.object.spec.minReplicas": "1",

"kubernetes_manifest.test.object.spec.metrics.0.type": "Resource",
"kubernetes_manifest.test.object.spec.metrics.0.resource.name": "cpu",
"kubernetes_manifest.test.object.spec.metrics.0.resource.target.type": "Utilization",
"kubernetes_manifest.test.object.spec.metrics.0.resource.target.averageUtilization": "50",
})

tfconfigModified := loadTerraformConfig(t, "HPA/hpa_modified.tf", tfvars)
tf.RequireSetConfig(t, tfconfigModified)
tf.RequireApply(t)

tfstate = tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,

"kubernetes_manifest.test.object.spec.scaleTargetRef.apiVersion": "apps/v1",
"kubernetes_manifest.test.object.spec.scaleTargetRef.kind": "Deployment",
"kubernetes_manifest.test.object.spec.scaleTargetRef.name": "nginx",

"kubernetes_manifest.test.object.spec.maxReplicas": "20",
"kubernetes_manifest.test.object.spec.minReplicas": "1",

"kubernetes_manifest.test.object.spec.metrics.0.type": "Resource",
"kubernetes_manifest.test.object.spec.metrics.0.resource.name": "cpu",
"kubernetes_manifest.test.object.spec.metrics.0.resource.target.type": "Utilization",
"kubernetes_manifest.test.object.spec.metrics.0.resource.target.averageUtilization": "65",
})
}
46 changes: 46 additions & 0 deletions test/acceptance/job_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_Job(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t, "batch/v1", "jobs", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "Job/job.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t, "batch/v1", "jobs", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,
"kubernetes_manifest.test.object.spec.template.spec.containers.0.name": "busybox",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.image": "busybox",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.command": []interface{}{"sleep", "30"},
"kubernetes_manifest.test.object.spec.template.spec.restartPolicy": "Never",
})
}
46 changes: 46 additions & 0 deletions test/acceptance/namespace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_Namespace(t *testing.T) {
name := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertResourceDoesNotExist(t, "v1", "namespaces", name)
}()

tfvars := TFVARS{
"name": name,
}
tfconfig := loadTerraformConfig(t, "Namespace/namespace.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertResourceExists(t, "v1", "namespaces", name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.name": name,
})

tfconfigModified := loadTerraformConfig(t, "Namespace/namespace_modified.tf", tfvars)
tf.RequireSetConfig(t, tfconfigModified)
tf.RequireApply(t)

tfstate = tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.name": name,
"kubernetes_manifest.test.object.metadata.labels.test": "test",
})
}
45 changes: 45 additions & 0 deletions test/acceptance/secret_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_Secret(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t, "v1", "secrets", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "Secret/secret.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t, "v1", "secrets", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,

"kubernetes_manifest.test.object.data.PGUSER": "username",
"kubernetes_manifest.test.object.data.PGPASSWORD": "password",
})
}
58 changes: 58 additions & 0 deletions test/acceptance/statefulset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// +build acceptance

package acceptance

import (
"testing"

tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)

func TestKubernetesManifest_StatefulSet(t *testing.T) {
name := randName()
namespace := randName()

tf := tfhelper.RequireNewWorkingDir(t)
tf.SetReattachInfo(reattachInfo)
defer func() {
tf.RequireDestroy(t)
tf.Close()
k8shelper.AssertNamespacedResourceDoesNotExist(t, "apps/v1", "statefulsets", namespace, name)
}()

k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)

tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "StatefulSet/statefulset.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)

k8shelper.AssertNamespacedResourceExists(t, "apps/v1", "statefulsets", namespace, name)

tfstate := tfstatehelper.NewHelper(tf.RequireState(t))
tfstate.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.metadata.name": name,

"kubernetes_manifest.test.object.spec.replicas": "2",
"kubernetes_manifest.test.object.spec.selector.matchLabels.app": "nginx",

"kubernetes_manifest.test.object.spec.template.spec.containers.0.name": "nginx",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.image": "nginx:1",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.ports.0.containerPort": "80",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.ports.0.name": "web",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.volumeMounts.0.name": "www",
"kubernetes_manifest.test.object.spec.template.spec.containers.0.volumeMounts.0.mountPath": "/usr/share/nginx/html",

"kubernetes_manifest.test.object.spec.volumeClaimTemplates.0.metadata.name": "www",
"kubernetes_manifest.test.object.spec.volumeClaimTemplates.0.spec.accessModes.0": "ReadWriteOnce",
"kubernetes_manifest.test.object.spec.volumeClaimTemplates.0.spec.resources.requests.storage": "1Gi",
})

tfstate.AssertAttributeExists(t, "kubernetes_manifest.test.object.spec.serviceName")
}
Loading