Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for map[string]map[string]string protobuf conversion #510

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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