-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cross test utilities to be shared between sdkv2 and pf (#2576)
This is a refactor which moves some of the SDKv2 cross-test utilities to the crosstestimpl colder so that they can be reused in the PF cross-tests. related to #2297
- Loading branch information
1 parent
58f0b33
commit ae9cd89
Showing
7 changed files
with
151 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package crosstestsimpl | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pulumi/pulumi/sdk/v3/go/auto" | ||
"github.com/pulumi/pulumi/sdk/v3/go/common/apitype" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tests/tfcheck" | ||
) | ||
|
||
type PulumiDiffResp struct { | ||
DetailedDiff map[string]interface{} `json:"detailedDiff"` | ||
DeleteBeforeReplace bool `json:"deleteBeforeReplace"` | ||
} | ||
|
||
type DiffResult struct { | ||
TFDiff tfcheck.TFChange | ||
PulumiDiff PulumiDiffResp | ||
} | ||
|
||
func VerifyBasicDiffAgreement(t T, tfActions []string, us auto.UpdateSummary, diffResponse PulumiDiffResp) { | ||
t.Helper() | ||
t.Logf("UpdateSummary.ResourceChanges: %#v", us.ResourceChanges) | ||
// Action list from https://github.com/opentofu/opentofu/blob/main/internal/plans/action.go#L11 | ||
if len(tfActions) == 0 { | ||
require.FailNow(t, "No TF actions found") | ||
} | ||
if len(tfActions) == 1 { | ||
switch tfActions[0] { | ||
case "no-op": | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
assert.Equalf(t, 2, rc[string(apitype.OpSame)], "expected the test resource and stack to stay the same") | ||
assert.Equalf(t, 1, len(rc), "expected one entry in UpdateSummary.ResourceChanges") | ||
case "create": | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
assert.Equalf(t, 1, rc[string(apitype.OpSame)], "expected the stack to stay the same") | ||
assert.Equalf(t, 1, rc[string(apitype.OpCreate)], "expected the test resource to get a create plan") | ||
case "read": | ||
require.FailNow(t, "Unexpected TF action: read") | ||
case "update": | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
assert.Equalf(t, 1, rc[string(apitype.OpSame)], "expected one resource to stay the same - the stack") | ||
assert.Equalf(t, 1, rc[string(apitype.Update)], "expected the test resource to get an update plan") | ||
assert.Equalf(t, 2, len(rc), "expected two entries in UpdateSummary.ResourceChanges") | ||
case "delete": | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
assert.Equalf(t, 1, rc[string(apitype.OpSame)], "expected the stack to stay the same") | ||
assert.Equalf(t, 1, rc[string(apitype.OpDelete)], "expected the test resource to get a delete plan") | ||
default: | ||
panic("TODO: do not understand this TF action yet: " + tfActions[0]) | ||
} | ||
} else if len(tfActions) == 2 { | ||
if tfActions[0] == "create" && tfActions[1] == "delete" { | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
assert.Equalf(t, 1, rc[string(apitype.OpSame)], "expected the stack to stay the same") | ||
assert.Equalf(t, 1, rc[string(apitype.OpReplace)], "expected the test resource to get a replace plan") | ||
assert.Equalf(t, false, diffResponse.DeleteBeforeReplace, "expected deleteBeforeReplace to be true") | ||
} else if tfActions[0] == "delete" && tfActions[1] == "create" { | ||
require.NotNilf(t, us.ResourceChanges, "UpdateSummary.ResourceChanges should not be nil") | ||
rc := *us.ResourceChanges | ||
t.Logf("UpdateSummary.ResourceChanges: %#v", rc) | ||
assert.Equalf(t, 1, rc[string(apitype.OpSame)], "expected the stack to stay the same") | ||
assert.Equalf(t, 1, rc[string(apitype.OpReplace)], "expected the test resource to get a replace plan") | ||
assert.Equalf(t, true, diffResponse.DeleteBeforeReplace, "expected deleteBeforeReplace to be true") | ||
} else { | ||
panic("TODO: do not understand this TF action yet: " + fmt.Sprint(tfActions)) | ||
} | ||
} else { | ||
panic("TODO: do not understand this TF action yet: " + fmt.Sprint(tfActions)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.