vagrant 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/Gemfile +4 -4
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/bin/vagrant +5 -13
  5. data/config/default.rb +1 -0
  6. data/keys/README.md +8 -1
  7. data/keys/vagrant.ppk +26 -0
  8. data/lib/vagrant.rb +3 -3
  9. data/lib/vagrant/actions/base.rb +15 -4
  10. data/lib/vagrant/actions/box/add.rb +1 -1
  11. data/lib/vagrant/actions/box/download.rb +72 -66
  12. data/lib/vagrant/actions/box/unpackage.rb +1 -4
  13. data/lib/vagrant/actions/runner.rb +1 -1
  14. data/lib/vagrant/actions/vm/boot.rb +5 -7
  15. data/lib/vagrant/actions/vm/customize.rb +2 -2
  16. data/lib/vagrant/actions/vm/destroy.rb +2 -2
  17. data/lib/vagrant/actions/vm/down.rb +7 -0
  18. data/lib/vagrant/actions/vm/export.rb +10 -4
  19. data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
  20. data/lib/vagrant/actions/vm/halt.rb +5 -3
  21. data/lib/vagrant/actions/vm/import.rb +10 -3
  22. data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
  23. data/lib/vagrant/actions/vm/package.rb +33 -10
  24. data/lib/vagrant/actions/vm/provision.rb +4 -4
  25. data/lib/vagrant/actions/vm/reload.rb +1 -1
  26. data/lib/vagrant/actions/vm/resume.rb +1 -1
  27. data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
  28. data/lib/vagrant/actions/vm/start.rb +3 -2
  29. data/lib/vagrant/actions/vm/suspend.rb +2 -2
  30. data/lib/vagrant/actions/vm/up.rb +7 -17
  31. data/lib/vagrant/active_list.rb +52 -45
  32. data/lib/vagrant/box.rb +18 -11
  33. data/lib/vagrant/busy.rb +7 -0
  34. data/lib/vagrant/command.rb +27 -0
  35. data/lib/vagrant/commands/base.rb +163 -0
  36. data/lib/vagrant/commands/box.rb +16 -0
  37. data/lib/vagrant/commands/box/add.rb +24 -0
  38. data/lib/vagrant/commands/box/list.rb +30 -0
  39. data/lib/vagrant/commands/box/remove.rb +31 -0
  40. data/lib/vagrant/commands/destroy.rb +23 -0
  41. data/lib/vagrant/commands/down.rb +16 -0
  42. data/lib/vagrant/commands/halt.rb +23 -0
  43. data/lib/vagrant/commands/init.rb +32 -0
  44. data/lib/vagrant/commands/package.rb +46 -0
  45. data/lib/vagrant/commands/reload.rb +22 -0
  46. data/lib/vagrant/commands/resume.rb +22 -0
  47. data/lib/vagrant/commands/ssh.rb +22 -0
  48. data/lib/vagrant/commands/ssh_config.rb +30 -0
  49. data/lib/vagrant/commands/status.rb +58 -0
  50. data/lib/vagrant/commands/suspend.rb +23 -0
  51. data/lib/vagrant/commands/up.rb +26 -0
  52. data/lib/vagrant/config.rb +21 -11
  53. data/lib/vagrant/downloaders/file.rb +5 -5
  54. data/lib/vagrant/downloaders/http.rb +10 -15
  55. data/lib/vagrant/environment.rb +259 -0
  56. data/lib/vagrant/provisioners/base.rb +7 -0
  57. data/lib/vagrant/provisioners/chef.rb +24 -9
  58. data/lib/vagrant/provisioners/chef_server.rb +23 -48
  59. data/lib/vagrant/provisioners/chef_solo.rb +48 -22
  60. data/lib/vagrant/ssh.rb +95 -46
  61. data/lib/vagrant/util.rb +2 -2
  62. data/lib/vagrant/util/errors.rb +36 -0
  63. data/lib/vagrant/util/platform.rb +12 -0
  64. data/lib/vagrant/util/progress_meter.rb +33 -0
  65. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  66. data/lib/vagrant/util/template_renderer.rb +83 -0
  67. data/lib/vagrant/vm.rb +1 -0
  68. data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
  69. data/templates/chef_server_client.erb +16 -0
  70. data/templates/chef_solo_solo.erb +4 -0
  71. data/templates/errors.yml +157 -0
  72. data/templates/package_Vagrantfile.erb +11 -0
  73. data/templates/ssh_config.erb +7 -0
  74. data/test/test_helper.rb +12 -15
  75. data/test/vagrant/actions/box/add_test.rb +1 -2
  76. data/test/vagrant/actions/box/destroy_test.rb +0 -1
  77. data/test/vagrant/actions/box/download_test.rb +40 -15
  78. data/test/vagrant/actions/box/unpackage_test.rb +2 -3
  79. data/test/vagrant/actions/collection_test.rb +8 -5
  80. data/test/vagrant/actions/runner_test.rb +8 -6
  81. data/test/vagrant/actions/vm/boot_test.rb +12 -11
  82. data/test/vagrant/actions/vm/customize_test.rb +2 -3
  83. data/test/vagrant/actions/vm/destroy_test.rb +2 -3
  84. data/test/vagrant/actions/vm/down_test.rb +16 -3
  85. data/test/vagrant/actions/vm/export_test.rb +4 -5
  86. data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
  87. data/test/vagrant/actions/vm/halt_test.rb +8 -2
  88. data/test/vagrant/actions/vm/import_test.rb +5 -5
  89. data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
  90. data/test/vagrant/actions/vm/package_test.rb +60 -22
  91. data/test/vagrant/actions/vm/provision_test.rb +7 -16
  92. data/test/vagrant/actions/vm/reload_test.rb +3 -2
  93. data/test/vagrant/actions/vm/resume_test.rb +0 -1
  94. data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
  95. data/test/vagrant/actions/vm/start_test.rb +10 -3
  96. data/test/vagrant/actions/vm/suspend_test.rb +1 -2
  97. data/test/vagrant/actions/vm/up_test.rb +19 -11
  98. data/test/vagrant/active_list_test.rb +148 -129
  99. data/test/vagrant/box_test.rb +26 -14
  100. data/test/vagrant/busy_test.rb +15 -6
  101. data/test/vagrant/command_test.rb +53 -0
  102. data/test/vagrant/commands/base_test.rb +118 -0
  103. data/test/vagrant/commands/box/add_test.rb +34 -0
  104. data/test/vagrant/commands/box/list_test.rb +32 -0
  105. data/test/vagrant/commands/box/remove_test.rb +41 -0
  106. data/test/vagrant/commands/destroy_test.rb +32 -0
  107. data/test/vagrant/commands/down_test.rb +17 -0
  108. data/test/vagrant/commands/halt_test.rb +28 -0
  109. data/test/vagrant/commands/init_test.rb +55 -0
  110. data/test/vagrant/commands/package_test.rb +84 -0
  111. data/test/vagrant/commands/reload_test.rb +28 -0
  112. data/test/vagrant/commands/resume_test.rb +33 -0
  113. data/test/vagrant/commands/ssh_config_test.rb +54 -0
  114. data/test/vagrant/commands/ssh_test.rb +32 -0
  115. data/test/vagrant/commands/status_test.rb +20 -0
  116. data/test/vagrant/commands/suspend_test.rb +33 -0
  117. data/test/vagrant/commands/up_test.rb +41 -0
  118. data/test/vagrant/config_test.rb +42 -17
  119. data/test/vagrant/downloaders/file_test.rb +7 -0
  120. data/test/vagrant/downloaders/http_test.rb +12 -0
  121. data/test/vagrant/environment_test.rb +595 -0
  122. data/test/vagrant/provisioners/base_test.rb +7 -1
  123. data/test/vagrant/provisioners/chef_server_test.rb +41 -51
  124. data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
  125. data/test/vagrant/provisioners/chef_test.rb +61 -15
  126. data/test/vagrant/ssh_test.rb +166 -38
  127. data/test/vagrant/util/errors_test.rb +57 -0
  128. data/test/vagrant/util/progress_meter_test.rb +33 -0
  129. data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
  130. data/test/vagrant/util/template_renderer_test.rb +138 -0
  131. data/test/vagrant/vm_test.rb +3 -2
  132. data/vagrant.gemspec +88 -33
  133. metadata +94 -51
  134. data/bin/vagrant-box +0 -34
  135. data/bin/vagrant-down +0 -27
  136. data/bin/vagrant-halt +0 -28
  137. data/bin/vagrant-init +0 -27
  138. data/bin/vagrant-package +0 -29
  139. data/bin/vagrant-reload +0 -29
  140. data/bin/vagrant-resume +0 -27
  141. data/bin/vagrant-ssh +0 -27
  142. data/bin/vagrant-status +0 -29
  143. data/bin/vagrant-suspend +0 -27
  144. data/bin/vagrant-up +0 -29
  145. data/lib/vagrant/commands.rb +0 -234
  146. data/lib/vagrant/env.rb +0 -189
  147. data/lib/vagrant/stacked_proc_runner.rb +0 -33
  148. data/test/vagrant/commands_test.rb +0 -269
  149. data/test/vagrant/env_test.rb +0 -418
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class ProvisionActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Provision)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "initialization" do
@@ -29,9 +28,7 @@ class ProvisionActionTest < Test::Unit::TestCase
29
28
  context "preparing" do
