getproviders: FakeInstallablePackageMeta filename
Add an optional execFilename argument to the test helper function FakeInstallablePackageMeta, which allows the creation of invalid packages.
This commit is contained in:
parent
8e87ccb689
commit
a18b531b14
|
@ -1710,7 +1710,7 @@ func newMockProviderSource(t *testing.T, availableProviderVersions map[string][]
|
||||||
close()
|
close()
|
||||||
t.Fatalf("failed to parse %q as a version number for %q: %s", versionStr, addr.ForDisplay(), err)
|
t.Fatalf("failed to parse %q as a version number for %q: %s", versionStr, addr.ForDisplay(), err)
|
||||||
}
|
}
|
||||||
meta, close, err := getproviders.FakeInstallablePackageMeta(addr, version, getproviders.VersionList{getproviders.MustParseVersion("5.0")}, getproviders.CurrentPlatform)
|
meta, close, err := getproviders.FakeInstallablePackageMeta(addr, version, getproviders.VersionList{getproviders.MustParseVersion("5.0")}, getproviders.CurrentPlatform, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
close()
|
close()
|
||||||
t.Fatalf("failed to prepare fake package for %s %s: %s", addr.ForDisplay(), versionStr, err)
|
t.Fatalf("failed to prepare fake package for %s %s: %s", addr.ForDisplay(), versionStr, err)
|
||||||
|
@ -1770,7 +1770,7 @@ func installFakeProviderPackagesElsewhere(t *testing.T, cacheDir *providercache.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to parse %q as a version number for %q: %s", versionStr, name, err)
|
t.Fatalf("failed to parse %q as a version number for %q: %s", versionStr, name, err)
|
||||||
}
|
}
|
||||||
meta, close, err := getproviders.FakeInstallablePackageMeta(addr, version, getproviders.VersionList{getproviders.MustParseVersion("5.0")}, getproviders.CurrentPlatform)
|
meta, close, err := getproviders.FakeInstallablePackageMeta(addr, version, getproviders.VersionList{getproviders.MustParseVersion("5.0")}, getproviders.CurrentPlatform, "")
|
||||||
// We're going to install all these fake packages before we return,
|
// We're going to install all these fake packages before we return,
|
||||||
// so we don't need to preserve them afterwards.
|
// so we don't need to preserve them afterwards.
|
||||||
defer close()
|
defer close()
|
||||||
|
|
|
@ -143,13 +143,15 @@ func FakePackageMeta(provider addrs.Provider, version Version, protocols Version
|
||||||
// to a temporary archive file that could actually be installed in principle.
|
// to a temporary archive file that could actually be installed in principle.
|
||||||
//
|
//
|
||||||
// Installing it will not produce a working provider though: just a fake file
|
// Installing it will not produce a working provider though: just a fake file
|
||||||
// posing as an executable.
|
// posing as an executable. The filename for the executable defaults to the
|
||||||
|
// standard terraform-provider-NAME_X.Y.Z format, but can be overridden with
|
||||||
|
// the execFilename argument.
|
||||||
//
|
//
|
||||||
// It's the caller's responsibility to call the close callback returned
|
// It's the caller's responsibility to call the close callback returned
|
||||||
// alongside the result in order to clean up the temporary file. The caller
|
// alongside the result in order to clean up the temporary file. The caller
|
||||||
// should call the callback even if this function returns an error, because
|
// should call the callback even if this function returns an error, because
|
||||||
// some error conditions leave a partially-created file on disk.
|
// some error conditions leave a partially-created file on disk.
|
||||||
func FakeInstallablePackageMeta(provider addrs.Provider, version Version, protocols VersionList, target Platform) (PackageMeta, func(), error) {
|
func FakeInstallablePackageMeta(provider addrs.Provider, version Version, protocols VersionList, target Platform, execFilename string) (PackageMeta, func(), error) {
|
||||||
f, err := ioutil.TempFile("", "terraform-getproviders-fake-package-")
|
f, err := ioutil.TempFile("", "terraform-getproviders-fake-package-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PackageMeta{}, func() {}, err
|
return PackageMeta{}, func() {}, err
|
||||||
|
@ -162,10 +164,12 @@ func FakeInstallablePackageMeta(provider addrs.Provider, version Version, protoc
|
||||||
os.Remove(f.Name())
|
os.Remove(f.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
execFilename := fmt.Sprintf("terraform-provider-%s_%s", provider.Type, version.String())
|
if execFilename == "" {
|
||||||
if target.OS == "windows" {
|
execFilename = fmt.Sprintf("terraform-provider-%s_%s", provider.Type, version.String())
|
||||||
// For a little more (technically unnecessary) realism...
|
if target.OS == "windows" {
|
||||||
execFilename += ".exe"
|
// For a little more (technically unnecessary) realism...
|
||||||
|
execFilename += ".exe"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zw := zip.NewWriter(f)
|
zw := zip.NewWriter(f)
|
||||||
|
|
Loading…
Reference in New Issue