From 7ec1ea9f4e709d52c81d9d7ac4b691adb5ee3282 Mon Sep 17 00:00:00 2001 From: i4k Date: Fri, 27 Sep 2024 21:23:20 +0100 Subject: [PATCH] test: fix windows CI tests. Signed-off-by: i4k --- .../{ci-experimental.yml => ci-windows.yml} | 8 +------ .../cloud/run_script_cloud_preview_test.go | 23 +++++++------------ e2etests/core/run_sharing_test.go | 9 ++++---- e2etests/core/run_test.go | 21 ++++++++++++----- e2etests/internal/runner/setup.go | 8 +++++++ makefiles/windows.mk | 2 ++ 6 files changed, 39 insertions(+), 32 deletions(-) rename .github/workflows/{ci-experimental.yml => ci-windows.yml} (84%) diff --git a/.github/workflows/ci-experimental.yml b/.github/workflows/ci-windows.yml similarity index 84% rename from .github/workflows/ci-experimental.yml rename to .github/workflows/ci-windows.yml index abc3e67b87..e70c0215ea 100644 --- a/.github/workflows/ci-experimental.yml +++ b/.github/workflows/ci-windows.yml @@ -1,15 +1,9 @@ # Copyright 2023 Terramate GmbH # SPDX-License-Identifier: MPL-2.0 -name: ci-experimental +name: ci-windows on: push: - paths-ignore: - - 'docs/**' - - 'makefiles/**' - - '.github/**' - - '**/*.tm.hcl' - - '.tool-versions' jobs: build_test: diff --git a/e2etests/cloud/run_script_cloud_preview_test.go b/e2etests/cloud/run_script_cloud_preview_test.go index 34bf2bfad5..5f121ebdd1 100644 --- a/e2etests/cloud/run_script_cloud_preview_test.go +++ b/e2etests/cloud/run_script_cloud_preview_test.go @@ -5,7 +5,6 @@ package cloud_test import ( "encoding/json" - "fmt" "net/http" "os" "path/filepath" @@ -72,13 +71,13 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - fmt.Sprintf(`f:stack/preview.tm: + `f:stack/preview.tm: script "preview" { description = "sync a preview" job { commands = [ - ["%s", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { + ["terraform", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { sync_preview = true, terraform_plan_file = "out.tfplan", }], @@ -86,8 +85,6 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - TerraformTestPath, - ), `f:stack/main.tf: resource "local_file" "foo" { content = "test content" @@ -129,13 +126,13 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - fmt.Sprintf(`f:stack/preview.tm: + `f:stack/preview.tm: script "preview" { description = "sync a preview" job { commands = [ - ["%s", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { + ["terraform", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { sync_preview = true, terraform_plan_file = "out.tfplan", }], @@ -143,8 +140,6 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - TerraformTestPath, - ), `f:stack/main.tf: resource "local_file" "foo" { content = "test content" @@ -177,7 +172,7 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { { ID: "1", Status: "changed", - Cmd: []string{TerraformTestPath, "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode"}, + Cmd: []string{"terraform", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode"}, }, }, ReviewRequest: &cloud.ReviewRequest{ @@ -239,14 +234,14 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - fmt.Sprintf(`f:stack/preview.tm: + `f:stack/preview.tm: script "preview" { description = "sync a preview" job { commands = [ ["do-not-exist-command"], - ["%s", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { + ["terraform", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode", { sync_preview = true, terraform_plan_file = "out.tfplan", }], @@ -254,8 +249,6 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { } } `, - TerraformTestPath, - ), `f:stack/main.tf: resource "local_file" "foo" { content = "test content" @@ -285,7 +278,7 @@ func TestScriptRunWithCloudSyncPreview(t *testing.T) { { ID: "1", Status: "failed", - Cmd: []string{TerraformTestPath, "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode"}, + Cmd: []string{"terraform", "plan", "-out=out.tfplan", "-no-color", "-detailed-exitcode"}, }, }, ReviewRequest: &cloud.ReviewRequest{ diff --git a/e2etests/core/run_sharing_test.go b/e2etests/core/run_sharing_test.go index eb818d524c..aee4ac36eb 100644 --- a/e2etests/core/run_sharing_test.go +++ b/e2etests/core/run_sharing_test.go @@ -274,7 +274,7 @@ func TestRunSharing(t *testing.T) { Labels("name"), Expr("type", "terraform"), Str("filename", "sharing.tf"), - Command(HelperPath, "exit", "1"), + Command("helper", "exit", "1"), ).String(), "s:s1:id=s1", "f:s1/main.tf:" + Doc( @@ -335,7 +335,7 @@ func TestRunSharing(t *testing.T) { Labels("name"), Expr("type", "terraform"), Str("filename", "sharing.tf"), - Command(HelperPath, "echo", "{}"), + Command("helper", "echo", "{}"), ).String(), "s:s1:id=s1", "f:s1/main.tf:" + Doc( @@ -402,7 +402,7 @@ func TestRunSharing(t *testing.T) { Labels("name"), Expr("type", "terraform"), Str("filename", "sharing.tf"), - Command(HelperPath, "echo", "$error"), + Command("helper", "echo", "$error"), ).String(), "s:s1:id=s1", "f:s1/main.tf:" + Doc( @@ -503,7 +503,8 @@ func TestRunSharing(t *testing.T) { s.BuildTree(layout) tmcli := NewCLI(t, s.RootDir()) tmcli.PrependToPath(filepath.Dir(TerraformTestPath)) - res := tmcli.Run("run", HelperPath, "echo", "hello") + tmcli.PrependToPath(filepath.Dir(HelperPath)) + res := tmcli.Run("run", "helper", "echo", "hello") if res.Status == 0 { // generate safeguard must trigger t.Fatal("run must fail if sharing is not generated") diff --git a/e2etests/core/run_test.go b/e2etests/core/run_test.go index 507451e87e..e731eab615 100644 --- a/e2etests/core/run_test.go +++ b/e2etests/core/run_test.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "runtime" "sort" "strings" @@ -2613,8 +2614,8 @@ func TestRunOutput(t *testing.T) { name: "run without eval", runArgs: []string{HelperPath, "echo", "hello"}, want: RunExpected{ - Stderr: "terramate: Entering stack in /stack" + "\n" + - fmt.Sprintf(`terramate: Executing command "%s echo hello"`, HelperPath) + "\n", + StderrRegex: "terramate: Entering stack in /stack" + "\n" + + `terramate: Executing command ".*? echo hello"` + "\n", Stdout: "hello\n", }, }, @@ -2667,8 +2668,12 @@ func TestRunDryRun(t *testing.T) { name: "dryrun without eval", runArgs: []string{"--dry-run", HelperPath, "echo", "hello"}, want: RunExpected{ - Stderr: "terramate: (dry-run) Entering stack in /stack" + "\n" + - fmt.Sprintf(`terramate: (dry-run) Executing command "%s echo hello"`, HelperPath) + "\n", + StderrRegexes: []string{ + regexp.QuoteMeta("terramate: (dry-run) Entering stack in /stack" + "\n" + + `terramate: (dry-run) Executing command "`, + ), + regexp.QuoteMeta(`echo hello"`), + }, Stdout: "", }, }, @@ -2676,8 +2681,12 @@ func TestRunDryRun(t *testing.T) { name: "dryrun with eval", runArgs: []string{"--dry-run", "--eval", HelperPath, "echo", "${terramate.stack.name}"}, want: RunExpected{ - Stderr: "terramate: (dry-run) Entering stack in /stack" + "\n" + - fmt.Sprintf(`terramate: (dry-run) Executing command "%s echo stack"`, HelperPath) + "\n", + StderrRegexes: []string{ + regexp.QuoteMeta("terramate: (dry-run) Entering stack in /stack" + "\n" + + `terramate: (dry-run) Executing command "`, + ), + regexp.QuoteMeta(`echo stack"`), + }, Stdout: "", }, }, diff --git a/e2etests/internal/runner/setup.go b/e2etests/internal/runner/setup.go index fb192b3a12..f6bd113e82 100644 --- a/e2etests/internal/runner/setup.go +++ b/e2etests/internal/runner/setup.go @@ -23,6 +23,10 @@ var TerraformVersion string // TerraformTestPath is the path to the installed terraform binary. var TerraformTestPath string +// TerraformTestPathAsHCL is the path to the installed terraform binary +// but suited for including in an HCL string expression. +var TerraformTestPathAsHCL string + var terraformCleanup func() // HelperPath is the path to the test binary we compiled for test purposes @@ -64,6 +68,10 @@ func Setup(projectRoot string) (err error) { err = errors.E(err, "failed to setup Terraform binary") return } + TerraformTestPathAsHCL = fmt.Sprintf(`${tm_chomp(<<-EOF + %s + EOF + )}`, TerraformTestPath) }) if err == nil { diff --git a/makefiles/windows.mk b/makefiles/windows.mk index 157e2f13f6..968dcd17a2 100644 --- a/makefiles/windows.mk +++ b/makefiles/windows.mk @@ -34,8 +34,10 @@ tempdir=$(shell .\bin\helper.exe tempdir) test: test/helper build set TM_TEST_ROOT_TEMPDIR=$(tempdir) go test -timeout 30m -p 100 ./... + set status=%errorlevel% .\bin\helper.exe rm $(tempdir) .\bin\terramate.exe run -- helper.exe true + exit %status% ## remove build artifacts .PHONY: clean