30
29
  context "with a nil provisioner" do
31
30
  setup do
32
- mock_config do |config|
33
- config.vm.provisioner = nil
34
- end
31
+ @runner.env.config.vm.provisioner = nil
35
32
  end
36
33
 
37
34
  should "not set a provisioner if set to nil" do
@@ -47,15 +44,13 @@ class ProvisionActionTest < Test::Unit::TestCase
47
44
  @instance.stubs(:prepare)
48
45
  @klass = mock("klass")
49
46
  @klass.stubs(:is_a?).with(Class).returns(true)
50
- @klass.stubs(:new).returns(@instance)
47
+ @klass.stubs(:new).with(@runner.env).returns(@instance)
51
48
 
52
- mock_config do |config|
53
- config.vm.provisioner = @klass
54
- end
49
+ @runner.env.config.vm.provisioner = @klass
55
50
  end
56
51
 
57
52
  should "set the provisioner to an instantiation of the class" do
58
- @klass.expects(:new).once.returns(@instance)
53
+ @klass.expects(:new).with(@runner.env).once.returns(@instance)
59
54
  assert_nothing_raised { @action.prepare }
60
55
  assert_equal @instance, @action.provisioner
61
56
  end
@@ -75,21 +70,17 @@ class ProvisionActionTest < Test::Unit::TestCase
75
70
 
