/
environment_test.rb
169 lines (138 loc) · 4.42 KB
/
environment_test.rb
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
require File.expand_path("../../base", __FILE__)
require "pathname"
require "vagrant/util/file_mode"
require "support/tempdir"
describe Vagrant::Environment do
include_context "unit"
let(:home_path) { Pathname.new(Tempdir.new.path) }
let(:instance) { described_class.new(:home_path => home_path) }
describe "current working directory" do
it "is the cwd by default" do
described_class.new.cwd.should == Pathname.new(Dir.pwd)
end
it "is set to the cwd given" do
instance = described_class.new(:cwd => "foobarbaz")
instance.cwd.should == Pathname.new("foobarbaz")
end
end
describe "home path" do
it "is set to the home path given" do
dir = Tempdir.new.path
instance = described_class.new(:home_path => dir)
instance.home_path.should == Pathname.new(dir)
end
it "is set to the environmental variable VAGRANT_HOME" do
pending "A good temporary ENV thing"
end
it "is set to the DEFAULT_HOME by default" do
expected = Pathname.new(File.expand_path(described_class::DEFAULT_HOME))
described_class.new.home_path.should == expected
end
it "throws an exception if inaccessible" do
expect {
described_class.new(:home_path => "/")
}.to raise_error(Vagrant::Errors::HomeDirectoryNotAccessible)
end
end
describe "copying the private SSH key" do
it "copies the SSH key into the home directory" do
env = isolated_environment
instance = described_class.new(:home_path => env.homedir)
pk = env.homedir.join("insecure_private_key")
pk.should be_exist
Vagrant::Util::FileMode.from_octal(pk.stat.mode).should == "600"
end
end
it "has a box collection pointed to the proper directory" do
collection = instance.boxes
collection.should be_kind_of(Vagrant::BoxCollection)
collection.directory.should == instance.boxes_path
end
describe "action runner" do
it "has an action runner" do
instance.action_runner.should be_kind_of(Vagrant::Action::Runner)
end
it "has a `ui` in the globals" do
result = nil
callable = lambda { |env| result = env[:ui] }
instance.action_runner.run(callable)
result.should eql(instance.ui)
end
end
describe "action registry" do
it "has an action registry" do
instance.action_registry.should be_kind_of(Vagrant::Action::Registry)
end
it "should have the built-in actions in the registry" do
instance.action_registry.get(:provision).should_not be_nil
end
end
describe "loading configuration" do
it "should load global configuration" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vagrant.dotfile_name = "foo"
end
VF
end
env = environment.create_vagrant_env
env.config.global.vagrant.dotfile_name.should == "foo"
end
it "should load VM configuration" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vagrant.dotfile_name = "foo"
end
VF
end
env = environment.create_vagrant_env
env.config.for_vm(:default).vm.name.should == :default
end
it "should load VM configuration with multiple VMs" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vm.define :foo do |vm|
vm.ssh.port = 100
end
config.vm.define :bar do |vm|
vm.ssh.port = 200
end
end
VF
end
env = environment.create_vagrant_env
env.config.for_vm(:foo).ssh.port.should == 100
env.config.for_vm(:bar).ssh.port.should == 200
end
it "should load box configuration" do
environment = isolated_environment do |env|
env.vagrantfile(<<-VF)
Vagrant::Config.run do |config|
config.vm.box = "base"
end
VF
env.box("base", <<-VF)
Vagrant::Config.run do |config|
config.ssh.port = 100
end
VF
end
env = environment.create_vagrant_env
env.config.for_vm(:default).ssh.port.should == 100
end
end
describe "ui" do
it "should be a silent UI by default" do
described_class.new.ui.should be_kind_of(Vagrant::UI::Silent)
end
it "should be a UI given in the constructor" do
# Create a custom UI for our test
class CustomUI < Vagrant::UI::Interface; end
instance = described_class.new(:ui_class => CustomUI)
instance.ui.should be_kind_of(CustomUI)
end
end
end