vagrant-dsc 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -13
- data/development/Vagrantfile +34 -5
- data/development/manifests/{ContosoWebsite.ps1 → MyWebsite.ps1} +1 -1
- data/lib/vagrant-dsc/config.rb +93 -42
- data/lib/vagrant-dsc/locales/en.yml +6 -0
- data/lib/vagrant-dsc/plugin.rb +2 -2
- data/lib/vagrant-dsc/provisioner.rb +73 -26
- data/lib/vagrant-dsc/templates/runner.ps1.erb +18 -10
- data/lib/vagrant-dsc/version.rb +1 -1
- data/spec/base.rb +48 -51
- data/spec/provisioner/config_spec.rb +107 -249
- data/spec/provisioner/provisioner_spec.rb +394 -34
- data/spec/spec_helper.rb +4 -1
- data/vagrant-dsc.gemspec +7 -7
- metadata +62 -20
data/spec/base.rb
CHANGED
@@ -1,57 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
require "vagrant"
|
11
|
-
require "vagrant/util/platform"
|
12
|
-
|
13
|
-
# Add the test directory to the load path
|
14
|
-
$:.unshift File.expand_path("../../", __FILE__)
|
15
|
-
|
16
|
-
# Load in helpers
|
17
|
-
require "vagrant/unit/support/dummy_communicator"
|
18
|
-
require "vagrant/unit/support/dummy_provider"
|
19
|
-
require "vagrant/unit/support/shared/base_context"
|
20
|
-
require "vagrant/unit/support/shared/action_synced_folders_context"
|
21
|
-
require "vagrant/unit/support/shared/capability_helpers_context"
|
22
|
-
require "vagrant/unit/support/shared/plugin_command_context"
|
23
|
-
require "vagrant/unit/support/shared/virtualbox_context"
|
24
|
-
|
25
|
-
# Do not buffer output
|
26
|
-
$stdout.sync = true
|
27
|
-
$stderr.sync = true
|
28
|
-
|
29
|
-
# Configure RSpec
|
30
|
-
RSpec.configure do |c|
|
31
|
-
c.expect_with :rspec, :stdlib
|
32
|
-
c.treat_symbols_as_metadata_keys_with_true_values = true
|
33
|
-
|
34
|
-
if Vagrant::Util::Platform.windows?
|
35
|
-
c.filter_run_excluding :skip_windows
|
36
|
-
else
|
37
|
-
c.filter_run_excluding :windows
|
1
|
+
shared_context "unit" do
|
2
|
+
before(:each) do
|
3
|
+
# State to store the list of registered plugins that we have to
|
4
|
+
# unregister later.
|
5
|
+
@_plugins = []
|
6
|
+
|
7
|
+
# Create a thing to store our temporary files so that they aren't
|
8
|
+
# unlinked right away.
|
9
|
+
@_temp_files = []
|
38
10
|
end
|
39
|
-
end
|
40
11
|
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
12
|
+
# This helper creates a temporary file and returns a Pathname
|
13
|
+
# object pointed to it.
|
14
|
+
#
|
15
|
+
# @return [Pathname]
|
16
|
+
def temporary_file(contents=nil)
|
17
|
+
f = Tempfile.new("vagrant-unit")
|
44
18
|
|
45
|
-
|
46
|
-
|
19
|
+
if contents
|
20
|
+
f.write(contents)
|
21
|
+
f.flush
|
22
|
+
end
|
47
23
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
24
|
+
# Store the tempfile in an instance variable so that it is not
|
25
|
+
# garbage collected, so that the tempfile is not unlinked.
|
26
|
+
@_temp_files << f
|
27
|
+
|
28
|
+
return Pathname.new(f.path)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Asserts that the current (config) validation run should fail.
|
32
|
+
# Any error message is sufficient.
|
33
|
+
def assert_invalid
|
34
|
+
errors = subject.validate(machine)
|
35
|
+
if !errors.values.any? { |v| !v.empty? }
|
36
|
+
raise "No errors: #{errors.inspect}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Asserts that the current (config) validation should fail with a specific message.
|
41
|
+
def assert_error(error)
|
42
|
+
errors = subject.validate(machine)
|
43
|
+
raise "Error #{error} was not raised" if !errors["dsc provisioner"].include? error
|
44
|
+
end
|
45
|
+
|
46
|
+
# Asserts that no failures should occur in the current (config) validation run.
|
47
|
+
def assert_valid
|
48
|
+
errors = subject.validate(machine)
|
49
|
+
if !errors.values.all? { |v| v.empty? }
|
50
|
+
raise "Errors: #{errors.inspect}"
|
51
|
+
end
|
53
52
|
end
|
54
|
-
end
|
55
53
|
|
56
|
-
|
57
|
-
Checkpoint.disable!
|
54
|
+
end
|
@@ -1,289 +1,147 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'vagrant-dsc/provisioner'
|
3
3
|
require 'vagrant-dsc/config'
|
4
|
-
require '
|
4
|
+
require 'base'
|
5
5
|
|
6
6
|
describe VagrantPlugins::DSC::Config do
|
7
|
-
|
7
|
+
include_context "unit"
|
8
8
|
let(:instance) { described_class.new }
|
9
|
-
|
10
|
-
before { subject.finalize! }
|
11
|
-
|
12
|
-
def assert_invalid
|
13
|
-
errors = subject.validate(machine)
|
14
|
-
if !errors.values.any? { |v| !v.empty? }
|
15
|
-
raise "No errors: #{errors.inspect}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def assert_valid
|
20
|
-
errors = subject.validate(machine)
|
21
|
-
if !errors.values.all? { |v| v.empty? }
|
22
|
-
raise "Errors: #{errors.inspect}"
|
23
|
-
end
|
24
|
-
end
|
9
|
+
let(:machine) { double("machine") }
|
25
10
|
|
26
11
|
def valid_defaults
|
27
|
-
subject.
|
12
|
+
# subject.prop = value
|
28
13
|
end
|
29
14
|
|
30
|
-
|
31
15
|
describe "defaults" do
|
32
16
|
|
17
|
+
before do
|
18
|
+
env = double("environment", root_path: "/tmp/vagrant-dsc-path")
|
19
|
+
config = double("config")
|
20
|
+
machine.stub(config: config, env: env)
|
21
|
+
|
22
|
+
allow(machine).to receive(:root_path).and_return("/c/foo")
|
23
|
+
end
|
24
|
+
|
33
25
|
# before do
|
34
26
|
# # By default lets be Linux for validations
|
35
27
|
# Vagrant::Util::Platform.stub(linux: true)
|
36
28
|
# end
|
37
29
|
|
38
|
-
subject
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
its("
|
45
|
-
its("
|
46
|
-
its("
|
47
|
-
its("
|
48
|
-
its("
|
49
|
-
its("
|
50
|
-
its("facter") { expect = {} }
|
51
|
-
its("synced_folder_type") { expect be_nil }
|
52
|
-
its("temp_dir") { expect match /^\/tmp\/vagrant-dsc-*/ }
|
53
|
-
its("working_directory") { expect be_nil }
|
30
|
+
before { subject.finalize! }
|
31
|
+
|
32
|
+
its("configuration_file") { expect = "default.ps1" }
|
33
|
+
its("manifests_path") { expect = "." }
|
34
|
+
its("configuration_name") { expect = "default" }
|
35
|
+
its("mof_path") { expect be_nil }
|
36
|
+
its("module_path") { expect be_nil }
|
37
|
+
its("options") { expect = [] }
|
38
|
+
its("configuration_params") { expect = {} }
|
39
|
+
its("synced_folder_type") { expect be_nil }
|
40
|
+
its("temp_dir") { expect match /^\/tmp\/vagrant-dsc-*/ }
|
41
|
+
its("working_directory") { expect be_nil }
|
54
42
|
end
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
# require_relative "../base"
|
59
|
-
|
60
|
-
# require "vagrant/util/platform"
|
61
|
-
|
62
|
-
# require Vagrant.source_root.join("plugins/providers/docker/config")
|
63
|
-
|
64
|
-
# describe VagrantPlugins::DockerProvider::Config do
|
65
|
-
# include_context "unit"
|
66
|
-
|
67
|
-
# let(:machine) { double("machine") }
|
68
|
-
|
69
|
-
# let(:build_dir) do
|
70
|
-
# temporary_dir.tap do |dir|
|
71
|
-
# dir.join("Dockerfile").open("w") do |f|
|
72
|
-
# f.write("Hello")
|
73
|
-
# end
|
74
|
-
# end
|
75
|
-
# end
|
76
|
-
|
77
|
-
# def assert_invalid
|
78
|
-
# errors = subject.validate(machine)
|
79
|
-
# if !errors.values.any? { |v| !v.empty? }
|
80
|
-
# raise "No errors: #{errors.inspect}"
|
81
|
-
# end
|
82
|
-
# end
|
83
|
-
|
84
|
-
# def assert_valid
|
85
|
-
# errors = subject.validate(machine)
|
86
|
-
# if !errors.values.all? { |v| v.empty? }
|
87
|
-
# raise "Errors: #{errors.inspect}"
|
88
|
-
# end
|
89
|
-
# end
|
90
|
-
|
91
|
-
# def valid_defaults
|
92
|
-
# subject.image = "foo"
|
93
|
-
# end
|
94
|
-
|
95
|
-
# describe "defaults" do
|
96
|
-
# before { subject.finalize! }
|
97
|
-
|
98
|
-
# its(:build_dir) { should be_nil }
|
99
|
-
# its(:expose) { should eq([]) }
|
100
|
-
# its(:cmd) { should eq([]) }
|
101
|
-
# its(:env) { should eq({}) }
|
102
|
-
# its(:force_host_vm) { should be_false }
|
103
|
-
# its(:host_vm_build_dir_options) { should be_nil }
|
104
|
-
# its(:image) { should be_nil }
|
105
|
-
# its(:name) { should be_nil }
|
106
|
-
# its(:privileged) { should be_false }
|
107
|
-
# its(:vagrant_machine) { should be_nil }
|
108
|
-
# its(:vagrant_vagrantfile) { should be_nil }
|
109
|
-
# end
|
110
|
-
|
111
|
-
# before do
|
112
|
-
# # By default lets be Linux for validations
|
113
|
-
# Vagrant::Util::Platform.stub(linux: true)
|
114
|
-
# end
|
115
|
-
|
116
|
-
# it "should be invalid if both build dir and image are set" do
|
117
|
-
# subject.build_dir = build_dir
|
118
|
-
# subject.image = "foo"
|
119
|
-
# subject.finalize!
|
120
|
-
# assert_invalid
|
121
|
-
# end
|
122
|
-
|
123
|
-
# describe "#build_dir" do
|
124
|
-
# it "should be valid if not set with image" do
|
125
|
-
# subject.build_dir = nil
|
126
|
-
# subject.image = "foo"
|
127
|
-
# subject.finalize!
|
128
|
-
# assert_valid
|
129
|
-
# end
|
130
43
|
|
131
|
-
|
132
|
-
# subject.build_dir = build_dir
|
133
|
-
# subject.finalize!
|
134
|
-
# assert_valid
|
135
|
-
# end
|
44
|
+
describe "derived settings" do
|
136
45
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
# end
|
143
|
-
|
144
|
-
# describe "#expose" do
|
145
|
-
# before do
|
146
|
-
# valid_defaults
|
147
|
-
# end
|
148
|
-
|
149
|
-
# it "uniqs the ports" do
|
150
|
-
# subject.expose = [1, 1, 4, 5]
|
151
|
-
# subject.finalize!
|
152
|
-
# assert_valid
|
153
|
-
|
154
|
-
# expect(subject.expose).to eq([1, 4, 5])
|
155
|
-
# end
|
156
|
-
# end
|
157
|
-
|
158
|
-
# describe "#image" do
|
159
|
-
# it "should be valid if set" do
|
160
|
-
# subject.image = "foo"
|
161
|
-
# subject.finalize!
|
162
|
-
# assert_valid
|
163
|
-
# end
|
164
|
-
|
165
|
-
# it "should be invalid if not set" do
|
166
|
-
# subject.image = nil
|
167
|
-
# subject.finalize!
|
168
|
-
# assert_invalid
|
169
|
-
# end
|
170
|
-
# end
|
171
|
-
|
172
|
-
# describe "#link" do
|
173
|
-
# before do
|
174
|
-
# valid_defaults
|
175
|
-
# end
|
176
|
-
|
177
|
-
# it "should be valid with good links" do
|
178
|
-
# subject.link "foo:bar"
|
179
|
-
# subject.link "db:blah"
|
180
|
-
# subject.finalize!
|
181
|
-
# assert_valid
|
182
|
-
# end
|
183
|
-
|
184
|
-
# it "should be invalid if not name:alias" do
|
185
|
-
# subject.link "foo"
|
186
|
-
# subject.finalize!
|
187
|
-
# assert_invalid
|
188
|
-
# end
|
46
|
+
it "should derive 'configuration_name' from 'configuration_file' automatically" do
|
47
|
+
subject.configuration_file = "manifests/MyWebsite.ps1"
|
48
|
+
subject.finalize!
|
49
|
+
expect(subject.configuration_name).to eq("MyWebsite")
|
50
|
+
end
|
189
51
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
# end
|
52
|
+
it "should derive 'configuration_name' from 'configuration_file' automatically, when given multi-level file path" do
|
53
|
+
subject.configuration_file = "manifests/foo/MyWebsite.ps1"
|
54
|
+
subject.finalize!
|
55
|
+
expect(subject.configuration_name).to eq("MyWebsite")
|
56
|
+
end
|
196
57
|
|
197
|
-
|
198
|
-
|
199
|
-
|
58
|
+
it "should derive 'configuration_name' from 'configuration_file' automatically, when given no multi-level file path" do
|
59
|
+
subject.configuration_file = "MyWebsite.ps1"
|
60
|
+
subject.finalize!
|
61
|
+
expect(subject.configuration_name).to eq("MyWebsite")
|
62
|
+
end
|
200
63
|
|
201
|
-
|
64
|
+
it "should detect the fully qualified path to the manifest automatically" do
|
65
|
+
env = double("environment", root_path: "")
|
66
|
+
config = double("config")
|
67
|
+
machine.stub(config: config, env: env)
|
68
|
+
allow(machine).to receive(:root_path).and_return(".")
|
202
69
|
|
203
|
-
|
204
|
-
# it "overrides image if build_dir is set previously" do
|
205
|
-
# one.build_dir = "foo"
|
206
|
-
# two.image = "bar"
|
70
|
+
subject.configuration_file = "manifests/MyWebsite.ps1"
|
207
71
|
|
208
|
-
|
209
|
-
|
210
|
-
# end
|
72
|
+
subject.finalize!
|
73
|
+
subject.validate(machine)
|
211
74
|
|
212
|
-
|
213
|
-
|
214
|
-
|
75
|
+
basePath = File.absolute_path(File.join(File.dirname(__FILE__), '../../'))
|
76
|
+
expect(subject.expanded_configuration_file.to_s).to eq("#{basePath}/manifests/MyWebsite.ps1")
|
77
|
+
end
|
78
|
+
end
|
215
79
|
|
216
|
-
|
217
|
-
|
218
|
-
# end
|
80
|
+
describe "validate" do
|
81
|
+
before { subject.finalize! }
|
219
82
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
83
|
+
before do
|
84
|
+
env = double("environment", root_path: "")
|
85
|
+
config = double("config")
|
86
|
+
machine.stub(config: config, env: env)
|
224
87
|
|
225
|
-
|
226
|
-
|
227
|
-
# end
|
228
|
-
# end
|
88
|
+
allow(machine).to receive(:root_path).and_return("/path/to/vagrant")
|
89
|
+
end
|
229
90
|
|
230
|
-
#
|
231
|
-
#
|
232
|
-
#
|
233
|
-
#
|
91
|
+
# before do
|
92
|
+
# # By default lets be Linux for validations
|
93
|
+
# Vagrant::Util::Platform.stub(linux: true)
|
94
|
+
# end
|
234
95
|
|
235
|
-
#
|
236
|
-
#
|
237
|
-
# "bar" => "baz",
|
238
|
-
# })
|
239
|
-
# end
|
240
|
-
# end
|
96
|
+
# it "should disallow absolute module paths" do
|
97
|
+
# end
|
241
98
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
99
|
+
it "should generate a module path on the host machine relative to the Vagrantfile" do
|
100
|
+
subject.module_path = "foo/modules"
|
101
|
+
expect(subject.expanded_module_paths('/path/to/vagrant/')).to eq(["/path/to/vagrant/foo/modules"])
|
102
|
+
end
|
246
103
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
104
|
+
it "should generate module paths on the host machine relative to the Vagrantfile" do
|
105
|
+
subject.module_path = ["dont/exist", "also/dont/exist"]
|
106
|
+
expect(subject.expanded_module_paths('/path/to/vagrant/')).to eq(["/path/to/vagrant/dont/exist", "/path/to/vagrant/also/dont/exist"])
|
107
|
+
end
|
251
108
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
109
|
+
it "should be invalid if 'manifests_path' is not a real directory" do
|
110
|
+
subject.manifests_path = "/i/do/not/exist"
|
111
|
+
assert_invalid
|
112
|
+
assert_error("\"Path to DSC Manifest folder does not exist: /i/do/not/exist\"")
|
113
|
+
end
|
256
114
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
115
|
+
it "should be invalid if 'configuration_file' is not a real file" do
|
116
|
+
subject.manifests_path = "/"
|
117
|
+
subject.configuration_file = "notexist.pp"
|
118
|
+
assert_invalid
|
119
|
+
assert_error("\"Path to DSC Manifest does not exist: /notexist.pp\"")
|
120
|
+
end
|
262
121
|
|
263
|
-
|
264
|
-
|
122
|
+
it "should be invalid if 'module_path' is not a real directory" do
|
123
|
+
subject.module_path = "/i/dont/exist"
|
124
|
+
assert_invalid
|
125
|
+
assert_error("\"Path to DSC Modules does not exist: /i/dont/exist\"")
|
126
|
+
end
|
265
127
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
# assert_valid
|
270
|
-
# expect(subject.vagrant_machine).to eq(:foo)
|
271
|
-
# end
|
272
|
-
# end
|
128
|
+
it "should be invalid if 'configuration_file' and 'mof_path' provided" do
|
129
|
+
mof = File.new(temporary_file)
|
130
|
+
man = File.new(temporary_file)
|
273
131
|
|
274
|
-
|
275
|
-
|
132
|
+
subject.configuration_file = File.basename(man)
|
133
|
+
subject.mof_path = File.basename(mof)
|
134
|
+
expect { subject.finalize! }.to raise_error("\"Cannot provide configuration_file and mof_path at the same time. Please provide only one of the two.\"")
|
135
|
+
# assert_error("\"Cannot provide configuration_file and mof_path at the same time. Please provide only one of the two.\"")
|
136
|
+
end
|
276
137
|
|
277
|
-
|
278
|
-
|
279
|
-
# subject.finalize!
|
280
|
-
# assert_valid
|
281
|
-
# end
|
138
|
+
it "should be valid if 'configuration_file' is a real file" do
|
139
|
+
file = File.new(temporary_file)
|
282
140
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
141
|
+
subject.configuration_file = File.basename(file)
|
142
|
+
subject.manifests_path = File.dirname(file)
|
143
|
+
subject.module_path = File.dirname(file)
|
144
|
+
assert_valid
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|