fix: internal/getprovider tests on Windows (#3275)

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
Diógenes Fernandes 2025-09-16 15:29:31 -03:00 committed by GitHub
parent f5ef40c37c
commit 9b14212207
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

1
.gitattributes vendored
View file

@ -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

View file

@ -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.

View file

@ -0,0 +1 @@
**/* text eol=lf