File: synced_folder_test.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (74 lines) | stat: -rw-r--r-- 2,937 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require_relative "../../../base"

require Vagrant.source_root.join("plugins/providers/docker/synced_folder")

describe VagrantPlugins::DockerProvider::SyncedFolder do
  subject { described_class.new }

  let(:provider_config) { double("provider_config", volumes: []) }
  let(:machine) { double("machine") }

  before do
    allow(machine).to receive(:provider_name).and_return(:docker)
    allow(machine).to receive(:provider_config).and_return(provider_config)
  end

  describe "#usable?" do
    it "is usable" do
      expect(subject).to be_usable(machine)
    end

    it "is not usable if provider isn't docker" do
      allow(machine).to receive(:provider_name).and_return(:virtualbox)
      expect(subject).to_not be_usable(machine)
    end

    it "raises an error if bad provider if specified" do
      allow(machine).to receive(:provider_name).and_return(:virtualbox)
      expect { subject.usable?(machine, true) }.
        to raise_error(VagrantPlugins::DockerProvider::Errors::SyncedFolderNonDocker)
    end
  end

  describe "#prepare" do
    let(:folders) {{"/guest/dir1"=>
                    {:guestpath=>"/guest/dir1",
                     :hostpath=>"/Users/brian/code/vagrant-sandbox",
                     :disabled=>false,
                     :__vagrantfile=>true},
                     "/dev/vagrant"=>
                    {:guestpath=>"/dev/vagrant",
                     :hostpath=>"/Users/brian/code/vagrant",
                     :disabled=>false,
                     :__vagrantfile=>true}}}

    let(:consistency_folders) {{"/guest/dir1"=>
                                {:docker_consistency=>"cached",
                                 :guestpath=>"/guest/dir1",
                                 :hostpath=>"/Users/brian/code/vagrant-sandbox",
                                 :disabled=>false,
                                 :__vagrantfile=>true},
                                 "/dev/vagrant"=>
                                {:docker_consistency=>"delegated",
                                 :guestpath=>"/dev/vagrant",
                                 :hostpath=>"/Users/brian/code/vagrant",
                                 :disabled=>false,
                                 :__vagrantfile=>true}}}
    let(:options) { {} }

    let(:volumes) { ["/Users/brian/code/vagrant-sandbox:/guest/dir1",
                     "/Users/brian/code/vagrant:/dev/vagrant"] }
    let(:consistency_volumes) { ["/Users/brian/code/vagrant-sandbox:/guest/dir1:cached",
                                 "/Users/brian/code/vagrant:/dev/vagrant:delegated"] }

    it "prepares folders to mount" do
      subject.prepare(machine, folders, options)
      expect(machine.provider_config.volumes).to eq(volumes)
    end

    it "sets volume consistency if specified" do
      subject.prepare(machine, consistency_folders, options)
      expect(machine.provider_config.volumes).to eq(consistency_volumes)
    end
  end
end