76
71
  context "with a Symbol provisioner" do
77
72
  def provisioner_expectation(symbol, provisioner)
78
- mock_config do |config|
79
- config.vm.provisioner = symbol
80
- end
73
+ @runner.env.config.vm.provisioner = symbol
81
74
 
82
75
  instance = mock("instance")
83
76
  instance.expects(:prepare).once
84
- provisioner.expects(:new).returns(instance)
77
+ provisioner.expects(:new).with(@runner.env).returns(instance)
85
78
  assert_nothing_raised { @action.prepare }
86
79
  assert_equal instance, @action.provisioner
87
80
  end
88
81
 
89
82
  should "raise an ActionException if its an unknown symbol" do
90
- mock_config do |config|
91
- config.vm.provisioner = :this_will_never_exist
92
- end
83
+ @runner.env.config.vm.provisioner = :this_will_never_exist
93
84
 
94
85
  assert_raises(Vagrant::Actions::ActionException) {
95
86
  @action.prepare
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class ReloadActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Reload)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "sub-actions" do
@@ -32,11 +31,13 @@ class ReloadActionTest < Test::Unit::TestCase
32
31
  end
33
32
 
34
33
  should "add in the provisioning step if enabled" do
35
- mock_config do |config|
34
+ env = mock_environment do |config|
36
35
  # Dummy provisioner to test
37
36
  config.vm.provisioner = "foo"
38
37
  end
39
38
 
39
+ @runner.stubs(:env).returns(env)
40
+
40
41
  @default_order.push(Vagrant::Actions::VM::Provision)
41
42
  setup_action_expectations
