Skip to content

Commit

Permalink
fix: terraform version loading should use GetAny (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishkrishnan authored Jan 12, 2022
1 parent f03d8f5 commit c23b9cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions server/core/terraform/terraform_client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand All @@ -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")
Expand Down

0 comments on commit c23b9cc

Please sign in to comment.