Files
atlantis/server/events/runtime/run_step_runner_test.go
Luke Kysow 78a2bb519e Set PLANFILE environment variable in run step.
Env var is set to where Atlantis expects the planfile to be.
Fixes #168.
2018-07-07 10:04:49 +02:00

81 lines
2.0 KiB
Go

package runtime_test
import (
"strings"
"testing"
"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/events/runtime"
"github.com/runatlantis/atlantis/server/events/yaml/valid"
"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"
)
func TestRunStepRunner_Run(t *testing.T) {
cases := []struct {
Command string
ExpOut string
ExpErr string
}{
{
Command: "",
ExpErr: "no commands for run step",
},
{
Command: "echo hi",
ExpOut: "hi\n",
},
{
Command: "echo hi >> file && cat file",
ExpOut: "hi\n",
},
{
Command: "lkjlkj",
ExpErr: "exit status 127: running \"lkjlkj\" in",
},
{
Command: "echo workspace=$WORKSPACE version=$ATLANTIS_TERRAFORM_VERSION dir=$DIR planfile=$PLANFILE",
ExpOut: "workspace=myworkspace version=0.11.0 dir=$DIR planfile=$DIR/myworkspace.tfplan\n",
},
}
projVersion, err := version.NewVersion("v0.11.0")
Ok(t, err)
defaultVersion, _ := version.NewVersion("0.8")
r := runtime.RunStepRunner{
DefaultTFVersion: defaultVersion,
}
ctx := models.ProjectCommandContext{
Log: logging.NewNoopLogger(),
Workspace: "myworkspace",
RepoRelDir: "mydir",
ProjectConfig: &valid.Project{
TerraformVersion: projVersion,
Workspace: "myworkspace",
Dir: "mydir",
},
}
for _, c := range cases {
t.Run(c.Command, func(t *testing.T) {
tmpDir, cleanup := TempDir(t)
defer cleanup()
var split []string
if c.Command != "" {
split = strings.Split(c.Command, " ")
}
out, err := r.Run(ctx, split, tmpDir)
if c.ExpErr != "" {
ErrContains(t, c.ExpErr, err)
return
}
Ok(t, err)
// Replace $DIR in the exp with the actual temp dir. We do this
// here because when constructing the cases we don't yet know the
// temp dir.
expOut := strings.Replace(c.ExpOut, "$DIR", tmpDir, -1)
Equals(t, expOut, out)
})
}
}