Test has capability
This commit is contained in:
parent
04222f0eb6
commit
434e613856
@ -102,7 +102,7 @@ module VagrantPlugins
|
||||
ServiceInfo.with_info(ctx) do |info|
|
||||
cap_name = req.args.detect { |a|
|
||||
a.type == "hashicorp.vagrant.sdk.Args.NamedCapability"
|
||||
}&.value&.value.strip.gsub("\b", "")
|
||||
}&.value&.value.strip.gsub("\b", "").gsub("\x05", "")
|
||||
plugin_name = info.plugin_name
|
||||
LOGGER.debug("checking for #{cap_name} capability in #{plugin_name}")
|
||||
|
||||
|
||||
@ -112,4 +112,65 @@ describe VagrantPlugins::CommandServe::Service::GuestService do
|
||||
expect(d.detected).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "requesting has capability" do
|
||||
before do
|
||||
cap_guest = Class.new(Vagrant.plugin("2", :guest)) do
|
||||
def detect?(machine)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
register_plugin do |p|
|
||||
p.guest(:cap_guest) { cap_guest }
|
||||
p.guest_capability(:cap_guest, :mycap) do
|
||||
"this is a capability"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
let(:named_cap_request){
|
||||
Hashicorp::Vagrant::Sdk::FuncSpec::Args.new(
|
||||
args: [
|
||||
Hashicorp::Vagrant::Sdk::FuncSpec::Value.new(
|
||||
name: "",
|
||||
type: "hashicorp.vagrant.sdk.Args.NamedCapability",
|
||||
value: Google::Protobuf::Any.pack(Hashicorp::Vagrant::Sdk::Args::NamedCapability.new(Capability:"mycap")))
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
let(:named_cap_bad_request){
|
||||
Hashicorp::Vagrant::Sdk::FuncSpec::Args.new(
|
||||
args: [
|
||||
Hashicorp::Vagrant::Sdk::FuncSpec::Value.new(
|
||||
name: "",
|
||||
type: "hashicorp.vagrant.sdk.Args.NamedCapability",
|
||||
value: Google::Protobuf::Any.pack(Hashicorp::Vagrant::Sdk::Args::NamedCapability.new(Capability:"notacapability")))
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
it "generates a spec" do
|
||||
spec = subject.has_capability_spec
|
||||
expect(spec).not_to be_nil
|
||||
end
|
||||
|
||||
it "raises an error for unknown plugins" do
|
||||
ctx = DummyContext.new("idontexisthahaha")
|
||||
expect { subject.has_capability(test_cap_name, ctx) }.to raise_error
|
||||
end
|
||||
|
||||
it "returns true for plugin with capability" do
|
||||
ctx = DummyContext.new("cap_guest")
|
||||
d = subject.has_capability(named_cap_request, ctx)
|
||||
expect(d.has_capability).to be true
|
||||
end
|
||||
|
||||
it "returns false for plugin without capability" do
|
||||
ctx = DummyContext.new("cap_guest")
|
||||
d = subject.has_capability(named_cap_bad_request, ctx)
|
||||
expect(d.has_capability).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user