42
43
  @action.prepare
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class ResumeActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Resume)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "executing" do
@@ -2,8 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
2
 
3
3
  class SharedFoldersActionTest < Test::Unit::TestCase
4
4
  setup do
5
- @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
6
- mock_config
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
7
6
  end
8
7
 
9
8
  def stub_shared_folders
@@ -27,11 +26,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
27
26
  end
28
27
 
29
28
  should "convert the vagrant config values into an array" do
30
- mock_config do |config|
29
+ env = mock_environment do |config|
31
30
  config.vm.shared_folders.clear
32
31
  config.vm.share_folder("foo", "bar", "baz")
33
32
  end
34
33
 
34
+ @runner.expects(:env).returns(env)
35
+
35
36
  result = [["foo", "baz", "bar"]]
36
37
  assert_equal result, @action.shared_folders
37
38
  end
@@ -39,11 +40,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
39
40
  should "expand the path of the host folder" do
40
41
  File.expects(:expand_path).with("baz").once.returns("expanded_baz")
41
42
 
42
- mock_config do |config|
43
+ env = mock_environment do |config|
43
44
  config.vm.shared_folders.clear
44
45
  config.vm.share_folder("foo", "bar", "baz")
45
46
  end
46
47
 
48
+ @runner.expects(:env).returns(env)
49
+
47
50
  result = [["foo", "expanded_baz", "bar"]]
48
51
  assert_equal result, @action.shared_folders
49
52
  end
@@ -62,7 +65,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
62
65
  sf.expects(:destroy).once.in_sequence(destroy_seq)
63
66
  end
64
67
 
65
- @mock_vm.expects(:reload!).once.in_sequence(destroy_seq)
68
+ @runner.expects(:reload!).once.in_sequence(destroy_seq)
66
69
  @action.clear_shared_folders
67
70
  end
68
71
  end
@@ -75,10 +78,10 @@ class SharedFoldersActionTest < Test::Unit::TestCase
75
78
  should "add all shared folders to the VM" do
76
79
  share_seq = sequence("share_seq")
77
80
  shared_folders = mock("shared_folders")
78
- shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "foo" && sf.hostpath == "from" }
79
- shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "bar" && sf.hostpath == "bfrom" }
81
+ shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "foo" && sf.host_path == "from" }
82
+ shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "bar" && sf.host_path == "bfrom" }
80
83
  @vm.stubs(:shared_folders).returns(shared_folders)
81
- @vm.expects(:save).with(true).once
84
+ @vm.expects(:save).once
82
85
 
83
86
  @action.create_metadata
84
87
  end
@@ -95,9 +98,9 @@ class SharedFoldersActionTest < Test::Unit::TestCase
95
98
  @folders.each do |name, hostpath, guestpath|
96
99
  ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq)
97
100
  @action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
98
- ssh.expects(:exec!).with("sudo chown #{Vagrant.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
101
+ ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
99
102
  end
100
- Vagrant::SSH.expects(:execute).yields(ssh)
103
+ @runner.env.ssh.expects(:execute).yields(ssh)
101
104
 
102
105
  @action.after_boot
103
106
  end
@@ -119,7 +122,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
119
122
  end
120
123
 
121
124
  should "execute the proper mount command" do
122
- @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{Vagrant.config.ssh.username},gid=#{Vagrant.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
125
+ @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{@runner.env.config.ssh.username},gid=#{@runner.env.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return)
123
126
  mount_folder
124
127
  end
125
128
 
@@ -158,11 +161,13 @@ class SharedFoldersActionTest < Test::Unit::TestCase
158
161
  should "add uid AND gid to mount" do
159
162
  uid = "foo"
160
163
  gid = "bar"
161
- mock_config do |config|
164
+ env = mock_environment do |config|
162
165
  config.vm.shared_folder_uid = uid
163
166
  config.vm.shared_folder_gid = gid
164
167
  end
165
168
 
169
+ @runner.expects(:env).twice.returns(env)
170
+
166
171
  @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
167
172
  mount_folder
168
173
  end
@@ -3,19 +3,19 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class StartActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Start)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "sub-actions" do
10
9
  setup do
