bmabey-vagrant 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +12 -0
  2. data/Gemfile +17 -0
  3. data/LICENSE +21 -0
  4. data/README.md +53 -0
  5. data/Rakefile +41 -0
  6. data/VERSION +1 -0
  7. data/bin/.gitignore +0 -0
  8. data/bin/vagrant +15 -0
  9. data/bin/vagrant-box +34 -0
  10. data/bin/vagrant-down +27 -0
  11. data/bin/vagrant-halt +28 -0
  12. data/bin/vagrant-init +27 -0
  13. data/bin/vagrant-package +29 -0
  14. data/bin/vagrant-reload +29 -0
  15. data/bin/vagrant-resume +27 -0
  16. data/bin/vagrant-ssh +27 -0
  17. data/bin/vagrant-status +29 -0
  18. data/bin/vagrant-suspend +27 -0
  19. data/bin/vagrant-up +29 -0
  20. data/config/default.rb +26 -0
  21. data/keys/README.md +10 -0
  22. data/keys/vagrant +27 -0
  23. data/keys/vagrant.pub +1 -0
  24. data/lib/vagrant.rb +19 -0
  25. data/lib/vagrant/actions/base.rb +118 -0
  26. data/lib/vagrant/actions/box/add.rb +22 -0
  27. data/lib/vagrant/actions/box/destroy.rb +14 -0
  28. data/lib/vagrant/actions/box/download.rb +72 -0
  29. data/lib/vagrant/actions/box/unpackage.rb +43 -0
  30. data/lib/vagrant/actions/collection.rb +36 -0
  31. data/lib/vagrant/actions/runner.rb +132 -0
  32. data/lib/vagrant/actions/vm/boot.rb +47 -0
  33. data/lib/vagrant/actions/vm/customize.rb +17 -0
  34. data/lib/vagrant/actions/vm/destroy.rb +23 -0
  35. data/lib/vagrant/actions/vm/down.rb +12 -0
  36. data/lib/vagrant/actions/vm/export.rb +41 -0
  37. data/lib/vagrant/actions/vm/forward_ports.rb +46 -0
  38. data/lib/vagrant/actions/vm/halt.rb +14 -0
  39. data/lib/vagrant/actions/vm/import.rb +18 -0
  40. data/lib/vagrant/actions/vm/move_hard_drive.rb +51 -0
  41. data/lib/vagrant/actions/vm/package.rb +65 -0
  42. data/lib/vagrant/actions/vm/provision.rb +49 -0
  43. data/lib/vagrant/actions/vm/reload.rb +17 -0
  44. data/lib/vagrant/actions/vm/resume.rb +16 -0
  45. data/lib/vagrant/actions/vm/shared_folders.rb +81 -0
  46. data/lib/vagrant/actions/vm/start.rb +18 -0
  47. data/lib/vagrant/actions/vm/suspend.rb +16 -0
  48. data/lib/vagrant/actions/vm/up.rb +40 -0
  49. data/lib/vagrant/active_list.rb +73 -0
  50. data/lib/vagrant/box.rb +152 -0
  51. data/lib/vagrant/busy.rb +73 -0
  52. data/lib/vagrant/commands.rb +219 -0
  53. data/lib/vagrant/config.rb +183 -0
  54. data/lib/vagrant/downloaders/base.rb +16 -0
  55. data/lib/vagrant/downloaders/file.rb +17 -0
  56. data/lib/vagrant/downloaders/http.rb +47 -0
  57. data/lib/vagrant/environment.rb +263 -0
  58. data/lib/vagrant/provisioners/base.rb +29 -0
  59. data/lib/vagrant/provisioners/chef.rb +103 -0
  60. data/lib/vagrant/provisioners/chef_server.rb +84 -0
  61. data/lib/vagrant/provisioners/chef_solo.rb +97 -0
  62. data/lib/vagrant/ssh.rb +104 -0
  63. data/lib/vagrant/util.rb +51 -0
  64. data/lib/vagrant/util/errors.rb +36 -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 +61 -0
  68. data/templates/Vagrantfile.erb +8 -0
  69. data/templates/errors.yml +117 -0
  70. data/test/test_helper.rb +163 -0
  71. data/test/vagrant/actions/base_test.rb +32 -0
  72. data/test/vagrant/actions/box/add_test.rb +37 -0
  73. data/test/vagrant/actions/box/destroy_test.rb +18 -0
  74. data/test/vagrant/actions/box/download_test.rb +131 -0
  75. data/test/vagrant/actions/box/unpackage_test.rb +100 -0
  76. data/test/vagrant/actions/collection_test.rb +110 -0
  77. data/test/vagrant/actions/runner_test.rb +265 -0
  78. data/test/vagrant/actions/vm/boot_test.rb +55 -0
  79. data/test/vagrant/actions/vm/customize_test.rb +16 -0
  80. data/test/vagrant/actions/vm/destroy_test.rb +36 -0
  81. data/test/vagrant/actions/vm/down_test.rb +32 -0
  82. data/test/vagrant/actions/vm/export_test.rb +88 -0
  83. data/test/vagrant/actions/vm/forward_ports_test.rb +104 -0
  84. data/test/vagrant/actions/vm/halt_test.rb +27 -0
  85. data/test/vagrant/actions/vm/import_test.rb +43 -0
  86. data/test/vagrant/actions/vm/move_hard_drive_test.rb +108 -0
  87. data/test/vagrant/actions/vm/package_test.rb +181 -0
  88. data/test/vagrant/actions/vm/provision_test.rb +108 -0
  89. data/test/vagrant/actions/vm/reload_test.rb +47 -0
  90. data/test/vagrant/actions/vm/resume_test.rb +27 -0
  91. data/test/vagrant/actions/vm/shared_folders_test.rb +176 -0
  92. data/test/vagrant/actions/vm/start_test.rb +36 -0
  93. data/test/vagrant/actions/vm/suspend_test.rb +27 -0
  94. data/test/vagrant/actions/vm/up_test.rb +107 -0
  95. data/test/vagrant/active_list_test.rb +190 -0
  96. data/test/vagrant/box_test.rb +151 -0
  97. data/test/vagrant/busy_test.rb +83 -0
  98. data/test/vagrant/commands_test.rb +307 -0
  99. data/test/vagrant/config_test.rb +256 -0
  100. data/test/vagrant/downloaders/base_test.rb +27 -0
  101. data/test/vagrant/downloaders/file_test.rb +26 -0
  102. data/test/vagrant/downloaders/http_test.rb +40 -0
  103. data/test/vagrant/environment_test.rb +607 -0
  104. data/test/vagrant/provisioners/base_test.rb +33 -0
  105. data/test/vagrant/provisioners/chef_server_test.rb +187 -0
  106. data/test/vagrant/provisioners/chef_solo_test.rb +149 -0
  107. data/test/vagrant/provisioners/chef_test.rb +117 -0
  108. data/test/vagrant/ssh_test.rb +222 -0
  109. data/test/vagrant/util/errors_test.rb +57 -0
  110. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  111. data/test/vagrant/util/template_renderer_test.rb +138 -0
  112. data/test/vagrant/util_test.rb +64 -0
  113. data/test/vagrant/vm_test.rb +114 -0
  114. data/vagrant.gemspec +216 -0
  115. metadata +285 -0
