mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
31349a9c3a
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.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package jsonprovider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
)
|
|
|
|
func TestMarshalBlock(t *testing.T) {
|
|
tests := []struct {
|
|
Input *configschema.Block
|
|
Want *block
|
|
}{
|
|
{
|
|
nil,
|
|
&block{},
|
|
},
|
|
{
|
|
Input: &configschema.Block{
|
|
Attributes: map[string]*configschema.Attribute{
|
|
"id": {Type: cty.String, Optional: true, Computed: true},
|
|
"ami": {Type: cty.String, Optional: true},
|
|
},
|
|
BlockTypes: map[string]*configschema.NestedBlock{
|
|
"network_interface": {
|
|
Nesting: configschema.NestingList,
|
|
Block: configschema.Block{
|
|
Attributes: map[string]*configschema.Attribute{
|
|
"device_index": {Type: cty.String, Optional: true},
|
|
"description": {Type: cty.String, Optional: true},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Want: &block{
|
|
Attributes: map[string]*attribute{
|
|
"ami": {AttributeType: json.RawMessage(`"string"`), Optional: true, DescriptionKind: "plain"},
|
|
"id": {AttributeType: json.RawMessage(`"string"`), Optional: true, Computed: true, DescriptionKind: "plain"},
|
|
},
|
|
BlockTypes: map[string]*blockType{
|
|
"network_interface": {
|
|
NestingMode: "list",
|
|
Block: &block{
|
|
Attributes: map[string]*attribute{
|
|
"description": {AttributeType: json.RawMessage(`"string"`), Optional: true, DescriptionKind: "plain"},
|
|
"device_index": {AttributeType: json.RawMessage(`"string"`), Optional: true, DescriptionKind: "plain"},
|
|
},
|
|
DescriptionKind: "plain",
|
|
},
|
|
},
|
|
},
|
|
DescriptionKind: "plain",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
got := marshalBlock(test.Input)
|
|
if !cmp.Equal(got, test.Want) {
|
|
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, test.Want))
|
|
}
|
|
}
|
|
}
|