Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyguava committed Jun 29, 2023
1 parent cf960b3 commit 9a770d6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion server/core/config/raw/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (s Step) Validate() error {
}
// Sort so tests can be deterministic.
sort.Strings(argKeys)
return fmt.Errorf("env steps only support keys %q, %q and %q, found extra keys %q", RunStepName, CommandArgKey, OutputArgKey, strings.Join(argKeys, ","))
return fmt.Errorf("run steps only support keys %q, %q and %q, found extra keys %q", RunStepName, CommandArgKey, OutputArgKey, strings.Join(argKeys, ","))
}
default:
return fmt.Errorf("%q is not a valid step type", stepName)
Expand Down
22 changes: 11 additions & 11 deletions server/core/config/raw/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ env:
value: direct_value
name: test`,
exp: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"value": "direct_value",
"name": "test",
Expand All @@ -96,7 +96,7 @@ env:
command: echo 123
name: test`,
exp: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"command": "echo 123",
"name": "test",
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "env",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"name": "test",
"command": "echo 123",
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "multiple keys in env",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"key1": nil,
"key2": nil,
},
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "invalid key in env",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"invalid": nil,
},
},
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "env step with no name key set",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"value": "value",
},
Expand All @@ -364,7 +364,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "env step with invalid key",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"abc": "",
"invalid2": "",
Expand All @@ -376,7 +376,7 @@ func TestStep_Validate(t *testing.T) {
{
description: "env step with both command and value set",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"name": "name",
"command": "command",
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestStep_ToValid(t *testing.T) {
{
description: "env step",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"env": {
"name": "test",
"command": "echo 123",
Expand Down Expand Up @@ -561,7 +561,7 @@ func TestStep_ToValid(t *testing.T) {
{
description: "run step with output",
input: raw.Step{
EnvOrRun: EnvType{
EnvOrRun: EnvOrRunType{
"run": {
"command": "my 'run command'",
"output": "hide",
Expand All @@ -583,4 +583,4 @@ func TestStep_ToValid(t *testing.T) {
}

type MapType map[string]map[string][]string
type EnvType map[string]map[string]string
type EnvOrRunType map[string]map[string]string
1 change: 1 addition & 0 deletions server/core/config/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ type Autoplan struct {
Enabled bool
}

// PostProcessRunOutputOption is an enum of options for post-processing RunCommand output
type PostProcessRunOutputOption string

const (
Expand Down
3 changes: 2 additions & 1 deletion server/core/runtime/env_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runtime
import (
"strings"

"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/events/command"
)

Expand All @@ -20,7 +21,7 @@ func (r *EnvStepRunner) Run(ctx command.ProjectContext, command string, value st
}
// Pass `false` for streamOutput because this isn't interesting to the user reading the build logs
// in the web UI.
res, err := r.RunStepRunner.Run(ctx, command, path, envs, false, "")
res, err := r.RunStepRunner.Run(ctx, command, path, envs, false, valid.PostProcessRunOutputShow)
// Trim newline from res to support running `echo env_value` which has
// a newline. We don't recommend users run echo -n env_value to remove the
// newline because -n doesn't work in the sh shell which is what we use
Expand Down
3 changes: 2 additions & 1 deletion server/core/runtime/multienv_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/events/command"
)

Expand All @@ -15,7 +16,7 @@ type MultiEnvStepRunner struct {
// Run runs the multienv step command.
// The command must return a json string containing the array of name-value pairs that are being added as extra environment variables
func (r *MultiEnvStepRunner) Run(ctx command.ProjectContext, command string, path string, envs map[string]string) (string, error) {
res, err := r.RunStepRunner.Run(ctx, command, path, envs, false, "")
res, err := r.RunStepRunner.Run(ctx, command, path, envs, false, valid.PostProcessRunOutputShow)
if err == nil {
if len(res) > 0 {
var sb strings.Builder
Expand Down
3 changes: 2 additions & 1 deletion server/core/runtime/run_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/hashicorp/go-version"
. "github.com/petergtz/pegomock/v4"
"github.com/runatlantis/atlantis/server/core/config/valid"
"github.com/runatlantis/atlantis/server/core/runtime"
"github.com/runatlantis/atlantis/server/core/terraform/mocks"
"github.com/runatlantis/atlantis/server/events/command"
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestRunStepRunner_Run(t *testing.T) {
ProjectName: c.ProjectName,
EscapedCommentArgs: []string{"-target=resource1", "-target=resource2"},
}
out, err := r.Run(ctx, c.Command, tmpDir, map[string]string{"test": "var"}, true, "")
out, err := r.Run(ctx, c.Command, tmpDir, map[string]string{"test": "var"}, true, valid.PostProcessRunOutputShow)
if c.ExpErr != "" {
ErrContains(t, c.ExpErr, err)
return
Expand Down

0 comments on commit 9a770d6

Please sign in to comment.