mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 01:48:02 +00:00
* Adding policy_check support into yaml config * Added policy check model and runtime structs * Adding BuildPolicyCheckCommand to ProjectCommandBuilder * Return incorrectly deleted code * Remove BuildAutoPolicyPlanCommand from ProjectCommandBuilder * Split runAutoCommand into two functions runAutoPlanCommand - does what originally RunAutoplancommand was doing except now it returns CommandResult and []models.ProjectCommandContext runAutoPolicyCheckCommand - accepts CommandContext, CommandResult, and []models.ProjectCommandContext as arguments and runs PolicyCheckStep runner * Refactor RunCommentCommand * Remove BuildPolicyCheckCommand and rename StepCmdExec back to TerraformExec * Add policy step runner logic and conftest interfaces. * Add show step runner to policy check stage. * Adding models.PolicyCheckCommand to buildCtx This also means buildPlanAllCommands call buildCtx twice once with models.PlanCommand and once with models.PolicyCheckCommand * Adding new project_command_builder that supports policy_check * Refactoring PolicyCheck specific logic into a PolicyCheckProjectCommandBuilder * Moving events.CommandContext to models.CommandContext this will allow me to remove buildCtx method and move ProjectCommandContext creation into models package * Policy Owners might be different types, for that reason we are refactoring Owners into its own struct with specific keys defining different owner types Co-authored-by: Nish Krishnan <nishk@lyft.com> Co-authored-by: Nish Krishnan <nishkrishnan@users.noreply.github.com>
121 lines
2.6 KiB
Go
121 lines
2.6 KiB
Go
package runtime
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
. "github.com/petergtz/pegomock"
|
|
"github.com/runatlantis/atlantis/server/events/models"
|
|
"github.com/runatlantis/atlantis/server/events/runtime/mocks"
|
|
. "github.com/runatlantis/atlantis/testing"
|
|
)
|
|
|
|
func TestRunMinimumVersionDelegate(t *testing.T) {
|
|
RegisterMockTestingT(t)
|
|
|
|
mockDelegate := mocks.NewMockRunner()
|
|
|
|
tfVersion12, _ := version.NewVersion("0.12.0")
|
|
tfVersion11, _ := version.NewVersion("0.11.14")
|
|
|
|
// these stay the same for all tests
|
|
extraArgs := []string{"extra", "args"}
|
|
envs := map[string]string{}
|
|
path := ""
|
|
|
|
expectedOut := "some valid output from delegate"
|
|
|
|
t.Run("default version success", func(t *testing.T) {
|
|
subject := &MinimumVersionStepRunnerDelegate{
|
|
defaultTfVersion: tfVersion12,
|
|
minimumVersion: tfVersion12,
|
|
delegate: mockDelegate,
|
|
}
|
|
|
|
ctx := models.ProjectCommandContext{}
|
|
|
|
When(mockDelegate.Run(ctx, extraArgs, path, envs)).ThenReturn(expectedOut, nil)
|
|
|
|
output, err := subject.Run(
|
|
ctx,
|
|
extraArgs,
|
|
path,
|
|
envs,
|
|
)
|
|
|
|
Equals(t, expectedOut, output)
|
|
Ok(t, err)
|
|
})
|
|
|
|
t.Run("ctx version success", func(t *testing.T) {
|
|
subject := &MinimumVersionStepRunnerDelegate{
|
|
defaultTfVersion: tfVersion11,
|
|
minimumVersion: tfVersion12,
|
|
delegate: mockDelegate,
|
|
}
|
|
|
|
ctx := models.ProjectCommandContext{
|
|
TerraformVersion: tfVersion12,
|
|
}
|
|
|
|
When(mockDelegate.Run(ctx, extraArgs, path, envs)).ThenReturn(expectedOut, nil)
|
|
|
|
output, err := subject.Run(
|
|
ctx,
|
|
extraArgs,
|
|
path,
|
|
envs,
|
|
)
|
|
|
|
Equals(t, expectedOut, output)
|
|
Ok(t, err)
|
|
})
|
|
|
|
t.Run("default version failure", func(t *testing.T) {
|
|
subject := &MinimumVersionStepRunnerDelegate{
|
|
defaultTfVersion: tfVersion11,
|
|
minimumVersion: tfVersion12,
|
|
delegate: mockDelegate,
|
|
}
|
|
|
|
ctx := models.ProjectCommandContext{}
|
|
|
|
output, err := subject.Run(
|
|
ctx,
|
|
extraArgs,
|
|
path,
|
|
envs,
|
|
)
|
|
|
|
mockDelegate.VerifyWasCalled(Never())
|
|
|
|
Equals(t, "Version: 0.11.14 is unsupported for this step. Minimum version is: 0.12.0", output)
|
|
Ok(t, err)
|
|
})
|
|
|
|
t.Run("ctx version failure", func(t *testing.T) {
|
|
subject := &MinimumVersionStepRunnerDelegate{
|
|
defaultTfVersion: tfVersion12,
|
|
minimumVersion: tfVersion12,
|
|
delegate: mockDelegate,
|
|
}
|
|
|
|
ctx := models.ProjectCommandContext{
|
|
TerraformVersion: tfVersion11,
|
|
}
|
|
|
|
output, err := subject.Run(
|
|
ctx,
|
|
extraArgs,
|
|
path,
|
|
envs,
|
|
)
|
|
|
|
mockDelegate.VerifyWasCalled(Never())
|
|
|
|
Equals(t, "Version: 0.11.14 is unsupported for this step. Minimum version is: 0.12.0", output)
|
|
Ok(t, err)
|
|
})
|
|
|
|
}
|