providers/docker: synced folder usable? raises error, tests

/cc @fgrehm
This commit is contained in:
Mitchell Hashimoto 2014-04-10 08:57:59 -07:00
parent 2e13feb130
commit ab2cae2379
4 changed files with 56 additions and 8 deletions

View File

@ -1,12 +1,21 @@
module VagrantPlugins
module DockerProvider
module Errors
class ImageNotConfiguredError < Vagrant::Errors::VagrantError
class DockerError < Vagrant::Errors::VagrantError
error_namespace("docker_provider.errors")
end
class ImageNotConfiguredError < DockerError
error_key(:docker_provider_image_not_configured)
end
class NfsWithoutPrivilegedError < Vagrant::Errors::VagrantError
class NfsWithoutPrivilegedError < DockerError
error_key(:docker_provider_nfs_without_privileged)
end
class SyncedFolderNonDocker < DockerError
error_key(:synced_folder_non_docker)
end
end
end
end

View File

@ -1,9 +1,18 @@
module VagrantPlugins
module DockerProvider
class SyncedFolder < Vagrant.plugin("2", :synced_folder)
def usable?(machine)
def usable?(machine, raise_error=false)
# These synced folders only work if the provider is Docker
machine.provider_name == :docker
if machine.provider_name != :docker
if raise_error
raise Errors::SyncedFolderNonDocker,
provider: machine.provider_name.to_s
end
return false
end
true
end
def prepare(machine, folders, _opts)

View File

@ -18,14 +18,14 @@ en:
config:
cmd_not_set: |-
The Docker command has not been set!
vagrant:
errors:
docker_provider_nfs_without_privileged: |-
You've configured a NFS synced folder but didn't enable privileged
mode for the container. Please set the `privileged` option to true
on the provider block from your Vagrantfile, recreate the container
and try again.
docker_provider_image_not_configured: |-
The base Docker image has not been set for the '%{name}' VM!
synced_folder_non_docker: |-
The "docker" synced folder type can't be used because the provider
in use is not Docker. This synced folder type only works with the
Docker provider. The provider this machine is using is: %{provider}

View File

@ -0,0 +1,30 @@
require_relative "../../../base"
require Vagrant.source_root.join("plugins/providers/docker/synced_folder")
describe VagrantPlugins::DockerProvider::SyncedFolder do
subject { described_class.new }
describe "#usable?" do
let(:machine) { double("machine") }
before do
machine.stub(provider_name: :docker)
end
it "is usable" do
expect(subject).to be_usable(machine)
end
it "is not usable if provider isn't docker" do
machine.stub(provider_name: :virtualbox)
expect(subject).to_not be_usable(machine)
end
it "raises an error if bad provider if specified" do
machine.stub(provider_name: :virtualbox)
expect { subject.usable?(machine, true) }.
to raise_error(VagrantPlugins::DockerProvider::Errors::SyncedFolderNonDocker)
end
end
end