From 9b14212207bd2bc0dce93a20e9832644584b821e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Di=C3=B3genes=20Fernandes?= Date: Tue, 16 Sep 2025 15:29:31 -0300 Subject: [PATCH] fix: `internal/getprovider` tests on Windows (#3275) Signed-off-by: Diogenes Fernandes --- .gitattributes | 1 - .../getproviders/package_authentication_test.go | 15 +++++++++++++-- internal/getproviders/testdata/.gitattributes | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 internal/getproviders/testdata/.gitattributes diff --git a/.gitattributes b/.gitattributes index cbd3665432..660cece98b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,3 @@ internal/**/*.tf text eol=lf internal/**/*.tofu text eol=lf internal/**/*.json text eol=lf internal/**/*.tmpl text eol=lf -internal/providercache/testdata/**/* text eol=lf \ No newline at end of file diff --git a/internal/getproviders/package_authentication_test.go b/internal/getproviders/package_authentication_test.go index 60d78b25fb..5d59401686 100644 --- a/internal/getproviders/package_authentication_test.go +++ b/internal/getproviders/package_authentication_test.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "path/filepath" + "runtime" "slices" "sort" "strings" @@ -240,7 +241,7 @@ func TestPackageHashAuthentication_failure(t *testing.T) { }{ "missing file": { PackageLocalArchive("testdata/no-package-here.zip"), - "failed to verify provider package checksums: lstat testdata/no-package-here.zip: " + syscall.ENOENT.Error(), + "failed to verify provider package checksums: " + statNotFoundErrorMsg("testdata/no-package-here.zip"), }, "checksum mismatch": { PackageLocalDir("testdata/filesystem-mirror/registry.opentofu.org/hashicorp/null/2.0.0/linux_amd64"), @@ -304,7 +305,7 @@ func TestArchiveChecksumAuthentication_failure(t *testing.T) { }{ "missing file": { PackageLocalArchive("testdata/no-package-here.zip"), - "failed to compute checksum for testdata/no-package-here.zip: lstat testdata/no-package-here.zip: " + syscall.ENOENT.Error(), + "failed to compute checksum for testdata/no-package-here.zip: " + statNotFoundErrorMsg("testdata/no-package-here.zip"), }, "checksum mismatch": { PackageLocalArchive("testdata/filesystem-mirror/registry.opentofu.org/hashicorp/null/terraform-provider-null_2.1.0_linux_amd64.zip"), @@ -333,6 +334,16 @@ func TestArchiveChecksumAuthentication_failure(t *testing.T) { } } +// statNotFoundErrorMsg is used to return a string containing: the specific name of the syscall used by +// the operating system to check the existence of a file, the filename, and the error message. +func statNotFoundErrorMsg(filename string) string { + prefix := "lstat" + if runtime.GOOS == "windows" { + prefix = "GetFileAttributesEx" + } + return fmt.Sprintf("%s %s: %s", prefix, filepath.FromSlash(filename), syscall.ENOENT.Error()) +} + // Matching checksum authentication takes a SHA256SUMS document, an archive // filename, and an expected SHA256 hash. On success both return values should // be nil. diff --git a/internal/getproviders/testdata/.gitattributes b/internal/getproviders/testdata/.gitattributes new file mode 100644 index 0000000000..bfaec8f648 --- /dev/null +++ b/internal/getproviders/testdata/.gitattributes @@ -0,0 +1 @@ +**/* text eol=lf