Paul Hinze 8730b9f100
Fix MachineState mapper so IsRunning actions work
The IsRunning action checks if `env[:machine].state.id == :running` but
this check was never passing as the protobuf-washed version of machine
state was yielding a machine state w/ a string value like `"running"`.

Easy fix in the mapper!
2022-04-25 12:26:34 -05:00

51 lines
1.3 KiB
Ruby

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
context "MachineState" do
it "yields an id that's a symbol, not a string" do
input = Hashicorp::Vagrant::Sdk::Args::Target::Machine::State.new(
id: "running",
)
output = subject.map(input, to: Vagrant::MachineState)
expect(output.id).to eq(:running)
end
end
end