@@ -0,0 +1,181 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class PackageActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", [])
6
+
7
+ mock_config
8
+ end
9
+
10
+ context "initialization" do
11
+ def get_action(*args)
12
+ runner, vm, action = mock_action(Vagrant::Actions::VM::Package, *args)
13
+ return action
14
+ end
15
+
16
+ should "make out_path 'package' by default if nil is given" do
17
+ action = get_action(nil, [])
18
+ assert_equal "package", action.out_path
19
+ end
20
+
21
+ should "make include files an empty array by default" do
22
+ action = get_action("foo", nil)
23
+ assert action.include_files.is_a?(Array)
24
+ assert action.include_files.empty?
25
+ end
26
+ end
27
+
28
+ context "executing" do
29
+ setup do
30
+ @action.stubs(:compress)
31
+ end
32
+
33
+ should "compress" do
34
+ package_seq = sequence("package_seq")
35
+ @action.expects(:compress).in_sequence(package_seq)
36
+ @action.execute!
37
+ end
38
+ end
39
+
40
+ context "tar path" do
41
+ should "be the temporary directory with the name and extension attached" do
42
+ pwd = "foo"
43
+ FileUtils.stubs(:pwd).returns(pwd)
44
+ assert_equal File.join(pwd, "#{@action.out_path}#{@runner.env.config.package.extension}"), @action.tar_path
45
+ end
46
+ end
47
+
48
+ context "temp path" do
49
+ setup do
50
+ @export = mock("export")
51
+ @action.expects(:export_action).returns(@export)
52
+ end
53
+
54
+ should "use the export action's temp dir" do
55
+ path = mock("path")
56
+ @export.expects(:temp_dir).returns(path)
57
+ @action.temp_path
58
+ end
59
+ end
60
+
61
+ context "compression" do
62
+ setup do
63
+ @tar_path = "foo"
64
+ @action.stubs(:tar_path).returns(@tar_path)
65
+
66
+ @temp_path = "foo"
67
+ @action.stubs(:temp_path).returns(@temp_path)
68
+
69
+ @include_files = []
70
+ @action.stubs(:include_files).returns(@include_files)
71
+
72
+ @pwd = "bar"
73
+ FileUtils.stubs(:pwd).returns(@pwd)
74
+ FileUtils.stubs(:cd)
75
+
76
+ @file = mock("file")
77
+ File.stubs(:open).yields(@file)
78
+
79
+ @output = mock("output")
80
+ @tar = Archive::Tar::Minitar
81
+ Archive::Tar::Minitar::Output.stubs(:open).yields(@output)
82
+ @tar.stubs(:pack_file)
83
+ end
84
+
85
+ should "open the tar file with the tar path properly" do
86
+ File.expects(:open).with(@tar_path, File::CREAT | File::WRONLY, 0644).once
87
+ @action.compress
88
+ end
89
+
90
+ should "open tar file" do
91
+ Archive::Tar::Minitar::Output.expects(:open).with(@file).once
92
+ @action.compress
93
+ end
94
+
95
+ #----------------------------------------------------------------
96
+ # Methods below this comment test the block yielded by Minitar open
97
+ #----------------------------------------------------------------
98
+ should "cd to the directory and append the directory" do
99
+ @files = []
100
+ compress_seq = sequence("compress_seq")
101
+
102
+ FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq)
103
+ FileUtils.expects(:cd).with(@temp_path).in_sequence(compress_seq)
104
+ Dir.expects(:glob).returns(@files).in_sequence(compress_seq)
105
+
106
+ 5.times do |i|
107
+ file = mock("file#{i}")
108
+ @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
109
+ @files << file
110
+ end
111
+
112
+ FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq)
113
+ @action.compress
114
+ end
115
+
116
+ should "pop back to the current directory even if an exception is raised" do
117
+ cd_seq = sequence("cd_seq")
118
+ FileUtils.expects(:cd).with(@temp_path).raises(Exception).in_sequence(cd_seq)
119
+ FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq)
120
+
121
+ assert_raises(Exception) {
122
+ @action.compress
123
+ }
124
+ end
125
+
126
+ should "add included files when passed" do
127
+ compress_seq = sequence("compress")
128
+ @files = []
129
+ 5.times do |i|
130
+ file = mock("file#{i}")
131
+ @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq)
132
+ @files << file
133
+ end
134
+
135
+ @action.expects(:include_files).returns(@files)
136
+ @action.compress
137
+ end
138
+
139
+ should "not add files when none are specified" do
140
+ @tar.expects(:pack_file).never
141
+ Dir.expects(:glob).once.returns([])
142
+ @action.compress
143
+ end
144
+ end
145
+
146
+ context "preparing the action" do
147
+ context "checking include files" do
148
+ setup do
149
+ @include_files = ['fooiest', 'booiest']
150
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Package, "bing", @include_files)
151
+ @runner.stubs(:find_action).returns("foo")
152
+ end
153
+
154
+ should "check that all the include files exist" do
155
+ @include_files.each do |file|
156
+ File.expects(:exists?).with(file).returns(true)
157
+ end
158
+ @action.prepare
159
+ end
160
+
161
+ should "raise an exception when an include file does not exist" do
162
+ File.expects(:exists?).once.returns(false)
163
+ assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
164
+ end
165
+ end
166
+
167
+ context "loading export reference" do
168
+ should "find and store a reference to the export action" do
169
+ @export = mock("export")
170
+ @runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(@export)
171
+ @action.prepare
172
+ assert @export.equal?(@action.export_action)
173
+ end
174
+
175
+ should "raise an exception if the export action couldn't be found" do
176
+ @runner.expects(:find_action).with(Vagrant::Actions::VM::Export).once.returns(nil)
177
+ assert_raises(Vagrant::Actions::ActionException) { @action.prepare }
178
+ end
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,108 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class ProvisionActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Provision)
6
+ mock_config
7
+ end
8
+
9
+ context "initialization" do
10
+ should "have a nil provisioner by default" do
11
+ assert_nil @action.provisioner
12
+ end
13
+ end
14
+
15
+ context "executing" do
16
+ should "do nothing if the provisioner is nil" do
17
+ @action.expects(:provisioner).returns(nil)
18
+ assert_nothing_raised { @action.execute! }
19
+ end
20
+
21
+ should "call `provision!` on the provisioner" do
22
+ provisioner = mock("provisioner")
23
+ provisioner.expects(:provision!).once
24
+ @action.expects(:provisioner).twice.returns(provisioner)
25
+ @action.execute!
26
+ end
27
+ end
28
+
29
+ context "preparing" do
30
+ context "with a nil provisioner" do
31
+ setup do
32
+ mock_config do |config|
33
+ config.vm.provisioner = nil
34
+ end
35
+ end
36
+
37
+ should "not set a provisioner if set to nil" do
38
+ @action.prepare
39
+ assert_nil @action.provisioner
40
+ end
41
+ end
42
+
43
+ context "with a Class provisioner" do
44
+ setup do
45
+ @instance = mock("instance")
46
+ @instance.stubs(:is_a?).with(Vagrant::Provisioners::Base).returns(true)
47
+ @instance.stubs(:prepare)
48
+ @klass = mock("klass")
49
+ @klass.stubs(:is_a?).with(Class).returns(true)
50
+ @klass.stubs(:new).with(@runner.env).returns(@instance)
51
+
52
+ mock_config do |config|
53
+ config.vm.provisioner = @klass
54
+ end
55
+ end
56
+
57
+ should "set the provisioner to an instantiation of the class" do
58
+ @klass.expects(:new).with(@runner.env).once.returns(@instance)
59
+ assert_nothing_raised { @action.prepare }
60
+ assert_equal @instance, @action.provisioner
61
+ end
62
+
63
+ should "call prepare on the instance" do
64
+ @instance.expects(:prepare).once
65
+ @action.prepare
66
+ end
67
+
68
+ should "raise an exception if the class is not a subclass of the provisioner base" do
69
+ @instance.expects(:is_a?).with(Vagrant::Provisioners::Base).returns(false)
70
+ assert_raises(Vagrant::Actions::ActionException) {
71
+ @action.prepare
72
+ }
73
+ end
74
+ end
75
+
76
+ context "with a Symbol provisioner" do
77
+ def provisioner_expectation(symbol, provisioner)
78
+ mock_config do |config|
79
+ config.vm.provisioner = symbol
80
+ end
81
+
82
+ instance = mock("instance")
83
+ instance.expects(:prepare).once
84
+ provisioner.expects(:new).with(@runner.env).returns(instance)
85
+ assert_nothing_raised { @action.prepare }
86
+ assert_equal instance, @action.provisioner
87
+ end
88
+
89
+ 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
93
+
94
+ assert_raises(Vagrant::Actions::ActionException) {
95
+ @action.prepare
96
+ }
97
+ end
98
+
99
+ should "set :chef_solo to the ChefSolo provisioner" do
100
+ provisioner_expectation(:chef_solo, Vagrant::Provisioners::ChefSolo)
101
+ end
102
+
103
+ should "set :chef_server to the ChefServer provisioner" do
104
+ provisioner_expectation(:chef_server, Vagrant::Provisioners::ChefServer)
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class ReloadActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Reload)
6
+ mock_config
7
+ end
8
+
9
+ context "sub-actions" do
10
+ setup do
11
+ @default_order = [Vagrant::Actions::VM::Customize, Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Boot]
12
+ @vm.stubs(:running?).returns(false)
13
+ end
14
+
15
+ def setup_action_expectations
16
+ default_seq = sequence("default_seq")
17
+ @default_order.each do |action|
18
+ @runner.expects(:add_action).with(action).once.in_sequence(default_seq)
19
+ end
20
+ end
21
+
22
+ should "do the proper actions by default" do
23
+ setup_action_expectations
24
+ @action.prepare
25
+ end
26
+
27
+ should "halt if the VM is running" do
28
+ @vm.expects(:running?).returns(true)
29
+ @default_order.unshift(Vagrant::Actions::VM::Halt)
30
+ setup_action_expectations
31
+ @action.prepare
32
+ end
33
+
34
+ should "add in the provisioning step if enabled" do
35
+ env = mock_environment do |config|
36
+ # Dummy provisioner to test
37
+ config.vm.provisioner = "foo"
38
+ end
39
+
40
+ @runner.stubs(:env).returns(env)
41
+
42
+ @default_order.push(Vagrant::Actions::VM::Provision)
43
+ setup_action_expectations
44
+ @action.prepare
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class ResumeActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::Resume)
6
+ mock_config
7
+ end
8
+
9
+ context "executing" do
10
+ setup do
11
+ @vm.stubs(:saved?).returns(true)
12
+ end
13
+
14
+ should "save the state of the VM" do
15
+ @runner.expects(:start).once
16
+ @action.execute!
17
+ end
18
+
19
+ should "raise an ActionException if the VM is not saved" do
20
+ @vm.expects(:saved?).returns(false)
21
+ @vm.expects(:start).never
22
+ assert_raises(Vagrant::Actions::ActionException) {
23
+ @action.execute!
24
+ }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,176 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
2
+
3
+ class SharedFoldersActionTest < Test::Unit::TestCase
4
+ setup do
5
+ @runner, @vm, @action = mock_action(Vagrant::Actions::VM::SharedFolders)
6
+ mock_config
7
+ end
8
+
9
+ def stub_shared_folders
10
+ folders = [%w{foo from to}, %w{bar bfrom bto}]
11
+ @action.expects(:shared_folders).returns(folders)
12
+ folders
13
+ end
14
+
15
+ context "before boot" do
16
+ should "clear folders and create metadata, in order" do
17
+ before_seq = sequence("before")
18
+ @action.expects(:clear_shared_folders).once.in_sequence(before_seq)
19
+ @action.expects(:create_metadata).once.in_sequence(before_seq)
20
+ @action.before_boot
21
+ end
22
+ end
23
+
24
+ context "collecting shared folders" do
25
+ setup do
26
+ File.stubs(:expand_path).returns("baz")
27
+ end
28
+
29
+ should "convert the vagrant config values into an array" do
30
+ env = mock_environment do |config|
31
+ config.vm.shared_folders.clear
32
+ config.vm.share_folder("foo", "bar", "baz")
33
+ end
34
+
35
+ @runner.expects(:env).returns(env)
36
+
37
+ result = [["foo", "baz", "bar"]]
38
+ assert_equal result, @action.shared_folders
39
+ end
40
+
41
+ should "expand the path of the host folder" do
42
+ File.expects(:expand_path).with("baz").once.returns("expanded_baz")
43
+
44
+ env = mock_environment do |config|
45
+ config.vm.shared_folders.clear
46
+ config.vm.share_folder("foo", "bar", "baz")
47
+ end
48
+
49
+ @runner.expects(:env).returns(env)
50
+
51
+ result = [["foo", "expanded_baz", "bar"]]
52
+ assert_equal result, @action.shared_folders
53
+ end
54
+ end
55
+
56
+ context "clearing shared folders" do
57
+ setup do
58
+ @shared_folder = mock("shared_folder")
59
+ @shared_folders = [@shared_folder]
60
+ @vm.stubs(:shared_folders).returns(@shared_folders)
61
+ end
62
+
63
+ should "call destroy on each shared folder then reload" do
64
+ destroy_seq = sequence("destroy")
65
+ @shared_folders.each do |sf|
66
+ sf.expects(:destroy).once.in_sequence(destroy_seq)
67
+ end
68
+
69
+ @runner.expects(:reload!).once.in_sequence(destroy_seq)
70
+ @action.clear_shared_folders
71
+ end
72
+ end
73
+
74
+ context "setting up shared folder metadata" do
75
+ setup do
76
+ @folders = stub_shared_folders
77
+ end
78
+
79
+ should "add all shared folders to the VM" do
80
+ share_seq = sequence("share_seq")
81
+ shared_folders = mock("shared_folders")
82
+ shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "foo" && sf.hostpath == "from" }
83
+ shared_folders.expects(:<<).in_sequence(share_seq).with() { |sf| sf.name == "bar" && sf.hostpath == "bfrom" }
84
+ @vm.stubs(:shared_folders).returns(shared_folders)
85
+ @vm.expects(:save).with(true).once
86
+
87
+ @action.create_metadata
88
+ end
89
+ end
90
+
91
+ context "mounting the shared folders" do
92
+ setup do
93
+ @folders = stub_shared_folders
94
+ end
95
+
96
+ should "mount all shared folders to the VM" do
97
+ mount_seq = sequence("mount_seq")
98
+ ssh = mock("ssh")
99
+ @folders.each do |name, hostpath, guestpath|
100
+ ssh.expects(:exec!).with("sudo mkdir -p #{guestpath}").in_sequence(mount_seq)
101
+ @action.expects(:mount_folder).with(ssh, name, guestpath).in_sequence(mount_seq)
102
+ ssh.expects(:exec!).with("sudo chown #{@runner.env.config.ssh.username} #{guestpath}").in_sequence(mount_seq)
103
+ end
104
+ @runner.env.ssh.expects(:execute).yields(ssh)
105
+
106
+ @action.after_boot
107
+ end
108
+ end
109
+
110
+ context "mounting the main folder" do
111
+ setup do
112
+ @ssh = mock("ssh")
113
+ @name = "foo"
114
+ @guestpath = "bar"
115
+ @sleeptime = 0
116
+ @limit = 10
117
+
118
+ @success_return = false
119
+ end
120
+
121
+ def mount_folder
122
+ @action.mount_folder(@ssh, @name, @guestpath, @sleeptime)
123
+ end
124
+
125
+ should "execute the proper mount command" do
126
+ @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)
127
+ mount_folder
128
+ end
129
+
130
+ should "test type of text and text string to detect error" do
131
+ data = mock("data")
132
+ data.expects(:[]=).with(:result, !@success_return)
133
+
134
+ @ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return)
135
+ mount_folder
136
+ end
137
+
138
+ should "test type of text and test string to detect success" do
139
+ data = mock("data")
140
+ data.expects(:[]=).with(:result, @success_return)
141
+
142
+ @ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return)
143
+ mount_folder
144
+ end
145
+
146
+ should "raise an ActionException if the command fails constantly" do
147
+ @ssh.expects(:exec!).times(@limit).returns(!@success_return)
148
+
149
+ assert_raises(Vagrant::Actions::ActionException) {
150
+ mount_folder
151
+ }
152
+ end
153
+
154
+ should "not raise any exception if the command succeeded" do
155
+ @ssh.expects(:exec!).once.returns(@success_return)
156
+
157
+ assert_nothing_raised {
158
+ mount_folder
159
+ }
160
+ end
161
+
162
+ should "add uid AND gid to mount" do
163
+ uid = "foo"
164
+ gid = "bar"
165
+ env = mock_environment do |config|
166
+ config.vm.shared_folder_uid = uid
167
+ config.vm.shared_folder_gid = gid
168
+ end
169
+
170
+ @runner.expects(:env).twice.returns(env)
171
+
172
+ @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return)
173
+ mount_folder
174
+ end
175
+ end
176
+ end