diff --git a/plugins/commands/serve/mappers/known_types.rb b/plugins/commands/serve/mappers/known_types.rb index 42d5af9a1..de09692fb 100644 --- a/plugins/commands/serve/mappers/known_types.rb +++ b/plugins/commands/serve/mappers/known_types.rb @@ -77,7 +77,10 @@ module VagrantPlugins def converter(proto, mapper) begin proto.list.map do |v| - mapper.map(v) + r = mapper.map(v) + # unwrap any wrapper classes here before assigning + r = r.value if r.is_a?(Type) + r end rescue => err logger.error("proto mapping to array failed: #{err}") @@ -169,6 +172,8 @@ module VagrantPlugins Hash.new.tap do |result| proto.fields.each do |k, v| r = mapper.map(v) + # unwrap any wrapper classes here before assigning + r = r.value if r.is_a?(Type) result[k.to_sym] = r end end diff --git a/test/unit/plugins/commands/serve/mappers_test.rb b/test/unit/plugins/commands/serve/mappers_test.rb new file mode 100644 index 000000000..951bfb381 --- /dev/null +++ b/test/unit/plugins/commands/serve/mappers_test.rb @@ -0,0 +1,39 @@ +require File.expand_path("../../../base", __dir__) + +require Vagrant.source_root.join("plugins/commands/serve/command") + +describe VagrantPlugins::CommandServe::Mappers do + include_context "unit" + + subject { described_class.new } + + context "Hash" do + it "unwraps wrapper types when they show up in the Hash" do + input = Hashicorp::Vagrant::Sdk::Args::Hash.new( + fields: { + "error_check" => Google::Protobuf::Any.pack( + Google::Protobuf::BoolValue.new(value: false) + ) + } + ) + output = subject.map(input, to: Hash) + + expect(output).to eq({error_check: false}) + end + end + + context "Array" do + it "unwraps wrapper types when they show up in the Array" do + input = Hashicorp::Vagrant::Sdk::Args::Array.new( + list: [ + Google::Protobuf::Any.pack( + Google::Protobuf::BoolValue.new(value: false) + ), + ], + ) + output = subject.map(input, to: Array) + + expect(output).to eq([false]) + end + end +end