From c23b9cc8a217567172dc935eeee816b440db27ae Mon Sep 17 00:00:00 2001 From: Nish Krishnan Date: Wed, 12 Jan 2022 15:11:26 -0800 Subject: [PATCH] fix: terraform version loading should use GetAny (#165) --- server/core/terraform/terraform_client.go | 2 +- server/core/terraform/terraform_client_internal_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/core/terraform/terraform_client.go b/server/core/terraform/terraform_client.go index 65cd82eb3b..dbfb714676 100644 --- a/server/core/terraform/terraform_client.go +++ b/server/core/terraform/terraform_client.go @@ -316,7 +316,7 @@ func (l *VersionLoader) loadVersion(v *version.Version, destPath string) (runtim binURL := fmt.Sprintf("%s_%s_%s.zip", urlPrefix, runtime.GOOS, runtime.GOARCH) checksumURL := fmt.Sprintf("%s_SHA256SUMS", urlPrefix) fullSrcURL := fmt.Sprintf("%s?checksum=file:%s", binURL, checksumURL) - if err := l.downloader.GetFile(destPath, fullSrcURL); err != nil { + if err := l.downloader.GetAny(destPath, fullSrcURL); err != nil { return runtime_models.LocalFilePath(""), errors.Wrapf(err, "downloading terraform version %s at %q", v.String(), fullSrcURL) } diff --git a/server/core/terraform/terraform_client_internal_test.go b/server/core/terraform/terraform_client_internal_test.go index c9fb65c19a..6af2320e0f 100644 --- a/server/core/terraform/terraform_client_internal_test.go +++ b/server/core/terraform/terraform_client_internal_test.go @@ -58,7 +58,7 @@ func TestDefaultClient_Synchronous_RunCommandWithVersion(t *testing.T) { Equals(t, "hello\n", out) } -func TestVersionLoader(t *testing.T) { +func TestVersionLoader_buildsURL(t *testing.T) { v, _ := version.NewVersion("0.15.0") destPath := "some/path" @@ -74,10 +74,10 @@ func TestVersionLoader(t *testing.T) { } t.Run("success", func(t *testing.T) { - When(mockDownloader.GetFile(EqString(destPath), EqString(fullURL))).ThenReturn(nil) + When(mockDownloader.GetAny(EqString(destPath), EqString(fullURL))).ThenReturn(nil) binPath, err := subject.loadVersion(v, destPath) - mockDownloader.VerifyWasCalledOnce().GetFile(EqString(destPath), EqString(fullURL)) + mockDownloader.VerifyWasCalledOnce().GetAny(EqString(destPath), EqString(fullURL)) Ok(t, err) @@ -86,7 +86,7 @@ func TestVersionLoader(t *testing.T) { t.Run("error", func(t *testing.T) { - When(mockDownloader.GetFile(EqString(destPath), EqString(fullURL))).ThenReturn(fmt.Errorf("err")) + When(mockDownloader.GetAny(EqString(destPath), EqString(fullURL))).ThenReturn(fmt.Errorf("err")) _, err := subject.loadVersion(v, destPath) Assert(t, err != nil, "err is expected")