initwd Windows tests fixes (#1723)

Signed-off-by: eduzgun <emreduz00@gmail.com>
Signed-off-by: Emre Duzgun <100037959+eduzgun@users.noreply.github.com>
This commit is contained in:
Emre Duzgun 2024-06-18 15:49:30 +01:00 committed by GitHub
parent 3fdc809050
commit 502877dbf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 7 deletions

View File

@ -7,7 +7,7 @@ package configs
import ( import (
"fmt" "fmt"
"path" "path/filepath"
"sort" "sort"
"strings" "strings"
@ -64,8 +64,8 @@ func buildTestModules(root *Config, walker ModuleWalker) hcl.Diagnostics {
// - file: main.tftest.hcl, run: setup - test.main.setup // - file: main.tftest.hcl, run: setup - test.main.setup
// - file: tests/main.tftest.hcl, run: setup - test.tests.main.setup // - file: tests/main.tftest.hcl, run: setup - test.tests.main.setup
dir := path.Dir(name) dir := filepath.Dir(name)
base := path.Base(name) base := filepath.Base(name)
path := addrs.Module{} path := addrs.Module{}
path = append(path, "test") path = append(path, "test")
@ -73,7 +73,6 @@ func buildTestModules(root *Config, walker ModuleWalker) hcl.Diagnostics {
path = append(path, strings.Split(dir, "/")...) path = append(path, strings.Split(dir, "/")...)
} }
path = append(path, strings.TrimSuffix(base, ".tftest.hcl"), run.Name) path = append(path, strings.TrimSuffix(base, ".tftest.hcl"), run.Name)
req := ModuleRequest{ req := ModuleRequest{
Name: run.Name, Name: run.Name,
Path: path, Path: path,

View File

@ -9,6 +9,7 @@ import (
"context" "context"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"testing" "testing"
@ -281,6 +282,11 @@ func TestDirFromModule_rel_submodules(t *testing.T) {
} }
t.Cleanup(func() { t.Cleanup(func() {
os.Chdir(oldDir) os.Chdir(oldDir)
// Trigger garbage collection to ensure that all open file handles are closed.
// This prevents TempDir RemoveAll cleanup errors on Windows.
if runtime.GOOS == "windows" {
runtime.GC()
}
}) })
hooks := &testInstallHooks{} hooks := &testInstallHooks{}

View File

@ -61,7 +61,7 @@ func TestModuleInstaller(t *testing.T) {
Name: "Install", Name: "Install",
ModuleAddr: "child_a.child_b", ModuleAddr: "child_a.child_b",
PackageAddr: "", PackageAddr: "",
LocalPath: "child_a/child_b", LocalPath: filepath.Join("child_a", "child_b"),
}, },
} }
@ -393,7 +393,7 @@ func TestModuleInstaller_symlink(t *testing.T) {
Name: "Install", Name: "Install",
ModuleAddr: "child_a.child_b", ModuleAddr: "child_a.child_b",
PackageAddr: "", PackageAddr: "",
LocalPath: "child_a/child_b", LocalPath: filepath.Join("child_a", "child_b"),
}, },
} }
@ -764,7 +764,7 @@ func TestModuleInstaller_fromTests(t *testing.T) {
config, loadDiags := loader.LoadConfigWithTests(".", "tests") config, loadDiags := loader.LoadConfigWithTests(".", "tests")
assertNoDiagnostics(t, tfdiags.Diagnostics{}.Append(loadDiags)) assertNoDiagnostics(t, tfdiags.Diagnostics{}.Append(loadDiags))
if config.Module.Tests["tests/main.tftest.hcl"].Runs[0].ConfigUnderTest == nil { if config.Module.Tests[filepath.Join("tests", "main.tftest.hcl")].Runs[0].ConfigUnderTest == nil {
t.Fatalf("should have loaded config into the relevant run block but did not") t.Fatalf("should have loaded config into the relevant run block but did not")
} }
} }

View File

@ -180,5 +180,7 @@ func (m Manifest) WriteSnapshotToDir(dir string) error {
if err != nil { if err != nil {
return err return err
} }
defer w.Close()
return m.WriteSnapshot(w) return m.WriteSnapshot(w)
} }