-
Notifications
You must be signed in to change notification settings - Fork 903
feat: Download default terraform version when minor version mismatches #1775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b25b4b1
download default terraform version when minor version mismatches
AbhineetJain 0e1aa3f
use the new exectuor version method
AbhineetJain 544243f
refactor into methods
AbhineetJain c76885d
add unit tests
AbhineetJain 6960c33
unset PATH variable in cleanup
AbhineetJain ebe115b
skip tests on Windows
AbhineetJain b822bf3
clean up code
AbhineetJain 62b395e
Debugging CI failure
AbhineetJain 3f51748
Update terraform version to default for ci
AbhineetJain 6b84a73
fix unit tests
AbhineetJain 7f68d1e
remove extra select
AbhineetJain 0c58641
simplify tests
AbhineetJain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add unit tests
- Loading branch information
commit c76885d302940008daa864683ab8a8c4d2e8cf44
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package terraform | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_getAbsoluteBinaryPath(t *testing.T) { | ||
t.Parallel() | ||
type args struct { | ||
ctx context.Context | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
terraformVersion string | ||
expectedAbsoluteBinary string | ||
expectedOk bool | ||
}{ | ||
{ | ||
name: "TestCorrectVersion", | ||
args: args{ctx: context.Background()}, | ||
terraformVersion: "1.1.9", | ||
expectedAbsoluteBinary: "", | ||
expectedOk: true, | ||
}, | ||
{ | ||
name: "TestOldVersion", | ||
args: args{ctx: context.Background()}, | ||
terraformVersion: "1.0.9", | ||
expectedAbsoluteBinary: "", | ||
expectedOk: false, | ||
}, | ||
{ | ||
name: "TestNewVersion", | ||
args: args{ctx: context.Background()}, | ||
terraformVersion: "1.2.9", | ||
expectedAbsoluteBinary: "", | ||
expectedOk: false, | ||
}, | ||
{ | ||
name: "TestMalformedVersion", | ||
args: args{ctx: context.Background()}, | ||
terraformVersion: "version", | ||
expectedAbsoluteBinary: "", | ||
expectedOk: false, | ||
}, | ||
} | ||
// nolint:paralleltest | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Create a temp dir with the binary | ||
tempDir := t.TempDir() | ||
terraformBinaryOutput := fmt.Sprintf(`#!/bin/sh | ||
cat <<-EOF | ||
{ | ||
"terraform_version": "%s", | ||
"platform": "linux_amd64", | ||
"provider_selections": {}, | ||
"terraform_outdated": false | ||
} | ||
EOF`, tt.terraformVersion) | ||
|
||
// #nosec | ||
err := os.WriteFile( | ||
filepath.Join(tempDir, "terraform"), | ||
[]byte(terraformBinaryOutput), | ||
0770, | ||
) | ||
require.NoError(t, err) | ||
|
||
// Add the binary to PATH | ||
pathVariable := os.Getenv("PATH") | ||
t.Setenv("PATH", strings.Join([]string{tempDir, pathVariable}, ":")) | ||
|
||
if tt.expectedOk { | ||
tt.expectedAbsoluteBinary = filepath.Join(tempDir, "terraform") | ||
} | ||
|
||
actualAbsoluteBinary, actualOk := getAbsoluteBinaryPath(tt.args.ctx) | ||
if actualAbsoluteBinary != tt.expectedAbsoluteBinary { | ||
t.Errorf("getAbsoluteBinaryPath() absoluteBinaryPath, actual = %v, expected %v", actualAbsoluteBinary, tt.expectedAbsoluteBinary) | ||
} | ||
if actualOk != tt.expectedOk { | ||
t.Errorf("getAbsoluteBinaryPath() ok, actual = %v, expected %v", actualOk, tt.expectedOk) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.