Slide 42
Slide 42 text
package test
import (...)
// An example of how to test the Kubernetes resource config in examples/kubernetes-basic-example using Terratest.
func TestKubernetesBasicExample(t *testing.T) {
t.Parallel()
// Path to the Kubernetes resource config we will test
kubeResourcePath, err := filepath.Abs("../examples/kubernetes-basic-example/nginx-deployment.yml")
require.NoError(t, err)
options := k8s.NewKubectlOptions("", "")
namespaceName := fmt.Sprintf("kubernetes-basic-example-%s", strings.ToLower(random.UniqueId()))
k8s.CreateNamespace(t, options, namespaceName)
// Make sure we set the namespace on the options
options.Namespace = namespaceName
defer k8s.DeleteNamespace(t, options, namespaceName)
// At the end of the test, run `kubectl delete -f RESOURCE_CONFIG` to clean up any resources that were created.
defer k8s.KubectlDelete(t, options, kubeResourcePath)
// This will run `kubectl apply -f RESOURCE_CONFIG` and fail the test if there are any errors
k8s.KubectlApply(t, options, kubeResourcePath)
service := k8s.GetService(t, options, "nginx-service")
require.Equal(t, service.Name, "nginx-service")
}
Ladislav Prskavec - Teststack conference, 6. 6. 2019 42