mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
Move command/ to internal/command/
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.
This commit is contained in:
212
internal/command/jsonprovider/provider_test.go
Normal file
212
internal/command/jsonprovider/provider_test.go
Normal file
@@ -0,0 +1,212 @@
|
||||
package jsonprovider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/zclconf/go-cty/cty"
|
||||
|
||||
"github.com/hashicorp/terraform/configs/configschema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestMarshalProvider(t *testing.T) {
|
||||
tests := []struct {
|
||||
Input *terraform.ProviderSchema
|
||||
Want *Provider
|
||||
}{
|
||||
{
|
||||
nil,
|
||||
&Provider{},
|
||||
},
|
||||
{
|
||||
testProvider(),
|
||||
&Provider{
|
||||
Provider: &schema{
|
||||
Block: &block{
|
||||
Attributes: map[string]*attribute{
|
||||
"region": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Required: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
ResourceSchemas: map[string]*schema{
|
||||
"test_instance": {
|
||||
Version: 42,
|
||||
Block: &block{
|
||||
Attributes: map[string]*attribute{
|
||||
"id": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"ami": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"volumes": {
|
||||
AttributeNestedType: &nestedType{
|
||||
NestingMode: "list",
|
||||
Attributes: map[string]*attribute{
|
||||
"size": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Required: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"mount_point": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Required: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
},
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
BlockTypes: map[string]*blockType{
|
||||
"network_interface": {
|
||||
Block: &block{
|
||||
Attributes: map[string]*attribute{
|
||||
"device_index": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"description": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
NestingMode: "list",
|
||||
},
|
||||
},
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
},
|
||||
DataSourceSchemas: map[string]*schema{
|
||||
"test_data_source": {
|
||||
Version: 3,
|
||||
Block: &block{
|
||||
Attributes: map[string]*attribute{
|
||||
"id": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"ami": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
BlockTypes: map[string]*blockType{
|
||||
"network_interface": {
|
||||
Block: &block{
|
||||
Attributes: map[string]*attribute{
|
||||
"device_index": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
"description": {
|
||||
AttributeType: json.RawMessage(`"string"`),
|
||||
Optional: true,
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
NestingMode: "list",
|
||||
},
|
||||
},
|
||||
DescriptionKind: "plain",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testProvider() *terraform.ProviderSchema {
|
||||
return &terraform.ProviderSchema{
|
||||
Provider: &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"region": {Type: cty.String, Required: true},
|
||||
},
|
||||
},
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
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{
|
||||
"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},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
ResourceTypeSchemaVersions: map[string]uint64{
|
||||
"test_instance": 42,
|
||||
"test_data_source": 3,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user