mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
add test for override
This commit is contained in:
parent
e36886c0e7
commit
191a5f1018
@ -3,6 +3,7 @@ package cloud
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@ -205,3 +206,63 @@ func TestTaskStagesWithErrors(t *testing.T) {
|
||||
t.Error("Expected to error but did not")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTaskStageOverride(t *testing.T) {
|
||||
b, bCleanup := testBackendWithName(t)
|
||||
defer bCleanup()
|
||||
|
||||
integrationContext, writer := newMockIntegrationContext(b, t)
|
||||
|
||||
integrationContext.Op.UIOut = b.CLI
|
||||
|
||||
cases := map[string]struct {
|
||||
taskStageID string
|
||||
isError bool
|
||||
errMsg string
|
||||
input *mockInput
|
||||
}{
|
||||
"override-pass": {
|
||||
taskStageID: "ts-pass",
|
||||
isError: false,
|
||||
input: testInput(t, map[string]string{
|
||||
"→→ [bold]Override": "override",
|
||||
}),
|
||||
errMsg: "",
|
||||
},
|
||||
"override-fail": {
|
||||
taskStageID: "ts-err",
|
||||
isError: true,
|
||||
input: testInput(t, map[string]string{
|
||||
"→→ [bold]Override": "override",
|
||||
}),
|
||||
errMsg: "",
|
||||
},
|
||||
"skip-override": {
|
||||
taskStageID: "ts-err",
|
||||
isError: true,
|
||||
errMsg: "Failed to override: Apply discarded.",
|
||||
input: testInput(t, map[string]string{
|
||||
"→→ [bold]Override": "no",
|
||||
}),
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
integrationContext.Op.UIIn = c.input
|
||||
_, err := b.processStageOverrides(integrationContext, writer, c.taskStageID)
|
||||
if c.isError {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected to fail with some error")
|
||||
}
|
||||
if c.errMsg != "" {
|
||||
if !strings.Contains(err.Error(), c.errMsg) {
|
||||
t.Fatalf("Expected: %s, got: %s", c.errMsg, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Fatalf("Expected to pass, got err: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,6 +209,7 @@ func testBackend(t *testing.T, obj cty.Value) (*Cloud, func()) {
|
||||
b.client.CostEstimates = mc.CostEstimates
|
||||
b.client.Organizations = mc.Organizations
|
||||
b.client.Plans = mc.Plans
|
||||
b.client.TaskStages = mc.TaskStages
|
||||
b.client.PolicySetOutcomes = mc.PolicySetOutcomes
|
||||
b.client.PolicyChecks = mc.PolicyChecks
|
||||
b.client.Runs = mc.Runs
|
||||
|
@ -28,6 +28,7 @@ type MockClient struct {
|
||||
Organizations *MockOrganizations
|
||||
Plans *MockPlans
|
||||
PolicySetOutcomes *MockPolicySetOutcomes
|
||||
TaskStages *MockTaskStages
|
||||
PolicyChecks *MockPolicyChecks
|
||||
Runs *MockRuns
|
||||
StateVersions *MockStateVersions
|
||||
@ -43,6 +44,7 @@ func NewMockClient() *MockClient {
|
||||
c.CostEstimates = newMockCostEstimates(c)
|
||||
c.Organizations = newMockOrganizations(c)
|
||||
c.Plans = newMockPlans(c)
|
||||
c.TaskStages = newMockTaskStages(c)
|
||||
c.PolicySetOutcomes = newMockPolicySetOutcomes(c)
|
||||
c.PolicyChecks = newMockPolicyChecks(c)
|
||||
c.Runs = newMockRuns(c)
|
||||
@ -547,6 +549,36 @@ func (m *MockPlans) ReadJSONOutput(ctx context.Context, planID string) ([]byte,
|
||||
return []byte(planOutput), nil
|
||||
}
|
||||
|
||||
type MockTaskStages struct {
|
||||
client *MockClient
|
||||
}
|
||||
|
||||
func newMockTaskStages(client *MockClient) *MockTaskStages {
|
||||
return &MockTaskStages{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockTaskStages) Override(ctx context.Context, taskStageID string, options tfe.TaskStageOverrideOptions) (*tfe.TaskStage, error) {
|
||||
switch taskStageID {
|
||||
case "ts-err":
|
||||
return nil, errors.New("test error")
|
||||
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockTaskStages) Read(ctx context.Context, taskStageID string, options *tfe.TaskStageReadOptions) (*tfe.TaskStage, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *MockTaskStages) List(ctx context.Context, runID string, options *tfe.TaskStageListOptions) (*tfe.TaskStageList, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
type MockPolicySetOutcomes struct {
|
||||
client *MockClient
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user