opentofu/internal/plans/planfile/config_snapshot_test.go
Martin Atkins 034e944070 Move plans/ to internal/plans/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

53 lines
1.1 KiB
Go

package planfile
import (
"archive/zip"
"bytes"
"path/filepath"
"reflect"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform/internal/configs/configload"
)
func TestConfigSnapshotRoundtrip(t *testing.T) {
fixtureDir := filepath.Join("testdata", "test-config")
loader, err := configload.NewLoader(&configload.Config{
ModulesDir: filepath.Join(fixtureDir, ".terraform", "modules"),
})
if err != nil {
t.Fatal(err)
}
_, snapIn, diags := loader.LoadConfigWithSnapshot(fixtureDir)
if diags.HasErrors() {
t.Fatal(diags.Error())
}
var buf bytes.Buffer
zw := zip.NewWriter(&buf)
err = writeConfigSnapshot(snapIn, zw)
if err != nil {
t.Fatalf("failed to write snapshot: %s", err)
}
zw.Close()
raw := buf.Bytes()
r := bytes.NewReader(raw)
zr, err := zip.NewReader(r, int64(len(raw)))
if err != nil {
t.Fatal(err)
}
snapOut, err := readConfigSnapshot(zr)
if err != nil {
t.Fatalf("failed to read snapshot: %s", err)
}
if !reflect.DeepEqual(snapIn, snapOut) {
t.Errorf("result does not match input\nresult: %sinput: %s", spew.Sdump(snapOut), spew.Sdump(snapIn))
}
}