Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix formatting and imports #1202

Merged
merged 2 commits into from
Nov 18, 2022
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
15 changes: 1 addition & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion modules/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions modules/azure/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -109,15 +109,15 @@ 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)

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)
Expand Down
8 changes: 4 additions & 4 deletions modules/azure/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -108,15 +108,15 @@ 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)

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)
Expand Down
4 changes: 2 additions & 2 deletions modules/azure/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ 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)

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)
Expand Down
3 changes: 2 additions & 1 deletion modules/docker/docker_compose_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package docker

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestDockerComposeWithBuildKit(t *testing.T) {
Expand Down
17 changes: 9 additions & 8 deletions modules/docker/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions modules/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 9 additions & 8 deletions modules/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions modules/logger/parser/failed_test_marker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
15 changes: 9 additions & 6 deletions modules/logger/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand All @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion modules/opa/download_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions modules/opa/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ 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) {
require.NoError(t, EvalE(t, options, jsonFilePaths, resultQuery))
}

// 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)
Expand Down
1 change: 0 additions & 1 deletion modules/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions modules/terraform/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Loading