Automated tests for Rancher using Terraform + Terratest
Provisioning:
- AWS Node driver
- RKE1
- RKE2
- K3s
- Hosted
- AKS
Functions:
- CleanupConfigTF:
- parameters - (
module string
); - description - cleans main.tf of desired module
- parameters - (
- GetClusterID:
- parameters - (
url string
,clusterName string
,bearer token string
); returnsstring
- description - returns the cluster's id
- parameters - (
- GetClusterName:
- parameters - (
url string
,clusterID string
,bearer token string
); returnsstring
- description - returns the cluster's name
- parameters - (
- GetClusterNodeCount:
- parameters - (
url string
,clusterID string
,bearer token string
); returnsint
- description - returns the cluster's node count
- parameters - (
- GetClusterProvider:
- parameters - (
url string
,clusterID string
,bearer token string
); returnsstring
- description - returns the cluster's provider
- parameters - (
- GetClusterState:
- parameters - (
url string
,clusterID string
,bearer token string
); returnsstring
- description - returns the cluster's current state
- parameters - (
- GetKubernetesVersion:
- parameters - (
url string
,clusterID string
,bearer token string
); returnsstring
- description - returns the cluster's kubernetes version
- parameters - (
- GetRancherServerVersion:
- parameters - (
url string
,bearer token string
); returnsstring
- description - returns rancher's server version
- parameters - (
- GetUserID:
- parameters - (
url string
,bearer token string
); returnsstring
- description - returns admin user id
- parameters - (
- OutputToInt:
- parameters - (
output string
); returnsint
- description - returns tf output as type int
- note - tf outputs values as type string;
- parameters - (
- SetConfigTF:
- parameters - (
module string
,k8sVersion string
,nodepools []models.Nodepool
; returnsbool
- description - sets config of desired module and overwrites existing main.tf
- parameters - (
- WaitForActiveCluster:
- parameters - (
url string
,clusterName string
,bearer token string
) - description - waits until cluster is in an active state
- parameters - (
Testing:
- Create and export configuration specs in config.go, to later reference in tests
- Create a new _test.go file in the
tests
folder and begin writing a test
Note:
- Tests that timeout will not have cleaned up resources
- Extending the test timeout is a best practice; default is 10m
- To extend timeout, add
-timeout <int>m
when running tests- e.g.
go test <testfile>.go -timeout 45m
||go test <testfile>.go -timeout 1h
- e.g.