|
|
|
|
@ -5,23 +5,28 @@ package jsonprovider
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/terraform"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/providers"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMarshalProvider(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
Input *terraform.ProviderSchema
|
|
|
|
|
Input providers.Schemas
|
|
|
|
|
Want *Provider
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
nil,
|
|
|
|
|
&Provider{},
|
|
|
|
|
providers.Schemas{},
|
|
|
|
|
&Provider{
|
|
|
|
|
Provider: &Schema{},
|
|
|
|
|
ResourceSchemas: map[string]*Schema{},
|
|
|
|
|
DataSourceSchemas: map[string]*Schema{},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testProvider(),
|
|
|
|
|
@ -143,73 +148,78 @@ func TestMarshalProvider(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
got := marshalProvider(test.Input)
|
|
|
|
|
if !cmp.Equal(got, test.Want) {
|
|
|
|
|
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, test.Want))
|
|
|
|
|
}
|
|
|
|
|
for i, test := range tests {
|
|
|
|
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
|
|
|
|
got := marshalProvider(test.Input)
|
|
|
|
|
if !cmp.Equal(got, test.Want) {
|
|
|
|
|
t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, test.Want))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testProvider() *terraform.ProviderSchema {
|
|
|
|
|
return &terraform.ProviderSchema{
|
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"region": {Type: cty.String, Required: true},
|
|
|
|
|
func testProvider() providers.Schemas {
|
|
|
|
|
return providers.Schemas{
|
|
|
|
|
Provider: providers.Schema{
|
|
|
|
|
Block: &configschema.Block{
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"region": {Type: cty.String, Required: true},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
|
ResourceTypes: map[string]providers.Schema{
|
|
|
|
|
"test_instance": {
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"id": {Type: cty.String, Optional: true, Computed: true},
|
|
|
|
|
"ami": {Type: cty.String, Optional: true},
|
|
|
|
|
"volumes": {
|
|
|
|
|
Optional: true,
|
|
|
|
|
NestedType: &configschema.Object{
|
|
|
|
|
Nesting: configschema.NestingList,
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"size": {Type: cty.String, Required: true},
|
|
|
|
|
"mount_point": {Type: cty.String, Required: true},
|
|
|
|
|
Version: 42,
|
|
|
|
|
Block: &configschema.Block{
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"id": {Type: cty.String, Optional: true, Computed: true},
|
|
|
|
|
"ami": {Type: cty.String, Optional: true},
|
|
|
|
|
"volumes": {
|
|
|
|
|
Optional: true,
|
|
|
|
|
NestedType: &configschema.Object{
|
|
|
|
|
Nesting: configschema.NestingList,
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"size": {Type: cty.String, Required: true},
|
|
|
|
|
"mount_point": {Type: cty.String, Required: 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},
|
|
|
|
|
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},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
DataSources: map[string]*configschema.Block{
|
|
|
|
|
DataSources: map[string]providers.Schema{
|
|
|
|
|
"test_data_source": {
|
|
|
|
|
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},
|
|
|
|
|
Version: 3,
|
|
|
|
|
Block: &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},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
ResourceTypeSchemaVersions: map[string]uint64{
|
|
|
|
|
"test_instance": 42,
|
|
|
|
|
"test_data_source": 3,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|