diff --git a/.circleci/config.yml b/.circleci/config.yml index e15b6a239..3d003e027 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,12 +14,11 @@ env: &env HELM_VERSION: v3.8.0 KUBECONFIG: /home/circleci/.kube/config BIN_BUILD_PARALLELISM: 3 - DOCKER_COMPOSE_VERSION: v2.5.0 defaults: &defaults machine: enabled: true - image: ubuntu-2004:202111-02 + image: ubuntu-2004:2022.10.1 <<: *env setup_minikube: &setup_minikube @@ -75,16 +74,6 @@ install_docker_buildx: &install_docker_buildx # Verify buildx is available docker buildx create --use -# Installation script for the docker compose plugin. See: https://docs.docker.com/compose/install/#install-compose-on-linux-systems -install_docker_compose: &install_docker_compose - name: install docker compose - command: | - curl -sLO https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64 - mkdir -p ~/.docker/cli-plugins - mv docker-compose-linux-x86_64 ~/.docker/cli-plugins/docker-compose - chmod a+x ~/.docker/cli-plugins/docker-compose - docker compose version - configure_environment_for_gcp: &configure_environment_for_gcp name: configure environment for gcp command: | @@ -180,8 +169,6 @@ jobs: <<: *install_gruntwork_utils - run: <<: *install_docker_buildx - - run: - <<: *install_docker_compose # The weird way you have to set PATH in Circle 2.0 - run: | diff --git a/modules/aws/s3.go b/modules/aws/s3.go index c8bf21992..56eddeca2 100644 --- a/modules/aws/s3.go +++ b/modules/aws/s3.go @@ -70,7 +70,7 @@ func GetS3BucketTags(t testing.TestingT, awsRegion string, bucket string) map[st return tags } -// GetS3BucketTagsE fetches the given bucket's tags and returns them as a string map of strings. +// GetS3BucketTagsE fetches the given bucket's tags and returns them as a string map of strings. func GetS3BucketTagsE(t testing.TestingT, awsRegion string, bucket string) (map[string]string, error) { s3Client, err := NewS3ClientE(t, awsRegion) if err != nil { diff --git a/modules/azure/mysql.go b/modules/azure/mysql.go index b73e2a299..5f447f448 100644 --- a/modules/azure/mysql.go +++ b/modules/azure/mysql.go @@ -82,7 +82,7 @@ func GetMYSQLDBClientE(subscriptionID string) (*mysql.DatabasesClient, error) { return &mysqlDBClient, nil } -//GetMYSQLDB is a helper function that gets the database. +// GetMYSQLDB is a helper function that gets the database. // This function would fail the test if there is an error. func GetMYSQLDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *mysql.Database { database, err := GetMYSQLDBE(t, subscriptionID, resGroupName, serverName, dbName) @@ -91,7 +91,7 @@ func GetMYSQLDB(t testing.TestingT, resGroupName string, serverName string, dbNa return database } -//GetMYSQLDBE is a helper function that gets the database. +// GetMYSQLDBE is a helper function that gets the database. func GetMYSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string, dbName string) (*mysql.Database, error) { // Create a mySQl db client mysqldbClient, err := GetMYSQLDBClientE(subscriptionID) @@ -109,7 +109,7 @@ func GetMYSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, return &mysqlDb, nil } -//ListMySQLDB is a helper function that gets all databases per server. +// ListMySQLDB is a helper function that gets all databases per server. func ListMySQLDB(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) []mysql.Database { dblist, err := ListMySQLDBE(t, subscriptionID, resGroupName, serverName) require.NoError(t, err) @@ -117,7 +117,7 @@ func ListMySQLDB(t testing.TestingT, resGroupName string, serverName string, sub return dblist } -//ListMySQLDBE is a helper function that gets all databases per server. +// ListMySQLDBE is a helper function that gets all databases per server. func ListMySQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) ([]mysql.Database, error) { // Create a mySQl db client mysqldbClient, err := GetMYSQLDBClientE(subscriptionID) diff --git a/modules/azure/postgresql.go b/modules/azure/postgresql.go index d9f3b47f9..dec69edb2 100644 --- a/modules/azure/postgresql.go +++ b/modules/azure/postgresql.go @@ -81,7 +81,7 @@ func GetPostgreSQLDBClientE(subscriptionID string) (*postgresql.DatabasesClient, return &postgresqlDBClient, nil } -//GetPostgreSQLDB is a helper function that gets the database. +// GetPostgreSQLDB is a helper function that gets the database. // This function would fail the test if there is an error. func GetPostgreSQLDB(t testing.TestingT, resGroupName string, serverName string, dbName string, subscriptionID string) *postgresql.Database { database, err := GetPostgreSQLDBE(t, subscriptionID, resGroupName, serverName, dbName) @@ -90,7 +90,7 @@ func GetPostgreSQLDB(t testing.TestingT, resGroupName string, serverName string, return database } -//GetPostgreSQLDBE is a helper function that gets the database. +// GetPostgreSQLDBE is a helper function that gets the database. func GetPostgreSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string, dbName string) (*postgresql.Database, error) { // Create a postgresql db client postgresqldbClient, err := GetPostgreSQLDBClientE(subscriptionID) @@ -108,7 +108,7 @@ func GetPostgreSQLDBE(t testing.TestingT, subscriptionID string, resGroupName st return &postgresqlDb, nil } -//ListPostgreSQLDB is a helper function that gets all databases per server. +// ListPostgreSQLDB is a helper function that gets all databases per server. func ListPostgreSQLDB(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) []postgresql.Database { dblist, err := ListPostgreSQLDBE(t, subscriptionID, resGroupName, serverName) require.NoError(t, err) @@ -116,7 +116,7 @@ func ListPostgreSQLDB(t testing.TestingT, subscriptionID string, resGroupName st return dblist } -//ListPostgreSQLDBE is a helper function that gets all databases per server. +// ListPostgreSQLDBE is a helper function that gets all databases per server. func ListPostgreSQLDBE(t testing.TestingT, subscriptionID string, resGroupName string, serverName string) ([]postgresql.Database, error) { // Create a postgresql db client postgresqldbClient, err := GetPostgreSQLDBClientE(subscriptionID) diff --git a/modules/azure/sql.go b/modules/azure/sql.go index b1e5992be..771c10803 100644 --- a/modules/azure/sql.go +++ b/modules/azure/sql.go @@ -83,7 +83,7 @@ func GetDatabaseClient(subscriptionID string) (*sql.DatabasesClient, error) { return &sqlDBClient, nil } -//ListSQLServerDatabases is a helper function that gets a list of databases on a sql server +// ListSQLServerDatabases is a helper function that gets a list of databases on a sql server func ListSQLServerDatabases(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) *[]sql.Database { dbList, err := ListSQLServerDatabasesE(t, resGroupName, serverName, subscriptionID) require.NoError(t, err) @@ -91,7 +91,7 @@ func ListSQLServerDatabases(t testing.TestingT, resGroupName string, serverName return dbList } -//ListSQLServerDatabasesE is a helper function that gets a list of databases on a sql server +// ListSQLServerDatabasesE is a helper function that gets a list of databases on a sql server func ListSQLServerDatabasesE(t testing.TestingT, resGroupName string, serverName string, subscriptionID string) (*[]sql.Database, error) { // Create a SQl db client sqlClient, err := CreateDatabaseClient(subscriptionID) diff --git a/modules/docker/docker_compose_test.go b/modules/docker/docker_compose_test.go index 56e79e2fa..b9799a356 100644 --- a/modules/docker/docker_compose_test.go +++ b/modules/docker/docker_compose_test.go @@ -1,8 +1,9 @@ package docker import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestDockerComposeWithBuildKit(t *testing.T) { diff --git a/modules/docker/inspect.go b/modules/docker/inspect.go index c507aa745..6d058d1b3 100644 --- a/modules/docker/inspect.go +++ b/modules/docker/inspect.go @@ -187,14 +187,15 @@ func transformContainer(t *testing.T, container inspectOutput) (*ContainerInspec } // transformContainerPorts converts Docker's ports from the following json into a more testable format -// { -// "80/tcp": [ -// { -// "HostIp": "" -// "HostPort": "8080" -// } -// ] -// } +// +// { +// "80/tcp": [ +// { +// "HostIp": "" +// "HostPort": "8080" +// } +// ] +// } func transformContainerPorts(container inspectOutput) ([]Port, error) { var ports []Port diff --git a/modules/k8s/service.go b/modules/k8s/service.go index c67f86509..fb50f0612 100644 --- a/modules/k8s/service.go +++ b/modules/k8s/service.go @@ -109,12 +109,12 @@ func GetServiceEndpoint(t testing.TestingT, options *KubectlOptions, service *co } // GetServiceEndpointE will return the service access point using the following logic: -// - For ClusterIP service type, return the URL that maps to ClusterIP and Service Port -// - For NodePort service type, identify the public IP of the node (if it exists, otherwise return the bound hostname), -// and the assigned node port for the provided service port, and return the URL that maps to node ip and node port. -// - For LoadBalancer service type, return the publicly accessible hostname of the load balancer. -// If the hostname is empty, it will return the public IP of the LoadBalancer. -// - All other service types are not supported. +// - For ClusterIP service type, return the URL that maps to ClusterIP and Service Port +// - For NodePort service type, identify the public IP of the node (if it exists, otherwise return the bound hostname), +// and the assigned node port for the provided service port, and return the URL that maps to node ip and node port. +// - For LoadBalancer service type, return the publicly accessible hostname of the load balancer. +// If the hostname is empty, it will return the public IP of the LoadBalancer. +// - All other service types are not supported. func GetServiceEndpointE(t testing.TestingT, options *KubectlOptions, service *corev1.Service, servicePort int) (string, error) { switch service.Spec.Type { case corev1.ServiceTypeClusterIP: diff --git a/modules/logger/logger.go b/modules/logger/logger.go index d290c6eee..5b544520e 100644 --- a/modules/logger/logger.go +++ b/modules/logger/logger.go @@ -108,16 +108,17 @@ func (_ terratestLogger) Logf(t testing.TestingT, format string, args ...interfa // immediately, rather than buffering all log output and only displaying it at the very end of the test. This is useful // because: // -// 1. It allows you to iterate faster locally, as you get feedback on whether your code changes are working as expected -// right away, rather than at the very end of the test run. +// 1. It allows you to iterate faster locally, as you get feedback on whether your code changes are working as expected +// right away, rather than at the very end of the test run. // -// 2. If you have a bug in your code that causes a test to never complete or if the test code crashes, t.Logf would -// show you no log output whatsoever, making debugging very hard, where as this method will show you all the log -// output available. +// 2. If you have a bug in your code that causes a test to never complete or if the test code crashes, t.Logf would +// show you no log output whatsoever, making debugging very hard, where as this method will show you all the log +// output available. +// +// 3. If you have a test that takes a long time to complete, some CI systems will kill the test suite prematurely +// because there is no log output with t.Logf (e.g., CircleCI kills tests after 10 minutes of no log output). With +// this log method, you get log output continuously. // -// 3. If you have a test that takes a long time to complete, some CI systems will kill the test suite prematurely -// because there is no log output with t.Logf (e.g., CircleCI kills tests after 10 minutes of no log output). With -// this log method, you get log output continuously. // Although t.Logf now supports streaming output since Go 1.14, this is kept for compatibility purposes. func Logf(t testing.TestingT, format string, args ...interface{}) { if tt, ok := t.(helper); ok { diff --git a/modules/logger/parser/failed_test_marker.go b/modules/logger/parser/failed_test_marker.go index e4821b710..f9f4dd305 100644 --- a/modules/logger/parser/failed_test_marker.go +++ b/modules/logger/parser/failed_test_marker.go @@ -4,8 +4,10 @@ package parser // TestResultMarker tracks the indentation level of a test result line in go test output. // Example: // --- FAIL: TestSnafu -// --- PASS: TestSnafu/Situation -// --- FAIL: TestSnafu/Normal +// +// --- PASS: TestSnafu/Situation +// --- FAIL: TestSnafu/Normal +// // The three markers for the above in order are: // TestResultMarker{TestName: "TestSnafu", IndentLevel: 0} // TestResultMarker{TestName: "TestSnafu/Situation", IndentLevel: 4} diff --git a/modules/logger/parser/parser.go b/modules/logger/parser/parser.go index 09692efec..fa78a10ad 100644 --- a/modules/logger/parser/parser.go +++ b/modules/logger/parser/parser.go @@ -47,8 +47,9 @@ var ( // getIndent takes a line and returns the indent string // Example: -// in: " --- FAIL: TestSnafu" -// out: " " +// +// in: " --- FAIL: TestSnafu" +// out: " " func getIndent(data string) string { re := regexp.MustCompile(`^\s+`) indent := re.FindString(data) @@ -57,8 +58,9 @@ func getIndent(data string) string { // getTestNameFromResultLine takes a go testing result line and extracts out the test name // Example: -// in: --- FAIL: TestSnafu -// out: TestSnafu +// +// in: --- FAIL: TestSnafu +// out: TestSnafu func getTestNameFromResultLine(text string) string { m := regexResult.FindStringSubmatch(text) return m[2] @@ -71,8 +73,9 @@ func isResultLine(text string) bool { // getTestNameFromStatusLine takes a go testing status line and extracts out the test name // Example: -// in: === RUN TestSnafu -// out: TestSnafu +// +// in: === RUN TestSnafu +// out: TestSnafu func getTestNameFromStatusLine(text string) string { m := regexStatus.FindStringSubmatch(text) return m[2] diff --git a/modules/opa/download_policy.go b/modules/opa/download_policy.go index b786a6f2b..c06d8ff9a 100644 --- a/modules/opa/download_policy.go +++ b/modules/opa/download_policy.go @@ -22,7 +22,9 @@ var ( // can be passed to opa. The temporary directory that is used is cached based on the go-getter base path, and reused // across calls. // For example, if you call DownloadPolicyE with the go-getter URL multiple times: -// git::https://github.com/gruntwork-io/terratest.git//policies/foo.rego?ref=master +// +// git::https://github.com/gruntwork-io/terratest.git//policies/foo.rego?ref=master +// // The first time the gruntwork-io/terratest repo will be downloaded to a new temp directory. All subsequent calls will // reuse that first temporary dir where the repo was cloned. This is preserved even if a different subdir is requested // later, e.g.: git::https://github.com/gruntwork-io/terratest.git//examples/bar.rego?ref=master. diff --git a/modules/opa/eval.go b/modules/opa/eval.go index e9e77689f..0d5de5beb 100644 --- a/modules/opa/eval.go +++ b/modules/opa/eval.go @@ -47,7 +47,9 @@ const ( ) // EvalE runs `opa eval` on the given JSON files using the configured policy file and result query. Translates to: -// opa eval -i $JSONFile -d $RulePath $ResultQuery +// +// opa eval -i $JSONFile -d $RulePath $ResultQuery +// // This will asynchronously run OPA on each file concurrently using goroutines. // This will fail the test if any one of the files failed. func Eval(t testing.TestingT, options *EvalOptions, jsonFilePaths []string, resultQuery string) { @@ -55,7 +57,9 @@ func Eval(t testing.TestingT, options *EvalOptions, jsonFilePaths []string, resu } // EvalE runs `opa eval` on the given JSON files using the configured policy file and result query. Translates to: -// opa eval -i $JSONFile -d $RulePath $ResultQuery +// +// opa eval -i $JSONFile -d $RulePath $ResultQuery +// // This will asynchronously run OPA on each file concurrently using goroutines. func EvalE(t testing.TestingT, options *EvalOptions, jsonFilePaths []string, resultQuery string) error { downloadedPolicyPath, err := DownloadPolicyE(t, options.RulePath) diff --git a/modules/packer/packer.go b/modules/packer/packer.go index 58439b796..8f11b4c4a 100644 --- a/modules/packer/packer.go +++ b/modules/packer/packer.go @@ -162,7 +162,6 @@ func BuildAmiE(t testing.TestingT, options *Options) (string, error) { // // 1456332887,amazon-ebs,artifact,0,id,us-east-1:ami-b481b3de // 1533742764,googlecompute,artifact,0,id,terratest-packer-example-2018-08-08t15-35-19z -// func extractArtifactID(packerLogOutput string) (string, error) { re := regexp.MustCompile(`.+artifact,\d+?,id,(?:.+?:|)(.+)`) matches := re.FindStringSubmatch(packerLogOutput) diff --git a/modules/terraform/format_test.go b/modules/terraform/format_test.go index acc3c1f06..3a2a325cb 100644 --- a/modules/terraform/format_test.go +++ b/modules/terraform/format_test.go @@ -127,16 +127,16 @@ func TestMapToHclString(t *testing.T) { // // We have a few unsatisfactory ways to solve this problem: // -// 1. Enforce iteration order. This is easy to do in other languages, where you have built-in sorted maps. In Go, no -// such map exists, and if you create a custom one, you can't use the range keyword on it -// (http://stackoverflow.com/a/35810932/483528). As a result, we'd have to modify our implementation code to take -// iteration order into account which is a totally unnecessary feature that increases complexity. -// 2. We could parse the output string and do an order-independent comparison. However, that adds a bunch of parsing -// logic into the test code which is a totally unnecessary feature that increases complexity. -// 3. We accept that Go is a shitty language and, if the test fails, we re-run it a bunch of times in the hope that, if -// the bug is caused by key ordering, we will randomly get the proper order in a future run. The code being tested -// here is tiny & fast, so doing a hundred retries is still sub millisecond, so while ugly, this provides a very -// simple solution. +// 1. Enforce iteration order. This is easy to do in other languages, where you have built-in sorted maps. In Go, no +// such map exists, and if you create a custom one, you can't use the range keyword on it +// (http://stackoverflow.com/a/35810932/483528). As a result, we'd have to modify our implementation code to take +// iteration order into account which is a totally unnecessary feature that increases complexity. +// 2. We could parse the output string and do an order-independent comparison. However, that adds a bunch of parsing +// logic into the test code which is a totally unnecessary feature that increases complexity. +// 3. We accept that Go is a shitty language and, if the test fails, we re-run it a bunch of times in the hope that, if +// the bug is caused by key ordering, we will randomly get the proper order in a future run. The code being tested +// here is tiny & fast, so doing a hundred retries is still sub millisecond, so while ugly, this provides a very +// simple solution. // // Isn't it great that Go's designers built features into the language to prevent bugs that now force every Go // developer to write thousands of lines of extra code like this, which is of course likely to contain bugs itself? diff --git a/modules/test-structure/test_structure.go b/modules/test-structure/test_structure.go index 93ebc4e9a..032716e6e 100644 --- a/modules/test-structure/test_structure.go +++ b/modules/test-structure/test_structure.go @@ -53,19 +53,19 @@ func SkipStageEnvVarSet() bool { // relative to the repo root. If your tests reside in the "/test" relative to the root, then you will use this as // follows: // -// // Root folder where terraform files should be (relative to the test folder) -// rootFolder := ".." +// // Root folder where terraform files should be (relative to the test folder) +// rootFolder := ".." // -// // Relative path to terraform module being tested from the root folder -// terraformFolderRelativeToRoot := "examples/terraform-aws-example" +// // Relative path to terraform module being tested from the root folder +// terraformFolderRelativeToRoot := "examples/terraform-aws-example" // -// // Copy the terraform folder to a temp folder -// tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) +// // Copy the terraform folder to a temp folder +// tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot) // -// // Make sure to use the temp test folder in the terraform options -// terraformOptions := &terraform.Options{ -// TerraformDir: tempTestFolder, -// } +// // Make sure to use the temp test folder in the terraform options +// terraformOptions := &terraform.Options{ +// TerraformDir: tempTestFolder, +// } // // Note that if any of the SKIP_ environment variables is set, we assume this is a test in the local dev where // there are no other concurrent tests running and we want to be able to cache test data between test stages, so in that @@ -84,23 +84,23 @@ func CopyTerraformFolderToTemp(t testing.TestingT, rootFolder string, terraformM // relative to the repo root. If your tests reside in the "/test" relative to the root, then you will use this as // follows: // -// // Destination for the copy of the files. In this example we are using the Azure Dev Ops variable -// // for the folder that is cleaned after each pipeline job. -// destRootFolder := os.Getenv("AGENT_TEMPDIRECTORY") +// // Destination for the copy of the files. In this example we are using the Azure Dev Ops variable +// // for the folder that is cleaned after each pipeline job. +// destRootFolder := os.Getenv("AGENT_TEMPDIRECTORY") // -// // Root folder where terraform files should be (relative to the test folder) -// rootFolder := ".." +// // Root folder where terraform files should be (relative to the test folder) +// rootFolder := ".." // -// // Relative path to terraform module being tested from the root folder -// terraformFolderRelativeToRoot := "examples/terraform-aws-example" +// // Relative path to terraform module being tested from the root folder +// terraformFolderRelativeToRoot := "examples/terraform-aws-example" // -// // Copy the terraform folder to a temp folder -// tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot, destRootFolder) +// // Copy the terraform folder to a temp folder +// tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot, destRootFolder) // -// // Make sure to use the temp test folder in the terraform options -// terraformOptions := &terraform.Options{ -// TerraformDir: tempTestFolder, -// } +// // Make sure to use the temp test folder in the terraform options +// terraformOptions := &terraform.Options{ +// TerraformDir: tempTestFolder, +// } // // Note that if any of the SKIP_ environment variables is set, we assume this is a test in the local dev where // there are no other concurrent tests running and we want to be able to cache test data between test stages, so in that diff --git a/modules/version-checker/version_checker.go b/modules/version-checker/version_checker.go index dba27a86b..a6ac4cca7 100644 --- a/modules/version-checker/version_checker.go +++ b/modules/version-checker/version_checker.go @@ -148,8 +148,8 @@ func extractVersionFromShellCommandOutput(output string) (string, error) { // It returns Error for ill-formatted version string and VersionMismatchErr for // minimum version check failure. // -// checkVersionConstraint(t, "1.2.31", ">= 1.2.0, < 2.0.0") - no error -// checkVersionConstraint(t, "1.0.31", ">= 1.2.0, < 2.0.0") - error +// checkVersionConstraint(t, "1.2.31", ">= 1.2.0, < 2.0.0") - no error +// checkVersionConstraint(t, "1.0.31", ">= 1.2.0, < 2.0.0") - error func checkVersionConstraint(actualVersionStr string, versionConstraintStr string) error { actualVersion, err := version.NewVersion(actualVersionStr) if err != nil {