This repository was archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathservice_external_name_test.go
More file actions
72 lines (56 loc) · 2.67 KB
/
service_external_name_test.go
File metadata and controls
72 lines (56 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// +build acceptance
package acceptance
import (
"testing"
tfstatehelper "github.com/hashicorp/terraform-provider-kubernetes-alpha/test/helper/state"
)
// This test case tests a Service but also is a demonstration of some the assert functions
// available in the test helper
func TestKubernetesManifest_Service_ExternalName(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", "services", namespace, name)
}()
k8shelper.CreateNamespace(t, namespace)
defer k8shelper.DeleteNamespace(t, namespace)
tfvars := TFVARS{
"namespace": namespace,
"name": name,
}
tfconfig := loadTerraformConfig(t, "Service_ExternalName/service.tf", tfvars)
tf.RequireSetConfig(t, tfconfig)
tf.RequireInit(t)
tf.RequireApply(t)
k8shelper.AssertNamespacedResourceExists(t, "v1", "services", 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.selector.app": "test",
"kubernetes_manifest.test.object.spec.type": "ExternalName",
"kubernetes_manifest.test.object.spec.externalName": "terraform.kubernetes.test.com",
})
tfstate.AssertAttributeDoesNotExist(t, "kubernetes_manifest.test.object.spec.ports.0")
tfconfigModified := loadTerraformConfig(t, "Service_ExternalName/service_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.metadata.annotations.test": "1",
"kubernetes_manifest.test.object.metadata.labels.test": "2",
"kubernetes_manifest.test.object.spec.selector.app": "test",
"kubernetes_manifest.test.object.spec.type": "ExternalName",
"kubernetes_manifest.test.object.spec.externalName": "kubernetes-alpha.terraform.test.com",
})
tfstate.AssertAttributeLen(t, "kubernetes_manifest.test.object.metadata.labels", 1)
tfstate.AssertAttributeLen(t, "kubernetes_manifest.test.object.metadata.annotations", 1)
tfstate.AssertAttributeNotEmpty(t, "kubernetes_manifest.test.object.metadata.labels.test")
tfstate.AssertAttributeDoesNotExist(t, "kubernetes_manifest.test.spec")
}