10
+ @vm.stubs(:saved?).returns(true)
11
11
  File.stubs(:file?).returns(true)
12
12
  File.stubs(:exist?).returns(true)
13
- @default_order = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
13
+ @default_order = [Vagrant::Actions::VM::Boot]
14
14
  end
15
15
 
16
16
  def setup_action_expectations
17
17
  default_seq = sequence("default_seq")
18
- @default_order.each do |action|
18
+ @default_order.flatten.each do |action|
19
19
  @mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
20
20
  end
21
21
  end
@@ -24,5 +24,12 @@ class StartActionTest < Test::Unit::TestCase
24
24
  setup_action_expectations
25
25
  @action.prepare
26
26
  end
27
+
28
+ should "add customize to the beginning if its not saved" do
29
+ @vm.expects(:saved?).returns(false)
30
+ @default_order.unshift([Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders])
31
+ setup_action_expectations
32
+ @action.prepare
33
+ end
27
34
  end
28
35
  end
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
3
3
  class SuspendActionTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Suspend)
6
- mock_config
7
6
  end
8
7
 
9
8
  context "executing" do
@@ -12,7 +11,7 @@ class SuspendActionTest < Test::Unit::TestCase
12
11
  end
13
12
 
14
13
  should "save the state of the VM" do
15
- @vm.expects(:save_state).with(true).once
14
+ @vm.expects(:save_state).once
16
15
  @action.execute!
17
16
  end
18
17
 
@@ -2,8 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
2
 
3
3
  class UpActionTest < Test::Unit::TestCase
4
4
  setup do
5
- @mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
6
- mock_config
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Up)
7
6
  end
8
7
 
9
8
  context "sub-actions" do
@@ -11,17 +10,20 @@ class UpActionTest < Test::Unit::TestCase
11
10
  File.stubs(:file?).returns(true)
12
11
  File.stubs(:exist?).returns(true)
