Skip to content

Commit

Permalink
Fix saved plan test regressions, fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasslash committed Jul 24, 2023
1 parent 31cf55f commit e6c0e7b
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/backend/local/backend_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestLocalRun_cloudPlan(t *testing.T) {
configDir := "./testdata/apply"
b := TestLocal(t)

_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir)
_, configLoader, configCleanup := initwd.MustLoadConfigForTests(t, configDir, "tests")
defer configCleanup()

planPath := "../../cloud/cloudplan/testdata/plan-bookmark/bookmark.json"
Expand Down
2 changes: 1 addition & 1 deletion internal/command/views/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

func TestShowHuman(t *testing.T) {
redactedPath := "../../cloud/testdata/plan-json-basic/plan-redacted.json"
redactedPath := "./testdata/plans/redacted-plan.json"
redactedPlanJson, err := os.ReadFile(redactedPath)
if err != nil {
t.Fatalf("couldn't read json plan test data at %s for showing a cloud plan. Did the file get moved?", redactedPath)
Expand Down
6 changes: 3 additions & 3 deletions internal/command/views/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func (t *TestHuman) Run(run *moduletest.Run, file *moduletest.File) {
RelevantAttributes: attrs,
}

var opts []jsonformat.PlanRendererOpt
var opts []plans.Quality
if !run.Verbose.Plan.CanApply() {
opts = append(opts, jsonformat.CanNotApply)
opts = append(opts, plans.NoChanges)
}
if run.Verbose.Plan.Errored {
opts = append(opts, jsonformat.Errored)
opts = append(opts, plans.Errored)
}

renderer.RenderHumanPlan(plan, run.Verbose.Plan.UIMode, opts...)
Expand Down
116 changes: 116 additions & 0 deletions internal/command/views/testdata/plans/redacted-plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"plan_format_version": "1.1",
"resource_drift": [],
"resource_changes": [
{
"address": "null_resource.foo",
"mode": "managed",
"type": "null_resource",
"name": "foo",
"provider_name": "registry.terraform.io/hashicorp/null",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"triggers": null
},
"after_unknown": {
"id": true
},
"before_sensitive": false,
"after_sensitive": {}
}
}
],
"relevant_attributes": [],
"output_changes": {},
"provider_schemas": {
"registry.terraform.io/hashicorp/null": {
"provider": {
"version": 0,
"block": {
"description_kind": "plain"
}
},
"resource_schemas": {
"null_resource": {
"version": 0,
"block": {
"attributes": {
"id": {
"type": "string",
"description": "This is set to a random value at create time.",
"description_kind": "plain",
"computed": true
},
"triggers": {
"type": [
"map",
"string"
],
"description": "A map of arbitrary strings that, when changed, will force the null resource to be replaced, re-running any associated provisioners.",
"description_kind": "plain",
"optional": true
}
},
"description": "The `null_resource` resource implements the standard resource lifecycle but takes no further action.\n\nThe `triggers` argument allows specifying an arbitrary set of values that, when changed, will cause the resource to be replaced.",
"description_kind": "plain"
}
}
},
"data_source_schemas": {
"null_data_source": {
"version": 0,
"block": {
"attributes": {
"has_computed_default": {
"type": "string",
"description": "If set, its literal value will be stored and returned. If not, its value defaults to `\"default\"`. This argument exists primarily for testing and has little practical use.",
"description_kind": "plain",
"optional": true,
"computed": true
},
"id": {
"type": "string",
"description": "This attribute is only present for some legacy compatibility issues and should not be used. It will be removed in a future version.",
"description_kind": "plain",
"deprecated": true,
"computed": true
},
"inputs": {
"type": [
"map",
"string"
],
"description": "A map of arbitrary strings that is copied into the `outputs` attribute, and accessible directly for interpolation.",
"description_kind": "plain",
"optional": true
},
"outputs": {
"type": [
"map",
"string"
],
"description": "After the data source is \"read\", a copy of the `inputs` map.",
"description_kind": "plain",
"computed": true
},
"random": {
"type": "string",
"description": "A random value. This is primarily for testing and has little practical use; prefer the [hashicorp/random provider](https://registry.terraform.io/providers/hashicorp/random) for more practical random number use-cases.",
"description_kind": "plain",
"computed": true
}
},
"description": "The `null_data_source` data source implements the standard data source lifecycle but does not\ninteract with any external APIs.\n\nHistorically, the `null_data_source` was typically used to construct intermediate values to re-use elsewhere in configuration. The\nsame can now be achieved using [locals](https://www.terraform.io/docs/language/values/locals.html).\n",
"description_kind": "plain",
"deprecated": true
}
}
}
}
},
"provider_format_version": "1.0"
}

0 comments on commit e6c0e7b

Please sign in to comment.