Skip to content

Commit 85472c0

Browse files
committed
Parameterize service infra test code for container image tag
Using the latest commit hash should generally be correct, especially in the CI environment, but there are situations where it's nice to be able to specify which version of the service to deploy. Also extract out the environment name being used, for code clarity.
1 parent 7b26ec0 commit 85472c0

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ infra-format: ## Format infra code
272272

273273
infra-test-service: ## Run service layer infra test suite
274274
@:$(call check_defined, APP_NAME, "the name of subdirectory of /infra that holds the application's infrastructure code")
275-
cd infra/test && APP_NAME=$(APP_NAME) go test -run TestService -v -timeout 30m
275+
cd infra/test && APP_NAME=$(APP_NAME) IMAGE_TAG=$(IMAGE_TAG) go test -run TestService -v -timeout 30m
276276

277277
#############
278278
## Linting ##

infra/test/infra_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,21 @@ import (
2323
var uniqueId = strings.ToLower(generateTestId())
2424
var workspaceName = fmt.Sprintf("t-%s", uniqueId)
2525
var testAppName = os.Getenv("APP_NAME")
26+
var imageTag = os.Getenv("IMAGE_TAG")
27+
var environmentName = "dev"
2628

2729
func TestService(t *testing.T) {
28-
imageTag := shell.RunCommandAndGetOutput(t, shell.Command{
29-
Command: "git",
30-
Args: []string{"rev-parse", "HEAD"},
31-
WorkingDir: "./",
32-
})
3330
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
3431
Reconfigure: true,
3532
TerraformDir: fmt.Sprintf("../%s/service/", testAppName),
3633
Vars: map[string]interface{}{
37-
"environment_name": "dev",
34+
"environment_name": environmentName,
3835
"image_tag": imageTag,
3936
},
4037
})
4138

4239
fmt.Println("::group::Initialize service module")
43-
TerraformInit(t, terraformOptions, "dev.s3.tfbackend")
40+
TerraformInit(t, terraformOptions, fmt.Sprintf("%s.s3.tfbackend", environmentName))
4441
fmt.Println("::endgroup::")
4542

4643
defer terraform.WorkspaceDelete(t, terraformOptions, workspaceName)
@@ -60,7 +57,6 @@ func TestService(t *testing.T) {
6057
func WaitForServiceToBeStable(t *testing.T, workspaceName string) {
6158
fmt.Println("::group::Wait for service to be stable")
6259
appName := testAppName
63-
environmentName := "dev"
6460
serviceName := fmt.Sprintf("%s-%s-%s", workspaceName, appName, environmentName)
6561
shell.RunCommand(t, shell.Command{
6662
Command: "aws",

0 commit comments

Comments
 (0)