fixes for rebase breaks and diffs

This commit is contained in:
Pat Gavlin 2021-04-28 14:21:10 -07:00
parent 908c3aeb70
commit 24a0eb0274
9 changed files with 50 additions and 24 deletions

View file

@ -464,7 +464,7 @@ func (b *localBackend) Preview(ctx context.Context, stack backend.Stack,
if cmdutil.IsTruthy(os.Getenv(PulumiFilestateLockingEnvVar)) {
err := b.Lock(ctx, stack.Ref())
if err != nil {
return nil, result.FromError(err)
return nil, nil, result.FromError(err)
}
defer b.Unlock(ctx, stack.Ref())
}

View file

@ -19,11 +19,11 @@ import (
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/v2/backend/display"
"github.com/pulumi/pulumi/pkg/v2/resource/deploy"
"github.com/pulumi/pulumi/sdk/v2/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/cmdutil"
"github.com/pulumi/pulumi/pkg/v3/backend/display"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
)
func newPlanCmd() *cobra.Command {

View file

@ -49,6 +49,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/constant"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/ciutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/cmdutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

View file

@ -2638,7 +2638,7 @@ func TestPlannedUpdate(t *testing.T) {
plan, res := TestOp(Update).Plan(project, p.GetTarget(nil), p.Options, p.BackendClient, nil)
assert.Nil(t, res)
// Run an update using the plan.
// Attempt to run an update using the plan.
ins = resource.NewPropertyMapFromMap(map[string]interface{}{
"qux": []interface{}{
"alpha",
@ -2647,6 +2647,30 @@ func TestPlannedUpdate(t *testing.T) {
})
p.Options.Plan = plan
snap, res := TestOp(Update).Run(project, p.GetTarget(nil), p.Options, false, p.BackendClient, nil)
assert.NotNil(t, res)
// Check the resource's state.
if !assert.Len(t, snap.Resources, 1) {
return
}
// Change the provider's planned operation to a same step.
// Remove the provider from the plan.
plan["urn:pulumi:test::test::pulumi:providers:pkgA::default"].Ops = []deploy.StepOp{deploy.OpSame}
// Attempt to run an update using the plan.
ins = resource.NewPropertyMapFromMap(map[string]interface{}{
"foo": "bar",
"baz": map[string]interface{}{
"a": 42,
"b": "alpha",
},
"qux": []interface{}{
"beta",
24,
},
})
snap, res = TestOp(Update).Run(project, p.GetTarget(snap), p.Options, false, p.BackendClient, nil)
assert.Nil(t, res)
// Check the resource's state.
@ -2658,9 +2682,10 @@ func TestPlannedUpdate(t *testing.T) {
"foo": "bar",
"baz": map[string]interface{}{
"a": 42,
"b": "alpha",
},
"qux": []interface{}{
"alpha",
"beta",
24,
},
})

View file

@ -40,19 +40,19 @@ func (u *updateInfo) GetTarget() *deploy.Target {
func ImportOp(imports []deploy.Import) TestOp {
return TestOp(func(info UpdateInfo, ctx *Context, opts UpdateOptions,
dryRun bool) (Plan, ResourceChanges, result.Result) {
dryRun bool) (deploy.Plan, ResourceChanges, result.Result) {
return Import(info, ctx, opts, imports, dryRun)
})
}
type TestOp func(UpdateInfo, *Context, UpdateOptions, bool) (Plan, ResourceChanges, result.Result)
type TestOp func(UpdateInfo, *Context, UpdateOptions, bool) (deploy.Plan, ResourceChanges, result.Result)
type ValidateFunc func(project workspace.Project, target deploy.Target, entries JournalEntries,
events []Event, res result.Result) result.Result
func (op TestOp) Plan(project workspace.Project, target deploy.Target, opts UpdateOptions,
backendClient deploy.BackendClient, validate ValidateFunc) (Plan, result.Result) {
backendClient deploy.BackendClient, validate ValidateFunc) (deploy.Plan, result.Result) {
plan, _, res := op.runWithContext(context.Background(), project, target, opts, true, backendClient, validate)
return plan, res
@ -76,7 +76,7 @@ func (op TestOp) RunWithContext(
func (op TestOp) runWithContext(
callerCtx context.Context, project workspace.Project,
target deploy.Target, opts UpdateOptions, dryRun bool,
backendClient deploy.BackendClient, validate ValidateFunc) (Plan, *deploy.Snapshot, result.Result) {
backendClient deploy.BackendClient, validate ValidateFunc) (deploy.Plan, *deploy.Snapshot, result.Result) {
// Create an appropriate update info and context.
info := &updateInfo{project: project, target: target}

View file

@ -5,9 +5,9 @@ import (
"sort"
"strings"
"github.com/pulumi/pulumi/pkg/v2/resource/deploy/providers"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy/providers"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)
// A Plan is a mapping from URNs to ResourcePlans. The plan defines an expected set of resources and the expected

View file

@ -1,10 +1,10 @@
package stack
import (
"github.com/pulumi/pulumi/pkg/v2/resource/deploy"
"github.com/pulumi/pulumi/sdk/v2/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource/config"
"github.com/pulumi/pulumi/pkg/v3/resource/deploy"
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
)
func SerializeResourcePlan(plan *deploy.ResourcePlan, enc config.Encrypter, showSecrets bool) (apitype.ResourcePlanV1, error) {

View file

@ -3,8 +3,8 @@ package apitype
import (
"encoding/json"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
)
// GoalV1 is the serializable version of a resource goal state.

View file

@ -187,7 +187,7 @@ func (props PropertyMap) diff(other PropertyMap, ignoreUnknowns bool, ignoreKeys
// If a new exists, use it; for output properties, however, ignore differences.
if new.IsOutput() {
sames[k] = old
} else if diff := old.Diff(new, ignoreKeys...); diff != nil {
} else if diff := old.diff(new, ignoreUnknowns, ignoreKeys); diff != nil {
if !old.HasValue() {
adds[k] = new
} else if !new.HasValue() {
@ -250,7 +250,7 @@ func (v PropertyValue) diff(other PropertyValue, ignoreUnknowns bool, ignoreKeys
sames := make(map[int]PropertyValue)
updates := make(map[int]ValueDiff)
for i := 0; i < len(old) && i < len(new); i++ {
if diff := old[i].Diff(new[i]); diff != nil {
if diff := old[i].diff(new[i], ignoreUnknowns, ignoreKeys); diff != nil {
updates[i] = *diff
} else {
sames[i] = old[i]
@ -274,7 +274,7 @@ func (v PropertyValue) diff(other PropertyValue, ignoreUnknowns bool, ignoreKeys
if v.IsObject() && other.IsObject() {
old := v.ObjectValue()
new := other.ObjectValue()
if diff := old.Diff(new, ignoreKeys...); diff != nil {
if diff := old.diff(new, ignoreUnknowns, ignoreKeys); diff != nil {
return &ValueDiff{
Old: v,
New: other,