From 5d2d784ae79940f92a243a43f52a9bbe0c5afdfd Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 8 Aug 2018 10:30:04 -0700 Subject: [PATCH] (#9085) - Add test for converting windows paths This commit adds a test for checking that a windows path for mounting a volume in a container is properly converted into something that's usable. --- plugins/providers/docker/driver.rb | 14 +++++----- .../plugins/providers/docker/driver_test.rb | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index cf3149429..88903039c 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -55,14 +55,14 @@ module VagrantPlugins host, colon, guest = v.rpartition(":") host = "//" + host[0].downcase + host[2..-1] v = [host, guest].join(":") - else + else host, guest = v.split(":", 2) - host = Vagrant::Util::Platform.windows_path(host) - # NOTE: Docker does not support UNC style paths (which also - # means that there's no long path support). Hopefully this - # will be fixed someday and the gsub below can be removed. - host.gsub!(/^[^A-Za-z]+/, "") - v = [host, guest].join(":") + host = Vagrant::Util::Platform.windows_path(host) + # NOTE: Docker does not support UNC style paths (which also + # means that there's no long path support). Hopefully this + # will be fixed someday and the gsub below can be removed. + host.gsub!(/^[^A-Za-z]+/, "") + v = [host, guest].join(":") end end diff --git a/test/unit/plugins/providers/docker/driver_test.rb b/test/unit/plugins/providers/docker/driver_test.rb index 0d12b4971..1b871299a 100644 --- a/test/unit/plugins/providers/docker/driver_test.rb +++ b/test/unit/plugins/providers/docker/driver_test.rb @@ -65,6 +65,33 @@ describe VagrantPlugins::DockerProvider::Driver do end end + describe '#create windows' do + let(:params) { { + image: 'jimi/hendrix:eletric-ladyland', + cmd: ['play', 'voodoo-chile'], + ports: '8080:80', + volumes: 'C:/Users/BobDylan/AllAlong:/The/Watchtower', + detach: true, + links: [[:janis, 'joplin'], [:janis, 'janis']], + env: {key: 'value'}, + name: cid, + hostname: 'jimi-hendrix', + privileged: true + } } + + let(:translated_path) { "//c/Users/BobDylan/AllAlong:/The/Watchtower" } + + before do + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) + subject.create(params) + end + + it 'shares folders' do + expect(cmd_executed).to match(/-v #{translated_path} .+ #{Regexp.escape params[:image]}/) + end + end + + describe '#created?' do let(:result) { subject.created?(cid) }