virtualbox 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +9 -9
- data/VERSION +1 -1
- data/docs/GettingStarted.md +11 -11
- data/docs/WhatsNew.md +1 -1
- data/lib/virtualbox.rb +10 -1
- data/lib/virtualbox/abstract_model.rb +47 -29
- data/lib/virtualbox/abstract_model/attributable.rb +16 -16
- data/lib/virtualbox/abstract_model/dirty.rb +10 -10
- data/lib/virtualbox/abstract_model/relatable.rb +22 -22
- data/lib/virtualbox/abstract_model/validatable.rb +4 -4
- data/lib/virtualbox/attached_device.rb +23 -23
- data/lib/virtualbox/command.rb +9 -9
- data/lib/virtualbox/dvd.rb +7 -7
- data/lib/virtualbox/ext/subclass_listing.rb +1 -1
- data/lib/virtualbox/extra_data.rb +17 -17
- data/lib/virtualbox/forwarded_port.rb +23 -23
- data/lib/virtualbox/hard_drive.rb +27 -27
- data/lib/virtualbox/image.rb +25 -18
- data/lib/virtualbox/nic.rb +22 -22
- data/lib/virtualbox/proxies/collection.rb +4 -4
- data/lib/virtualbox/shared_folder.rb +25 -25
- data/lib/virtualbox/storage_controller.rb +16 -16
- data/lib/virtualbox/vm.rb +95 -42
- data/test/virtualbox/abstract_model/attributable_test.rb +28 -28
- data/test/virtualbox/abstract_model/dirty_test.rb +13 -13
- data/test/virtualbox/abstract_model/relatable_test.rb +36 -36
- data/test/virtualbox/abstract_model/validatable_test.rb +22 -22
- data/test/virtualbox/abstract_model_test.rb +46 -36
- data/test/virtualbox/attached_device_test.rb +47 -47
- data/test/virtualbox/command_test.rb +12 -12
- data/test/virtualbox/dvd_test.rb +15 -19
- data/test/virtualbox/ext/subclass_listing_test.rb +2 -2
- data/test/virtualbox/extra_data_test.rb +37 -37
- data/test/virtualbox/forwarded_port_test.rb +31 -31
- data/test/virtualbox/hard_drive_test.rb +40 -48
- data/test/virtualbox/image_test.rb +36 -33
- data/test/virtualbox/nic_test.rb +22 -22
- data/test/virtualbox/proxies/collection_test.rb +6 -6
- data/test/virtualbox/shared_folder_test.rb +36 -36
- data/test/virtualbox/storage_controller_test.rb +14 -14
- data/test/virtualbox/vm_test.rb +121 -70
- data/test/virtualbox_test.rb +19 -0
- data/virtualbox.gemspec +5 -3
- metadata +4 -2
@@ -8,59 +8,59 @@ class CommandTest < Test::Unit::TestCase
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
context "executing commands" do
|
13
13
|
should "use backticks to execute the command" do
|
14
14
|
VirtualBox::Command.expects(:`).with("foo").once
|
15
15
|
VirtualBox::Command.execute("foo")
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
should "return the result of the execution" do
|
19
19
|
VirtualBox::Command.expects(:`).with("foo").returns("bar").once
|
20
20
|
assert_equal "bar", VirtualBox::Command.execute("foo")
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
context "vbox commands" do
|
25
25
|
should "call 'vboxmanage' followed by command" do
|
26
|
-
VirtualBox::Command.expects(:execute).with("VBoxManage foo")
|
26
|
+
VirtualBox::Command.expects(:execute).with("VBoxManage -q foo")
|
27
27
|
VirtualBox::Command.stubs(:success?).returns(true)
|
28
28
|
VirtualBox::Command.vboxmanage("foo")
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
should "call the custom vboxmanage executable if set" do
|
32
32
|
VirtualBox::Command.vboxmanage = "barf"
|
33
|
-
VirtualBox::Command.expects(:execute).with("barf foo")
|
33
|
+
VirtualBox::Command.expects(:execute).with("barf -q foo")
|
34
34
|
VirtualBox::Command.stubs(:success?).returns(true)
|
35
35
|
VirtualBox::Command.vboxmanage("foo")
|
36
36
|
VirtualBox::Command.vboxmanage = "VBoxManage"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
should "raise a CommandFailedException if it failed" do
|
40
|
-
VirtualBox::Command.expects(:execute).with("VBoxManage foo")
|
40
|
+
VirtualBox::Command.expects(:execute).with("VBoxManage -q foo")
|
41
41
|
VirtualBox::Command.stubs(:success?).returns(false)
|
42
42
|
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
43
43
|
VirtualBox::Command.vboxmanage("foo")
|
44
44
|
}
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
context "testing command results" do
|
49
49
|
setup do
|
50
50
|
@command = "foo"
|
51
51
|
VirtualBox::Command.stubs(:execute)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
should "return true if the exit code is 0" do
|
55
55
|
system("echo 'hello' 1>/dev/null")
|
56
56
|
assert_equal 0, $?.to_i
|
57
57
|
assert VirtualBox::Command.test(@command)
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
should "return false if the exit code is 1" do
|
61
61
|
system("there_is_no_way_this_can_exist_1234567890")
|
62
62
|
assert_not_equal 0, $?.to_i
|
63
|
-
assert !VirtualBox::Command.test(@command)
|
63
|
+
assert !VirtualBox::Command.test(@command)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
data/test/virtualbox/dvd_test.rb
CHANGED
@@ -4,26 +4,26 @@ class DVDTest < Test::Unit::TestCase
|
|
4
4
|
setup do
|
5
5
|
VirtualBox::Command.stubs(:execute)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
context "destroying a dvd" do
|
9
9
|
setup do
|
10
10
|
@dvd = VirtualBox::DVD.new
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
should "return false if attempting to destroy an empty drive" do
|
14
14
|
assert !VirtualBox::DVD.empty_drive.destroy
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
should "call vboxmanage to destroy it" do
|
18
18
|
VirtualBox::Command.expects(:vboxmanage).with("closemedium dvd #{@dvd.uuid} --delete")
|
19
19
|
assert @dvd.destroy
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "return false if destroy failed" do
|
23
23
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
24
24
|
assert !@dvd.destroy
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
should "raise an exception if failed and flag is set" do
|
28
28
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
29
29
|
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
@@ -31,19 +31,19 @@ class DVDTest < Test::Unit::TestCase
|
|
31
31
|
}
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
context "empty drive" do
|
36
36
|
should "return an empty drive instance by calling new with :empty_drive" do
|
37
37
|
dvd = VirtualBox::DVD.new(:empty_drive)
|
38
38
|
assert dvd.empty_drive?
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
should "call new with :empty_drive with empty_drive class method" do
|
42
42
|
dvd = VirtualBox::DVD.empty_drive
|
43
43
|
assert dvd.empty_drive?
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context "retrieving all dvds" do
|
48
48
|
setup do
|
49
49
|
@expectations = {
|
@@ -51,18 +51,14 @@ class DVDTest < Test::Unit::TestCase
|
|
51
51
|
:location => "/Users/mitchellh/Downloads/jeos-8.04.3-jeos-i386.iso",
|
52
52
|
:accessible => "yes"
|
53
53
|
},
|
54
|
-
|
54
|
+
|
55
55
|
"4a08f52c-bca3-4908-8da4-4f48aaa4ebba" => {
|
56
56
|
:location => "/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso",
|
57
57
|
:accessible => "yes"
|
58
58
|
}
|
59
59
|
}
|
60
|
-
|
61
|
-
@valid = <<-valid
|
62
|
-
VirtualBox Command Line Management Interface Version 3.1.2
|
63
|
-
(C) 2005-2009 Sun Microsystems, Inc.
|
64
|
-
All rights reserved.
|
65
60
|
|
61
|
+
@valid = <<-valid
|
66
62
|
UUID: d3252617-8176-4f8c-9d73-1c9c82b23960
|
67
63
|
Path: /Users/mitchellh/Downloads/jeos-8.04.3-jeos-i386.iso
|
68
64
|
Accessible: yes
|
@@ -75,23 +71,23 @@ valid
|
|
75
71
|
|
76
72
|
VirtualBox::Command.expects(:vboxmanage).with("list dvds").returns(@valid)
|
77
73
|
end
|
78
|
-
|
74
|
+
|
79
75
|
should "return an array of DVD objects" do
|
80
76
|
result = VirtualBox::DVD.all
|
81
77
|
assert result.is_a?(Array)
|
82
|
-
|
78
|
+
|
83
79
|
result.each { |v| assert v.is_a?(VirtualBox::DVD) }
|
84
80
|
end
|
85
|
-
|
81
|
+
|
86
82
|
should "return the proper results" do
|
87
83
|
result = VirtualBox::DVD.all
|
88
84
|
assert result.is_a?(Array)
|
89
85
|
assert_equal @expectations.length, result.length
|
90
|
-
|
86
|
+
|
91
87
|
result.each do |image|
|
92
88
|
expected_image = @expectations[image.uuid]
|
93
89
|
assert expected_image
|
94
|
-
|
90
|
+
|
95
91
|
expected_image.each do |k,v|
|
96
92
|
assert_equal v, image.read_attribute(k)
|
97
93
|
end
|
@@ -12,13 +12,13 @@ class SubclassListingTest < Test::Unit::TestCase
|
|
12
12
|
include VirtualBox::SubclassListing
|
13
13
|
end
|
14
14
|
class F < E; end
|
15
|
-
|
15
|
+
|
16
16
|
should "list subclasses, including sub-subclasses, etc" do
|
17
17
|
assert_equal [F], E.subclasses
|
18
18
|
assert_equal [C], B.subclasses
|
19
19
|
assert_equal [B, C, D], A.subclasses.sort_by { |c| c.name }
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "list direct subclasses if flag is set" do
|
23
23
|
assert_equal [B, D], A.subclasses(true).sort_by { |c| c.name }
|
24
24
|
end
|
@@ -9,7 +9,7 @@ Key: GUI/LastWindowPostion, Value: 99,457,770,550
|
|
9
9
|
Key: GUI/SUNOnlineData, Value: triesLeft=0
|
10
10
|
Key: GUI/SuppressMessages, Value: ,confirmInputCapture,remindAboutAutoCapture,confirmRemoveMedium,remindAboutInaccessibleMedia,confirmGoingFullscreen,remindAboutMouseIntegrationOn
|
11
11
|
Key: GUI/UpdateCheckCount, Value: 13
|
12
|
-
Key: GUI/UpdateDate, Value: 1 d, 2010-01-29, stable
|
12
|
+
Key: GUI/UpdateDate, Value: 1 d, 2010-01-29, stable
|
13
13
|
raw
|
14
14
|
|
15
15
|
VirtualBox::Command.stubs(:execute)
|
@@ -18,115 +18,115 @@ raw
|
|
18
18
|
@ed["foo"] = "bar"
|
19
19
|
@ed.clear_dirty!
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
context "attributes" do
|
23
23
|
should "return parent name if its a VM object" do
|
24
24
|
vm = mock("vm")
|
25
25
|
vm.stubs(:is_a?).with(VirtualBox::VM).returns(true)
|
26
26
|
vm.stubs(:name).returns("FOO")
|
27
|
-
|
27
|
+
|
28
28
|
@ed.parent = vm
|
29
29
|
assert_equal "FOO", @ed.parent_name
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should "return default otherwise" do
|
33
33
|
assert_equal "global", @ed.parent_name
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context "relationships" do
|
38
38
|
setup do
|
39
39
|
@caller = mock("caller")
|
40
40
|
@caller.stubs(:name).returns("foocaller")
|
41
|
-
|
42
|
-
VirtualBox::Command.stubs(:vboxmanage).returns(@raw)
|
41
|
+
|
42
|
+
VirtualBox::Command.stubs(:vboxmanage).returns(@raw)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
context "populating" do
|
46
46
|
should "call VBoxManage for the caller" do
|
47
47
|
VirtualBox::Command.expects(:vboxmanage).with("getextradata #{@caller.name} enumerate").returns(@raw)
|
48
48
|
VirtualBox::ExtraData.populate_relationship(@caller, {})
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
should "call pairs_to_objects with parent set to the caller" do
|
52
52
|
VirtualBox::ExtraData.expects(:parse_kv_pairs).with(@raw, @caller).once
|
53
|
-
VirtualBox::ExtraData.populate_relationship(@caller, {})
|
53
|
+
VirtualBox::ExtraData.populate_relationship(@caller, {})
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
should "return an array of ExtraData objects" do
|
57
57
|
result = VirtualBox::ExtraData.populate_relationship(@caller, {})
|
58
58
|
assert result.is_a?(VirtualBox::ExtraData)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
context "saving" do
|
63
63
|
should "call save on the ExtraData object" do
|
64
64
|
object = mock("object")
|
65
65
|
object.expects(:save).once
|
66
|
-
|
66
|
+
|
67
67
|
VirtualBox::ExtraData.save_relationship(@caller, object)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
context "destroying (deleting)" do
|
73
73
|
setup do
|
74
74
|
@key = "foo"
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
should "call the proper vbox command" do
|
78
78
|
VirtualBox::Command.expects(:vboxmanage).with("setextradata global foo")
|
79
79
|
assert @ed.delete(@key)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
should "remove the key from the hash" do
|
83
83
|
assert @ed.has_key?(@key)
|
84
84
|
assert @ed.delete(@key)
|
85
85
|
assert !@ed.has_key?(@key)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
should "raise an exception if true sent to save and error occured" do
|
89
89
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
90
90
|
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
91
91
|
@ed.delete(@key, true)
|
92
92
|
}
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
should "return false if the command failed" do
|
96
96
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
97
97
|
assert !@ed.delete(@key)
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
context "saving" do
|
102
102
|
setup do
|
103
103
|
@ed["foo"] = "BAR"
|
104
104
|
assert @ed.changed?
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
should "do nothing if there are no changes" do
|
108
108
|
@ed.clear_dirty!
|
109
109
|
VirtualBox::Command.expects(:vboxmanage).never
|
110
110
|
assert @ed.save
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
should "call the proper vbox command" do
|
114
114
|
VirtualBox::Command.expects(:vboxmanage).with("setextradata global foo BAR")
|
115
115
|
assert @ed.save
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
should "return false if the command failed" do
|
119
119
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
120
120
|
assert !@ed.save
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
should "raise an exception if true sent to save and error occured" do
|
124
124
|
VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
|
125
125
|
assert_raises(VirtualBox::Exceptions::CommandFailedException) {
|
126
126
|
@ed.save(true)
|
127
127
|
}
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
should "clear dirty state" do
|
131
131
|
@ed["value"] = "rawr"
|
132
132
|
assert @ed.changed?
|
@@ -143,14 +143,14 @@ raw
|
|
143
143
|
should "not be dirty initially" do
|
144
144
|
assert !@ed.changed?
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
should "be dirty when setting a value" do
|
148
148
|
@ed["foo"] = "bar"
|
149
149
|
assert @ed.changed?
|
150
150
|
assert @ed.changes.has_key?("foo")
|
151
151
|
end
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
context "global extra data" do
|
155
155
|
setup do
|
156
156
|
get_seq = sequence("get_seq")
|
@@ -158,59 +158,59 @@ raw
|
|
158
158
|
VirtualBox::ExtraData.expects(:parse_kv_pairs).returns(@ed).once.in_sequence(get_seq)
|
159
159
|
@global = VirtualBox::ExtraData.global(true)
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
should "call the command, parse it, then turn it into objects" do
|
163
163
|
assert_equal "bar", @global["foo"]
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
should "return the same object if it exists for global data, rather than recreating it" do
|
167
167
|
VirtualBox::Command.expects(:vboxmanage).never
|
168
168
|
assert_equal @global, VirtualBox::ExtraData.global
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
should "return a new object if reload is true" do
|
172
172
|
VirtualBox::Command.expects(:vboxmanage).once
|
173
173
|
VirtualBox::ExtraData.expects(:parse_kv_pairs).returns(@ed.dup).once
|
174
174
|
assert !@global.equal?(VirtualBox::ExtraData.global(true))
|
175
175
|
end
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
context "constructor" do
|
179
179
|
should "set the parent with the given argument" do
|
180
180
|
ed = VirtualBox::ExtraData.new("JOEY")
|
181
181
|
assert_equal "JOEY", ed.parent
|
182
182
|
end
|
183
|
-
|
183
|
+
|
184
184
|
should "be global by default" do
|
185
185
|
ed = VirtualBox::ExtraData.new
|
186
186
|
assert_equal "global", ed.parent
|
187
187
|
end
|
188
188
|
end
|
189
|
-
|
189
|
+
|
190
190
|
context "parsing KV pairs" do
|
191
191
|
setup do
|
192
192
|
@data = VirtualBox::ExtraData.parse_kv_pairs(@raw)
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
should "return the proper number of items" do
|
196
196
|
# Shows that it skips over non-matching lines as well
|
197
197
|
assert_equal 6, @data.length
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
should "return as an ExtraData Hash" do
|
201
201
|
assert @data.is_a?(Hash)
|
202
202
|
assert @data.is_a?(VirtualBox::ExtraData)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
should "return proper values, trimmed" do
|
206
206
|
assert_equal "1 d, 2010-01-29, stable", @data["GUI/UpdateDate"]
|
207
207
|
end
|
208
|
-
|
208
|
+
|
209
209
|
should "send the 2nd param as the parent to the ED object" do
|
210
210
|
@data = VirtualBox::ExtraData.parse_kv_pairs(@raw, "FOO")
|
211
211
|
assert_equal "FOO", @data.parent
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
should "return an unchanged ED object" do
|
215
215
|
assert !@data.changed?
|
216
216
|
end
|
@@ -4,7 +4,7 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
4
4
|
setup do
|
5
5
|
@caller = mock("caller")
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
context "validations" do
|
9
9
|
setup do
|
10
10
|
@port = VirtualBox::ForwardedPort.new
|
@@ -13,16 +13,16 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
13
13
|
@port.hostport = "2222"
|
14
14
|
@port.added_to_relationship(@caller)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
should "be valid with all fields" do
|
18
18
|
assert @port.valid?
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
should "be invalid with no name" do
|
22
22
|
@port.name = nil
|
23
23
|
assert !@port.valid?
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
should "be invalid with no guest port" do
|
27
27
|
@port.guestport = nil
|
28
28
|
assert !@port.valid?
|
@@ -32,13 +32,13 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
32
32
|
@port.hostport = nil
|
33
33
|
assert !@port.valid?
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
should "be invalid if not in a relationship" do
|
37
37
|
@port.write_attribute(:parent, nil)
|
38
38
|
assert !@port.valid?
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context "with an instance" do
|
43
43
|
setup do
|
44
44
|
@port = VirtualBox::ForwardedPort.new({
|
@@ -47,67 +47,67 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
47
47
|
:guestport => "22",
|
48
48
|
:hostport => "2222"
|
49
49
|
})
|
50
|
-
|
50
|
+
|
51
51
|
@ed = mock("extradata")
|
52
52
|
@ed.stubs(:[]=)
|
53
53
|
@ed.stubs(:save)
|
54
54
|
@ed.stubs(:delete)
|
55
55
|
@caller.stubs(:extra_data).returns(@ed)
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
context "saving" do
|
59
59
|
context "an existing record" do
|
60
60
|
setup do
|
61
61
|
@port.existing_record!
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
should "not do anything and return true if its unchanged" do
|
65
65
|
@caller.expects(:extra_data).never
|
66
66
|
assert @port.save
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
should "clear the dirty state after saving" do
|
70
70
|
@port.name = "diff"
|
71
71
|
@port.save
|
72
72
|
assert !@port.changed?
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
should "call destroy if the name changed" do
|
76
76
|
@port.name = "diff"
|
77
77
|
@port.expects(:destroy).once
|
78
78
|
@port.save
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
should "not call destroy if the name didn't change" do
|
82
82
|
assert !@port.name_changed?
|
83
83
|
@port.expects(:destroy).never
|
84
84
|
@port.save
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
context "a new record" do
|
89
89
|
setup do
|
90
90
|
assert @port.new_record!
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
should "no longer be a new record after saving" do
|
94
94
|
@port.save
|
95
95
|
assert !@port.new_record?
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
should "return false and do nothing if invalid" do
|
99
99
|
@caller.expects(:extra_data).never
|
100
100
|
@port.expects(:valid?).returns(false)
|
101
101
|
assert !@port.save
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
should "raise a ValidationFailedException if invalid and raise_errors is true" do
|
105
105
|
@port.expects(:valid?).returns(false)
|
106
106
|
assert_raises(VirtualBox::Exceptions::ValidationFailedException) {
|
107
107
|
@port.save(true)
|
108
108
|
}
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
should "call save on the extra_data" do
|
112
112
|
@ed = mock("ed")
|
113
113
|
@ed.expects(:[]=).times(3)
|
@@ -117,49 +117,49 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
context "key prefix" do
|
122
122
|
should "return a proper key prefix constructed with the attributes" do
|
123
123
|
assert_equal "VBoxInternal\/Devices\/#{@port.device}\/#{@port.instance}\/LUN#0\/Config\/#{@port.name}\/", @port.key_prefix
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
should "return with previous name if parameter is true" do
|
127
127
|
@port.name = "diff"
|
128
128
|
assert @port.name_changed?
|
129
129
|
assert_equal "VBoxInternal\/Devices\/#{@port.device}\/#{@port.instance}\/LUN#0\/Config\/#{@port.name_was}\/", @port.key_prefix(true)
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
should "not use previous name if parameter is true and name didn't change" do
|
133
133
|
assert !@port.name_changed?
|
134
134
|
assert_equal "VBoxInternal\/Devices\/#{@port.device}\/#{@port.instance}\/LUN#0\/Config\/#{@port.name}\/", @port.key_prefix(true)
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
context "destroying" do
|
139
139
|
setup do
|
140
140
|
@port.existing_record!
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
should "call delete on the extra data for each key" do
|
144
144
|
@ed = mock("ed")
|
145
145
|
@ed.expects(:delete).times(3)
|
146
146
|
@caller.expects(:extra_data).times(3).returns(@ed)
|
147
147
|
@port.destroy
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
should "do nothing if the record is new" do
|
151
151
|
@port.new_record!
|
152
152
|
@caller.expects(:extra_data).never
|
153
153
|
@port.destroy
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
should "be a new record after destroying" do
|
157
157
|
@port.destroy
|
158
158
|
assert @port.new_record?
|
159
159
|
end
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
context "relationships" do
|
164
164
|
context "saving" do
|
165
165
|
should "call #save on every object" do
|
@@ -169,11 +169,11 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
169
169
|
object.expects(:save).once
|
170
170
|
objects.push(object)
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
VirtualBox::ForwardedPort.save_relationship(@caller, objects)
|
174
174
|
end
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
context "populating" do
|
178
178
|
setup do
|
179
179
|
@caller.stubs(:extra_data).returns({
|
@@ -182,22 +182,22 @@ class ForwardedPortTest < Test::Unit::TestCase
|
|
182
182
|
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" => "2222",
|
183
183
|
"VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" => "TCP"
|
184
184
|
})
|
185
|
-
|
185
|
+
|
186
186
|
@objects = VirtualBox::ForwardedPort.populate_relationship(@caller, {})
|
187
187
|
end
|
188
|
-
|
188
|
+
|
189
189
|
should "return an array of ForwardedPorts" do
|
190
190
|
assert @objects.is_a?(VirtualBox::Proxies::Collection)
|
191
191
|
assert @objects.all? { |o| o.is_a?(VirtualBox::ForwardedPort) }
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
should "have the proper data" do
|
195
195
|
object = @objects.first
|
196
196
|
assert_equal "22", object.guestport
|
197
197
|
assert_equal "2222", object.hostport
|
198
198
|
assert_equal "TCP", object.protocol
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
should "be existing records" do
|
202
202
|
assert !@objects.first.new_record?
|
203
203
|
end
|