Skip to content

Commit

Permalink
test: fix windows CI tests.
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed Sep 27, 2024
1 parent cf8c727 commit 975324a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
23 changes: 8 additions & 15 deletions e2etests/cloud/run_script_cloud_preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package cloud_test

import (
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -72,22 +71,20 @@ 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",
}],
]
}
}
`,
TerraformTestPath,
),
`f:stack/main.tf:
resource "local_file" "foo" {
content = "test content"
Expand Down Expand Up @@ -129,22 +126,20 @@ 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",
}],
]
}
}
`,
TerraformTestPath,
),
`f:stack/main.tf:
resource "local_file" "foo" {
content = "test content"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -239,23 +234,21 @@ 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",
}],
]
}
}
`,
TerraformTestPath,
),
`f:stack/main.tf:
resource "local_file" "foo" {
content = "test content"
Expand Down Expand Up @@ -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{
Expand Down
9 changes: 5 additions & 4 deletions e2etests/core/run_sharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions e2etests/core/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2613,8 +2613,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",
},
},
Expand Down
8 changes: 8 additions & 0 deletions e2etests/internal/runner/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions makefiles/windows.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 975324a

Please sign in to comment.