13
12
  @default_order = [Vagrant::Actions::VM::Import, Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
13
+
14
+ @dotfile_path = "foo"
15
+ @runner.env.stubs(:dotfile_path).returns(@dotfile_path)
14
16
  end
15
17
 
16
18
  def setup_action_expectations
17
19
  default_seq = sequence("default_seq")
18
20
  @default_order.each do |action|
19
- @mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
21
+ @runner.expects(:add_action).with(action).once.in_sequence(default_seq)
20
22
  end
21
23
  end
22
24
 
23
25
  should "raise an ActionException if a dotfile exists but is not a file" do
24
- File.expects(:file?).with(Vagrant::Env.dotfile_path).returns(false)
26
+ File.expects(:file?).with(@runner.env.dotfile_path).returns(false)
25
27
  assert_raises(Vagrant::Actions::ActionException) {
26
28
  @action.prepare
27
29
  }
@@ -46,21 +48,27 @@ class UpActionTest < Test::Unit::TestCase
46
48
  end
47
49
 
48
50
  should "add in the provisioning step if enabled" do
49
- mock_config do |config|
51
+ env = mock_environment do |config|
50
52
  config.vm.provisioner = "foo"
51
53
  end
52
54
 
55
+ @runner.stubs(:env).returns(env)
56
+ env.stubs(:dotfile_path).returns(@dotfile_path)
57
+
53
58
  @default_order.push(Vagrant::Actions::VM::Provision)
54
59
  setup_action_expectations
55
60
  @action.prepare
56
61
  end
57
62
 
58
63
  should "add in the action to move hard drive if config is set" do
59
- mock_config do |config|
64
+ env = mock_environment do |config|
60
65
  File.expects(:directory?).with("foo").returns(true)
61
66
  config.vm.hd_location = "foo"
62
67
  end
63
68
 
69
+ @runner.stubs(:env).returns(env)
70
+ env.stubs(:dotfile_path).returns(@dotfile_path)
71
+
64
72
  @default_order.insert(0, Vagrant::Actions::VM::MoveHardDrive)
65
73
  setup_action_expectations
66
74
  @action.prepare
@@ -78,8 +86,8 @@ class UpActionTest < Test::Unit::TestCase
78
86
 
79
87
  context "persisting" do
80
88
  should "persist the VM with Env" do
81
- @mock_vm.stubs(:uuid)
82
- Vagrant::Env.expects(:persist_vm).with(@mock_vm).once
89
+ @runner.stubs(:uuid)
90
+ @runner.env.expects(:persist_vm).once
83
91
  @action.persist
84
92
  end
85
93
  end
@@ -87,10 +95,10 @@ class UpActionTest < Test::Unit::TestCase
87
95
  context "setting up MAC address" do
88
96
  should "match the mac address with the base" do
89
97
  nic = mock("nic")
90
- nic.expects(:macaddress=).once
98
+ nic.expects(:mac_address=).once
91
99
 
92
- @vm.expects(:nics).returns([nic]).once
93
- @vm.expects(:save).with(true).once
100
+ @vm.expects(:network_adapters).returns([nic]).once
101
+ @vm.expects(:save).once
94
102
 
95
103
  @action.setup_mac_address
96
104
  end
@@ -2,168 +2,187 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class ActiveListTest < Test::Unit::TestCase
4
4
  setup do
5
- mock_config
5
+ @env = mock_environment
6
+ @list = Vagrant::ActiveList.new(@env)
6
7
  end
7
8
 
8
- context "class methods" do
9
- context "loading" do
10
- should "load if reload is given" do
11
- File.stubs(:file?).returns(true)
12
- File.expects(:open).once
13
- Vagrant::ActiveList.list(true)
14
- end
9
+ context "initializing" do
10
+ should "set the environment to nil if not specified" do
11
+ assert_nothing_raised {
12
+ list = Vagrant::ActiveList.new
13
+ assert list.env.nil?
14
+ }
15
+ end
15
16
 
16
- should "not load if the active json file doesn't exist" do
17
- File.expects(:file?).with(Vagrant::ActiveList.path).returns(false)
18
- File.expects(:open).never
19
- assert_equal [], Vagrant::ActiveList.list(true)
20
- end
17
+ should "set the environment to the given parameter if specified" do
18
+ env = mock("env")
19
+ list = Vagrant::ActiveList.new(env)
20
+ assert_equal env, list.env
21
+ end
22
+ end
21
23
 
22
- should "parse the JSON by reading the file" do
23
- file = mock("file")
24
- data = mock("data")
25
- result = mock("result")
26
- File.expects(:file?).returns(true)
27
- File.expects(:open).with(Vagrant::ActiveList.path, 'r').once.yields(file)
28
- file.expects(:read).returns(data)
29
- JSON.expects(:parse).with(data).returns(result)
30
- assert_equal result, Vagrant::ActiveList.list(true)
31
- end
24
+ context "listing" do
25
+ setup do
26
+ @path = "foo"
27
+ @list.stubs(:path).returns(@path)
28
+ end
32
29
 
33
- should "not load if reload flag is false and already loaded" do
34
- File.expects(:file?).once.returns(false)
35
- result = Vagrant::ActiveList.list(true)
36
- assert result.equal?(Vagrant::ActiveList.list)
37
- assert result.equal?(Vagrant::ActiveList.list)
38
- assert result.equal?(Vagrant::ActiveList.list)
39
- end
30
+ should "load if reload is given" do
31
+ File.stubs(:file?).returns(true)
32
+ File.expects(:open).once
33
+ @list.list(true)
40
34
  end
41
35
 
42
- context "vms" do
43
- setup do
44
- @list = ["foo", "bar"]
45
- Vagrant::ActiveList.stubs(:list).returns(@list)
46
- end
36
+ should "not load if the active json file doesn't exist" do
37
+ File.expects(:file?).with(@list.path).returns(false)
38
+ File.expects(:open).never
39
+ assert_equal [], @list.list(true)
40
+ end
41
+
42
+ should "parse the JSON by reading the file" do
43
+ file = mock("file")
44
+ data = mock("data")
45
+ result = mock("result")
46
+ File.expects(:file?).returns(true)
47
+ File.expects(:open).with(@list.path, 'r').once.yields(file)
48
+ file.expects(:read).returns(data)
49
+ JSON.expects(:parse).with(data).returns(result)
50
+ assert_equal result, @list.list(true)
51
+ end
52
+
53
+ should "not load if reload flag is false and already loaded" do
54
+ File.expects(:file?).once.returns(false)
55
+ result = @list.list(true)
56
+ assert result.equal?(@list.list)
57
+ assert result.equal?(@list.list)
58
+ assert result.equal?(@list.list)
59
+ end
60
+ end
47
61
 
48
- should "return the list, but with each value as a VM" do
49
- new_seq = sequence("new")
50
- results = []
51
- @list.each do |item|
52
- result = mock("result-#{item}")
53
- Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq)
54
- results << result
55
- end
62
+ context "vms" do
63
+ setup do
64
+ @the_list = ["foo", "bar"]
65
+ @list.stubs(:list).returns(@the_list)
66
+ end
56
67
 
