Skip to content

Commit

Permalink
Added support for map[string]map[string]string protobuf conversion (#510
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jmwilliams89 authored Dec 15, 2021
1 parent 1ca402f commit 3140581
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions operator/builtin/output/googlecloud/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ func toProto(v interface{}) (*structpb.Value, error) {
for key, value := range v {
fields[key] = structpb.NewStringValue(value)
}
return structpb.NewStructValue(&structpb.Struct{
Fields: fields,
}), nil
case map[string]map[string]string:
fields := map[string]*structpb.Value{}
for key, value := range v {
proto, err := toProto(value)
if err != nil {
return nil, err
}

fields[key] = proto
}

return structpb.NewStructValue(&structpb.Struct{
Fields: fields,
}), nil
Expand Down
17 changes: 17 additions & 0 deletions operator/builtin/output/googlecloud/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ func TestToProto(t *testing.T) {
},
}),
},
{
name: "map[string]map[string]string",
value: map[string]map[string]string{
"test": {
"key": "value",
},
},
expectedValue: structpb.NewStructValue(&structpb.Struct{
Fields: map[string]*structpb.Value{
"test": structpb.NewStructValue(&structpb.Struct{
Fields: map[string]*structpb.Value{
"key": structpb.NewStringValue("value"),
},
}),
},
}),
},
{
name: "interface list",
value: []interface{}{"value", 1},
Expand Down

0 comments on commit 3140581

Please sign in to comment.