"Fossies" - the Fresh Open Source Software Archive 
Member "vagrant-2.2.14/test/unit/plugins/guests/darwin/cap/mount_vmware_shared_folder_test.rb" (20 Nov 2020, 7820 Bytes) of package /linux/misc/vagrant-2.2.14.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "mount_vmware_shared_folder_test.rb":
2.2.13_vs_2.2.14.
1 require_relative "../../../../base"
2
3 describe "VagrantPlugins::GuestDarwin::Cap::MountVmwareSharedFolder" do
4 let(:described_class) do
5 VagrantPlugins::GuestDarwin::Plugin
6 .components
7 .guest_capabilities[:darwin]
8 .get(:mount_vmware_shared_folder)
9 end
10
11 let(:machine) { double("machine", communicate: communicator, id: "MACHINE_ID", guest: guest) }
12 let(:guest) {double("guest")}
13 let(:communicator) { double("communicator") }
14
15 before do
16 allow(communicator).to receive(:test)
17 allow(communicator).to receive(:sudo)
18 allow(VagrantPlugins::GuestDarwin::Plugin).to receive(:action_hook)
19 end
20
21 describe ".mount_vmware_shared_folder" do
22 let(:name) { "-vagrant" }
23 let(:guestpath) { "/vagrant" }
24 let(:options) { {} }
25
26 before do
27 allow(described_class).to receive(:system_firmlink?)
28 described_class.reset!
29 end
30
31 after {
32 described_class.mount_vmware_shared_folder(machine, name, guestpath, options)
33 }
34
35 context "with APFS root container" do
36 before do
37 expect(communicator).to receive(:test).with("test -d /System/Volumes/Data").and_return(true)
38 end
39
40 it "should check for existing entry" do
41 expect(communicator).to receive(:test).with(/synthetic\.conf/)
42 end
43
44 context "with guest path within existing directory" do
45 let(:guestpath) { "/Users/vagrant/workspace" }
46
47 it "should test if guest path is a symlink" do
48 expect(communicator).to receive(:test).with(/test -L/)
49 end
50
51 it "should remove guest path if it is a symlink" do
52 expect(communicator).to receive(:test).with(/test -L/).and_return(true)
53 expect(communicator).to receive(:sudo).with(/rm -f/)
54 end
55
56 it "should not test if guest path is a directory if guest path is symlink" do
57 expect(communicator).to receive(:test).with(/test -L/).and_return(true)
58 expect(communicator).not_to receive(:test).with(/test -d/)
59 end
60
61 it "should test if guest path is directory if not a symlink" do
62 expect(communicator).to receive(:test).with(/test -d/)
63 end
64
65 it "should remove guest path if it is a directory" do
66 expect(communicator).to receive(:test).with(/test -d/).and_return(true)
67 expect(communicator).to receive(:sudo).with(/rm -Rf/)
68 end
69
70 it "should create the symlink to the vmware folder" do
71 expect(communicator).to receive(:sudo).with(/ln -s/)
72 end
73
74 it "should create the symlink within the writable APFS container" do
75 expect(communicator).to receive(:sudo).with(%r{ln -s .+/System/Volumes/Data.+})
76 end
77
78 {
79 19 => "-B",
80 20 => "-t",
81 21 => "-t",
82 nil => "-B"
83 }.each do |version, expected_flag|
84 it "should re-bootstrap root dir for darwin version #{version}" do
85 expect(communicator).to receive(:sudo).with(/apfs.util #{expected_flag}/, any_args)
86 expect(guest).to receive(:capability).with("darwin_major_version").and_return(version)
87
88 described_class.mount_vmware_shared_folder(machine, name, guestpath, options)
89 described_class.apfs_firmlinks_delayed[machine.id].call
90 end
91 end
92
93 context "when firmlink is provided by the system" do
94 before { expect(described_class).to receive(:system_firmlink?).and_return(true) }
95
96 it "should not register an action hook" do
97 expect(VagrantPlugins::GuestDarwin::Plugin).not_to receive(:action_hook).with(:apfs_firmlinks, :after_synced_folders)
98 end
99 end
100 end
101 end
102
103 context "with non-APFS root container" do
104 before do
105 expect(communicator).to receive(:test).with("test -d /System/Volumes/Data").and_return(false)
106 end
107
108 it "should test if guest path is a symlink" do
109 expect(communicator).to receive(:test).with(/test -L/)
110 end
111
112 it "should remove guest path if it is a symlink" do
113 expect(communicator).to receive(:test).with(/test -L/).and_return(true)
114 expect(communicator).to receive(:sudo).with(/rm -f/)
115 end
116
117 it "should not test if guest path is a directory if guest path is symlink" do
118 expect(communicator).to receive(:test).with(/test -L/).and_return(true)
119 expect(communicator).not_to receive(:test).with(/test -d/)
120 end
121
122 it "should test if guest path is directory if not a symlink" do
123 expect(communicator).to receive(:test).with(/test -d/)
124 end
125
126 it "should remove guest path if it is a directory" do
127 expect(communicator).to receive(:test).with(/test -d/).and_return(true)
128 expect(communicator).to receive(:sudo).with(/rm -Rf/)
129 end
130
131 it "should create the symlink to the vmware folder" do
132 expect(communicator).to receive(:sudo).with(/ln -s/)
133 end
134
135 it "should not register an action hook" do
136 expect(VagrantPlugins::GuestDarwin::Plugin).not_to receive(:action_hook).with(:apfs_firmlinks, :after_synced_folders)
137 end
138 end
139 end
140
141 describe ".system_firmlink?" do
142 before { described_class.reset! }
143
144 context "when file does not exist" do
145 before { allow(File).to receive(:exist?).with("/usr/share/firmlinks").and_return(false) }
146
147 it "should always return false" do
148 expect(described_class.system_firmlink?("test")).to be_falsey
149 end
150 end
151
152 context "when file does exist" do
153 let(:content) {
154 ["/Users\tUsers",
155 "/usr/local\tusr/local"]
156 }
157
158 before do
159 expect(File).to receive(:exist?).with("/usr/share/firmlinks").and_return(true)
160 expect(File).to receive(:readlines).with("/usr/share/firmlinks").and_return(content)
161 end
162
163 it "should return true when firmlink exists" do
164 expect(described_class.system_firmlink?("/Users")).to be_truthy
165 end
166
167 it "should return true when firmlink is not prefixed with /" do
168 expect(described_class.system_firmlink?("Users")).to be_truthy
169 end
170
171 it "should return false when firmlink does not exist" do
172 expect(described_class.system_firmlink?("/testing")).to be_falsey
173 end
174 end
175 end
176
177 describe ".write_apfs_firmlinks" do
178 let(:env) { nil }
179 let(:action) { double("action", call: nil) }
180 let(:machine) { double("machine", id: machine_id) }
181 let(:machine_id) { double("machine_id") }
182 let(:delayed) { {} }
183
184 context "when env is nil" do
185 it "should be a no-op" do
186 expect(described_class).not_to receive(:apfs_firmlinks_delayed)
187 described_class.write_apfs_firmlinks(env)
188 end
189 end
190
191 context "when env is empty hash" do
192 let(:env) { {} }
193
194 it "should be a no-op" do
195 expect(described_class).not_to receive(:apfs_firmlinks_delayed)
196 described_class.write_apfs_firmlinks(env)
197 end
198 end
199
200 context "when machine is defined within env" do
201 let(:env) { {machine: machine} }
202
203 it "should request the stored delayed actions" do
204 expect(described_class).to receive(:apfs_firmlinks_delayed).and_return(delayed)
205 described_class.write_apfs_firmlinks(env)
206 end
207 end
208
209 context "when delayed action is stored for machine" do
210 let(:env) { {machine: machine} }
211
212 before { described_class.apfs_firmlinks_delayed[machine_id] = action }
213 after { described_class.apfs_firmlinks_delayed.clear }
214
215 it "should call the delayed action" do
216 expect(action).to receive(:call)
217 described_class.write_apfs_firmlinks(env)
218 end
219
220 it "should remove the action after calling" do
221 expect(action).to receive(:call)
222 described_class.write_apfs_firmlinks(env)
223 expect(delayed).to be_empty
224 end
225 end
226 end
227 end