-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
663 additions
and
76 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,25 @@ | ||
package runtime | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
) | ||
|
||
// VersionStepRunner runs a version command given a ctx | ||
type VersionStepRunner struct { | ||
TerraformExecutor TerraformExec | ||
DefaultTFVersion *version.Version | ||
} | ||
|
||
// Run ensures a given version for the executable, builds the args from the project context and then runs executable returning the result | ||
func (v *VersionStepRunner) Run(ctx models.ProjectCommandContext, extraArgs []string, path string, envs map[string]string) (string, error) { | ||
tfVersion := v.DefaultTFVersion | ||
if ctx.TerraformVersion != nil { | ||
tfVersion = ctx.TerraformVersion | ||
} | ||
|
||
versionCmd := []string{"version"} | ||
return v.TerraformExecutor.RunCommandWithVersion(ctx.Log, filepath.Clean(path), versionCmd, envs, tfVersion, ctx.Workspace) | ||
} |
This file contains 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,50 @@ | ||
package runtime | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
. "github.com/petergtz/pegomock" | ||
"github.com/runatlantis/atlantis/server/core/terraform/mocks" | ||
"github.com/runatlantis/atlantis/server/events/models" | ||
"github.com/runatlantis/atlantis/server/logging" | ||
. "github.com/runatlantis/atlantis/testing" | ||
) | ||
|
||
func TestRunVersionStep(t *testing.T) { | ||
RegisterMockTestingT(t) | ||
logger := logging.NewNoopLogger(t) | ||
workspace := "default" | ||
|
||
context := models.ProjectCommandContext{ | ||
Log: logger, | ||
EscapedCommentArgs: []string{"comment", "args"}, | ||
Workspace: workspace, | ||
RepoRelDir: ".", | ||
User: models.User{Username: "username"}, | ||
Pull: models.PullRequest{ | ||
Num: 2, | ||
}, | ||
BaseRepo: models.Repo{ | ||
FullName: "owner/repo", | ||
Owner: "owner", | ||
Name: "repo", | ||
}, | ||
} | ||
|
||
terraform := mocks.NewMockClient() | ||
tfVersion, _ := version.NewVersion("0.15.0") | ||
tmpDir, cleanup := TempDir(t) | ||
defer cleanup() | ||
|
||
s := &VersionStepRunner{ | ||
TerraformExecutor: terraform, | ||
DefaultTFVersion: tfVersion, | ||
} | ||
|
||
t.Run("ensure runs", func(t *testing.T) { | ||
_, err := s.Run(context, []string{}, tmpDir, map[string]string(nil)) | ||
terraform.VerifyWasCalledOnce().RunCommandWithVersion(logger, tmpDir, []string{"version"}, map[string]string(nil), tfVersion, "default") | ||
Ok(t, err) | ||
}) | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.