Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix windows CI tests.
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <[email protected]>
i4ki committed Sep 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent cf8c727 commit 9fb2569
Showing 6 changed files with 30 additions and 31 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:
23 changes: 8 additions & 15 deletions e2etests/cloud/run_script_cloud_preview_test.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ package cloud_test

import (
"encoding/json"
"fmt"
"net/http"
"os"
"path/filepath"
@@ -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"
@@ -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"
@@ -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,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"
@@ -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{
9 changes: 5 additions & 4 deletions e2etests/core/run_sharing_test.go
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 6 additions & 5 deletions e2etests/core/run_test.go
Original file line number Diff line number Diff line change
@@ -2611,25 +2611,25 @@ func TestRunOutput(t *testing.T) {
for _, tc := range []testcase{
{
name: "run without eval",
runArgs: []string{HelperPath, "echo", "hello"},
runArgs: []string{"helper", "echo", "hello"},
want: RunExpected{
Stderr: "terramate: Entering stack in /stack" + "\n" +
fmt.Sprintf(`terramate: Executing command "%s echo hello"`, HelperPath) + "\n",
`terramate: Executing command "helper echo hello"` + "\n",
Stdout: "hello\n",
},
},
{
name: "run with eval",
runArgs: []string{"--eval", HelperPath, "echo", "${terramate.stack.name}"},
runArgs: []string{"--eval", "helper", "echo", "${terramate.stack.name}"},
want: RunExpected{
Stderr: "terramate: Entering stack in /stack" + "\n" +
fmt.Sprintf(`terramate: Executing command "%s echo stack"`, HelperPath) + "\n",
`terramate: Executing command "helper echo stack"` + "\n",
Stdout: "stack\n",
},
},
{
name: "run with eval with error",
runArgs: []string{"--eval", HelperPath, "echo", "${terramate.stack.abcabc}"},
runArgs: []string{"--eval", "helper", "echo", "${terramate.stack.abcabc}"},
want: RunExpected{
Stderr: "Error: unable to evaluate command" + "\n" +
`> <cmd arg>:1,19-26: eval expression: eval "${terramate.stack.abcabc}": This object does not have an attribute named "abcabc"` + ".\n",
@@ -2644,6 +2644,7 @@ func TestRunOutput(t *testing.T) {
git := s.Git()
git.CommitAll("first commit")
cli := NewCLI(t, s.RootDir())
cli.PrependToPath(filepath.Dir(HelperPath))
AssertRunResult(t,
cli.Run(append([]string{"run"}, tc.runArgs...)...),
tc.want,
8 changes: 8 additions & 0 deletions e2etests/internal/runner/setup.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 2 additions & 0 deletions makefiles/windows.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9fb2569

Please sign in to comment.