57
- assert_equal results, Vagrant::ActiveList.vms
68
+ should "return the list, but with each value as a VM" do
69
+ new_seq = sequence("new")
70
+ results = []
71
+ @the_list.each do |item|
72
+ result = mock("result-#{item}")
73
+ Vagrant::VM.expects(:find).with(item).returns(result).in_sequence(new_seq)
74
+ results << result
58
75
  end
59
76
 
60
- should "compact out the nil values" do
61
- Vagrant::VM.stubs(:find).returns(nil)
62
- results = Vagrant::ActiveList.vms
63
- assert results.empty?
64
- end
77
+ assert_equal results, @list.vms
65
78
  end
66
79
 
67
- context "filtered list" do
68
- should "return a list of UUIDs from the VMs" do
69
- vms = []
70
- result = []
71
- 5.times do |i|
72
- vm = mock("vm#{i}")
73
- vm.expects(:uuid).returns(i)
74
- result << i
75
- vms << vm
76
- end
80
+ should "compact out the nil values" do
81
+ Vagrant::VM.stubs(:find).returns(nil)
82
+ results = @list.vms
83
+ assert results.empty?
84
+ end
85
+ end
77
86
 
78
- Vagrant::ActiveList.stubs(:vms).returns(vms)
79
- assert_equal result, Vagrant::ActiveList.filtered_list
87
+ context "filtered list" do
88
+ should "return a list of UUIDs from the VMs" do
89
+ vms = []
90
+ result = []
91
+ 5.times do |i|
92
+ vm = mock("vm#{i}")
93
+ vm.expects(:uuid).returns(i)
94
+ result << i
95
+ vms << vm
80
96
  end
97
+
98
+ @list.stubs(:vms).returns(vms)
99
+ assert_equal result, @list.filtered_list
81
100
  end
101
+ end
82
102
 
83
- context "adding a VM to the list" do
84
- setup do
85
- @list = []
86
- Vagrant::ActiveList.stubs(:list).returns(@list)
87
- Vagrant::ActiveList.stubs(:save)
103
+ context "adding a VM to the list" do
104
+ setup do
105
+ @the_list = []
106
+ @list.stubs(:list).returns(@the_list)
107
+ @list.stubs(:save)
88
108
 
89
- @uuid = "foo"
90
- @vm = mock("vm")
91
- @vm.stubs(:uuid).returns(@uuid)
92
- end
109
+ @uuid = "foo"
110
+ @vm = mock("vm")
111
+ @vm.stubs(:uuid).returns(@uuid)
112
+ end
93
113
 
94
- should "add the VMs UUID to the list" do
95
- Vagrant::ActiveList.add(@vm)
96
- assert_equal [@uuid], @list
97
- end
114
+ should "add the VMs UUID to the list" do
115
+ @list.add(@vm)
116
+ assert_equal [@uuid], @the_list
117
+ end
98
118
 
99
- should "uniq the array so multiples never exist" do
100
- @list << @uuid
101
- assert_equal 1, @list.length
102
- Vagrant::ActiveList.add(@vm)
103
- assert_equal 1, @list.length
104
- end
119
+ should "uniq the array so multiples never exist" do
120
+ @the_list << @uuid
121
+ assert_equal 1, @the_list.length
122
+ @list.add(@vm)
123
+ assert_equal 1, @the_list.length
124
+ end
105
125
 
