insert "github.com/zclconf/go-cty/cty/json" encoding beforce hcl decoding things to make sure tests are working similarly as real life version

This commit is contained in:
Adrien Delorme 2020-02-17 15:53:05 +01:00
parent 1ec68cac23
commit 00c812cfe8
1 changed files with 18 additions and 0 deletions

View File

@ -6,9 +6,12 @@ import (
"context"
"time"
"github.com/zclconf/go-cty/cty/json"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/packer"
"github.com/zclconf/go-cty/cty"
)
type NestedMockConfig struct {
@ -33,6 +36,21 @@ type MockConfig struct {
}
func (b *MockConfig) Prepare(raws ...interface{}) error {
for i, raw := range raws {
cval, ok := raw.(cty.Value)
if !ok {
continue
}
b, err := json.Marshal(cval, cty.DynamicPseudoType)
if err != nil {
return err
}
ccval, err := json.Unmarshal(b, cty.DynamicPseudoType)
if err != nil {
return err
}
raws[i] = ccval
}
return config.Decode(b, &config.DecodeOpts{
Interpolate: true,
}, raws...)