github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonprovider/attribute_test.go (about) 1 package jsonprovider 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/google/go-cmp/cmp" 8 "github.com/zclconf/go-cty/cty" 9 10 "github.com/hashicorp/terraform/internal/configs/configschema" 11 ) 12 13 func TestMarshalAttribute(t *testing.T) { 14 tests := []struct { 15 Input *configschema.Attribute 16 Want *Attribute 17 }{ 18 { 19 &configschema.Attribute{Type: cty.String, Optional: true, Computed: true}, 20 &Attribute{ 21 AttributeType: json.RawMessage(`"string"`), 22 Optional: true, 23 Computed: true, 24 DescriptionKind: "plain", 25 }, 26 }, 27 { // collection types look a little odd. 28 &configschema.Attribute{Type: cty.Map(cty.String), Optional: true, Computed: true}, 29 &Attribute{ 30 AttributeType: json.RawMessage(`["map","string"]`), 31 Optional: true, 32 Computed: true, 33 DescriptionKind: "plain", 34 }, 35 }, 36 } 37 38 for _, test := range tests { 39 got := marshalAttribute(test.Input) 40 if !cmp.Equal(got, test.Want) { 41 t.Fatalf("wrong result:\n %v\n", cmp.Diff(got, test.Want)) 42 } 43 } 44 }