106
- should "save after adding" do
107
- save_seq = sequence('save')
108
- @list.expects(:<<).in_sequence(save_seq)
109
- Vagrant::ActiveList.expects(:save).in_sequence(save_seq)
110
- Vagrant::ActiveList.add(@vm)
111
- end
126
+ should "save after adding" do
127
+ save_seq = sequence('save')
128
+ @the_list.expects(:<<).in_sequence(save_seq)
129
+ @list.expects(:save).in_sequence(save_seq)
130
+ @list.add(@vm)
112
131
  end
132
+ end
113
133
 
114
- context "deleting a VM from the list" do
115
- setup do
116
- @list = ["bar"]
117
- Vagrant::ActiveList.stubs(:list).returns(@list)
118
- Vagrant::ActiveList.stubs(:save)
134
+ context "deleting a VM from the list" do
135
+ setup do
136
+ @the_list = ["bar"]
137
+ @list.stubs(:list).returns(@the_list)
138
+ @list.stubs(:save)
119
139
 
120
- @uuid = "bar"
121
- @vm = mock("vm")
122
- @vm.stubs(:uuid).returns(@uuid)
123
- @vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
124
- end
140
+ @uuid = "bar"
141
+ @vm = mock("vm")
142
+ @vm.stubs(:uuid).returns(@uuid)
143
+ @vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
144
+ end
125
145
 
126
- should "delete the uuid from the list of a VM" do
127
- Vagrant::ActiveList.remove(@vm)
128
- assert @list.empty?
129
- end
146
+ should "delete the uuid from the list of a VM" do
147
+ @list.remove(@vm)
148
+ assert @the_list.empty?
149
+ end
130
150
 
131
- should "delete just the string if a string is given" do
132
- @list << "zoo"
133
- Vagrant::ActiveList.remove("zoo")
134
- assert !@list.include?("zoo")
135
- end
151
+ should "delete just the string if a string is given" do
152
+ @the_list << "zoo"
153
+ @list.remove("zoo")
154
+ assert !@the_list.include?("zoo")
155
+ end
136
156
 
137
- should "save after removing" do
138
- save_seq = sequence('save')
139
- @list.expects(:delete).in_sequence(save_seq)
140
- Vagrant::ActiveList.expects(:save).in_sequence(save_seq)
141
- Vagrant::ActiveList.remove(@vm)
142
- end
157
+ should "save after removing" do
158
+ save_seq = sequence('save')
159
+ @the_list.expects(:delete).in_sequence(save_seq)
160
+ @list.expects(:save).in_sequence(save_seq)
161
+ @list.remove(@vm)
143
162
  end
163
+ end
144
164
 
145
- context "saving" do
146
- setup do
147
- @filtered = ["zoo"]
148
- Vagrant::ActiveList.stubs(:filtered_list).returns(@filtered)
149
- end
165
+ context "saving" do
166
+ setup do
167
+ @filtered = ["zoo"]
168
+ @list.stubs(:filtered_list).returns(@filtered)
169
+ end
150
170
 
151
- should "open the JSON path and save to it" do
152
- file = mock("file")
153
- File.expects(:open).with(Vagrant::ActiveList.path, "w+").yields(file)
154
- file.expects(:write).with(@filtered.to_json)
155
- Vagrant::ActiveList.save
156
- end
171
+ should "open the JSON path and save to it" do
172
+ file = mock("file")
173
+ File.expects(:open).with(@list.path, "w+").yields(file)
174
+ file.expects(:write).with(@filtered.to_json)
175
+ @list.save
157
176
  end
177
+ end
158
178
 
159
- context "path" do
160
- setup do
161
- Vagrant::Env.stubs(:home_path).returns("foo")
162
- end
179
+ context "path" do
180
+ setup do
181
+ @env.stubs(:home_path).returns("foo")
182
+ end
163
183
 
164
- should "return the active file within the home path" do
165
- assert_equal File.join(Vagrant::Env.home_path, Vagrant::ActiveList::FILENAME), Vagrant::ActiveList.path
166
- end
184
+ should "return the active file within the home path" do
185
+ assert_equal File.join(@env.home_path, Vagrant::ActiveList::FILENAME), @list.path
167
186
  end
168
187
  end
169
188
  end