mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Cloud: Split private readRedactedPlan func into two
Since `terraform show -json` needs to get a raw hunk of json bytes and sling it right back out again, it's going to be more convenient if plain `show` can ALSO take in raw json. In order for that to happen, I need a function that basically acts like `client.Plans.ReadJSONOutput()`, without eagerly unmarshalling that `jsonformat.Plan` struct. As a slight bonus, this also lets us make the tfe client mocks slightly stupider.
This commit is contained in:
committed by
Sebastian Rivera
parent
0df3c143bb
commit
2a08a5b46e
@@ -7,7 +7,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -22,7 +21,6 @@ import (
|
||||
tfe "github.com/hashicorp/go-tfe"
|
||||
"github.com/mitchellh/copystructure"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/command/jsonformat"
|
||||
tfversion "github.com/hashicorp/terraform/version"
|
||||
)
|
||||
|
||||
@@ -468,13 +466,13 @@ func (m *MockOrganizations) ReadRunQueue(ctx context.Context, name string, optio
|
||||
|
||||
type MockRedactedPlans struct {
|
||||
client *MockClient
|
||||
redactedPlans map[string]*jsonformat.Plan
|
||||
redactedPlans map[string][]byte
|
||||
}
|
||||
|
||||
func newMockRedactedPlans(client *MockClient) *MockRedactedPlans {
|
||||
return &MockRedactedPlans{
|
||||
client: client,
|
||||
redactedPlans: make(map[string]*jsonformat.Plan),
|
||||
redactedPlans: make(map[string][]byte),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,23 +493,17 @@ func (m *MockRedactedPlans) create(cvID, workspaceID, planID string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadAll(redactedPlanFile)
|
||||
raw, err := io.ReadAll(redactedPlanFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
redactedPlan := &jsonformat.Plan{}
|
||||
err = json.Unmarshal(raw, redactedPlan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.redactedPlans[planID] = redactedPlan
|
||||
m.redactedPlans[planID] = raw
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockRedactedPlans) Read(ctx context.Context, hostname, token, planID string) (*jsonformat.Plan, error) {
|
||||
func (m *MockRedactedPlans) Read(ctx context.Context, hostname, token, planID string) ([]byte, error) {
|
||||
if p, ok := m.redactedPlans[planID]; ok {
|
||||
return p, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user