Skip to content

Commit 57640b9

Browse files
committed
jsonstate: Test identity marshalling
1 parent 3992140 commit 57640b9

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

internal/command/jsonstate/state_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,54 @@ func TestMarshalResources(t *testing.T) {
620620
},
621621
false,
622622
},
623+
"single resource_with_identity": {
624+
map[string]*states.Resource{
625+
"test_identity.baz": {
626+
Addr: addrs.AbsResource{
627+
Resource: addrs.Resource{
628+
Mode: addrs.ManagedResourceMode,
629+
Type: "test_identity",
630+
Name: "bar",
631+
},
632+
},
633+
Instances: map[addrs.InstanceKey]*states.ResourceInstance{
634+
addrs.NoKey: {
635+
Current: &states.ResourceInstanceObjectSrc{
636+
Status: states.ObjectReady,
637+
AttrsJSON: []byte(`{"woozles":"confuzles","foozles":"sensuzles","name":"bar"}`),
638+
IdentityJSON: []byte(`{"foozles":"sensuzles","name":"bar"}`),
639+
},
640+
},
641+
},
642+
ProviderConfig: addrs.AbsProviderConfig{
643+
Provider: addrs.NewDefaultProvider("test"),
644+
Module: addrs.RootModule,
645+
},
646+
},
647+
},
648+
testSchemas(),
649+
[]Resource{
650+
{
651+
Address: "test_identity.bar",
652+
Mode: "managed",
653+
Type: "test_identity",
654+
Name: "bar",
655+
Index: nil,
656+
ProviderName: "registry.terraform.io/hashicorp/test",
657+
AttributeValues: AttributeValues{
658+
"name": json.RawMessage(`"bar"`),
659+
"foozles": json.RawMessage(`"sensuzles"`),
660+
"woozles": json.RawMessage(`"confuzles"`),
661+
},
662+
SensitiveValues: json.RawMessage("{\"foozles\":true}"),
663+
IdentityValues: IdentityValues{
664+
"name": json.RawMessage(`"bar"`),
665+
"foozles": json.RawMessage(`"sensuzles"`),
666+
},
667+
},
668+
},
669+
false,
670+
},
623671
}
624672

625673
for name, test := range tests {
@@ -867,6 +915,22 @@ func testSchemas() *terraform.Schemas {
867915
},
868916
},
869917
},
918+
"test_identity": {
919+
Body: &configschema.Block{
920+
Attributes: map[string]*configschema.Attribute{
921+
"name": {Type: cty.String, Required: true},
922+
"woozles": {Type: cty.String, Optional: true, Computed: true},
923+
"foozles": {Type: cty.String, Optional: true, Sensitive: true},
924+
},
925+
},
926+
Identity: &configschema.Object{
927+
Attributes: map[string]*configschema.Attribute{
928+
"name": {Type: cty.String, Required: true},
929+
"foozles": {Type: cty.String, Optional: true},
930+
},
931+
Nesting: configschema.NestingSingle,
932+
},
933+
},
870934
},
871935
},
872936
},

0 commit comments

Comments
 (0)