derelict_m 0.6.2a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.cane +2 -0
  3. data/.coveralls.yml +1 -0
  4. data/.gitignore +18 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +99 -0
  9. data/Rakefile +22 -0
  10. data/derelict.gemspec +63 -0
  11. data/lib/derelict.rb +74 -0
  12. data/lib/derelict/box.rb +29 -0
  13. data/lib/derelict/box/manager.rb +111 -0
  14. data/lib/derelict/box/not_found.rb +16 -0
  15. data/lib/derelict/connection.rb +84 -0
  16. data/lib/derelict/connection/invalid.rb +14 -0
  17. data/lib/derelict/connection/not_found.rb +13 -0
  18. data/lib/derelict/exception.rb +6 -0
  19. data/lib/derelict/exception/optional_reason.rb +32 -0
  20. data/lib/derelict/executer.rb +237 -0
  21. data/lib/derelict/instance.rb +147 -0
  22. data/lib/derelict/instance/command_failed.rb +30 -0
  23. data/lib/derelict/instance/invalid.rb +14 -0
  24. data/lib/derelict/instance/missing_binary.rb +13 -0
  25. data/lib/derelict/instance/non_directory.rb +13 -0
  26. data/lib/derelict/instance/not_found.rb +13 -0
  27. data/lib/derelict/parser.rb +27 -0
  28. data/lib/derelict/parser/box_list.rb +53 -0
  29. data/lib/derelict/parser/box_list/invalid_format.rb +16 -0
  30. data/lib/derelict/parser/plugin_list.rb +63 -0
  31. data/lib/derelict/parser/plugin_list/invalid_format.rb +16 -0
  32. data/lib/derelict/parser/plugin_list/needs_reinstall.rb +22 -0
  33. data/lib/derelict/parser/status.rb +90 -0
  34. data/lib/derelict/parser/status/invalid_format.rb +16 -0
  35. data/lib/derelict/parser/version.rb +28 -0
  36. data/lib/derelict/parser/version/invalid_format.rb +16 -0
  37. data/lib/derelict/plugin.rb +29 -0
  38. data/lib/derelict/plugin/manager.rb +107 -0
  39. data/lib/derelict/plugin/not_found.rb +14 -0
  40. data/lib/derelict/utils.rb +11 -0
  41. data/lib/derelict/utils/logger.rb +59 -0
  42. data/lib/derelict/utils/logger/array_outputter.rb +43 -0
  43. data/lib/derelict/utils/logger/invalid_type.rb +15 -0
  44. data/lib/derelict/utils/logger/raw_formatter.rb +12 -0
  45. data/lib/derelict/version.rb +3 -0
  46. data/lib/derelict/virtual_machine.rb +190 -0
  47. data/lib/derelict/virtual_machine/invalid.rb +14 -0
  48. data/lib/derelict/virtual_machine/not_found.rb +18 -0
  49. data/spec/coverage_helper.rb +19 -0
  50. data/spec/derelict/box/manager_spec.rb +171 -0
  51. data/spec/derelict/box/not_found_spec.rb +13 -0
  52. data/spec/derelict/box_spec.rb +37 -0
  53. data/spec/derelict/connection/invalid_spec.rb +16 -0
  54. data/spec/derelict/connection/not_found_spec.rb +13 -0
  55. data/spec/derelict/connection_spec.rb +107 -0
  56. data/spec/derelict/exception/optional_reason_spec.rb +41 -0
  57. data/spec/derelict/exception_spec.rb +11 -0
  58. data/spec/derelict/executer_spec.rb +129 -0
  59. data/spec/derelict/instance/command_failed_spec.rb +40 -0
  60. data/spec/derelict/instance/invalid_spec.rb +16 -0
  61. data/spec/derelict/instance/missing_binary_spec.rb +13 -0
  62. data/spec/derelict/instance/non_directory_spec.rb +13 -0
  63. data/spec/derelict/instance/not_found_spec.rb +13 -0
  64. data/spec/derelict/instance_spec.rb +258 -0
  65. data/spec/derelict/parser/box_list/invalid_format_spec.rb +16 -0
  66. data/spec/derelict/parser/box_list_spec.rb +64 -0
  67. data/spec/derelict/parser/plugin_list/invalid_format_spec.rb +16 -0
  68. data/spec/derelict/parser/plugin_list/needs_reinstall_spec.rb +13 -0
  69. data/spec/derelict/parser/plugin_list_spec.rb +82 -0
  70. data/spec/derelict/parser/status/invalid_format_spec.rb +16 -0
  71. data/spec/derelict/parser/status_spec.rb +214 -0
  72. data/spec/derelict/parser/version/invalid_format_spec.rb +16 -0
  73. data/spec/derelict/parser/version_spec.rb +42 -0
  74. data/spec/derelict/parser_spec.rb +24 -0
  75. data/spec/derelict/plugin/manager_spec.rb +208 -0
  76. data/spec/derelict/plugin/not_found_spec.rb +13 -0
  77. data/spec/derelict/plugin_spec.rb +37 -0
  78. data/spec/derelict/utils/logger/array_outputter_spec.rb +40 -0
  79. data/spec/derelict/utils/logger/invalid_type_spec.rb +13 -0
  80. data/spec/derelict/utils/logger/raw_formatter_spec.rb +17 -0
  81. data/spec/derelict/utils/logger_spec.rb +35 -0
  82. data/spec/derelict/virtual_machine/invalid_spec.rb +16 -0
  83. data/spec/derelict/virtual_machine/not_found_spec.rb +34 -0
  84. data/spec/derelict/virtual_machine_spec.rb +356 -0
  85. data/spec/derelict_spec.rb +50 -0
  86. data/spec/spec_helper.rb +32 -0
  87. data/spec/support/log_context.rb +36 -0
  88. metadata +332 -0
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::BoxList::InvalidFormat do
4
+ it "is autoloaded" do
5
+ should be_a Derelict::Parser::BoxList::InvalidFormat
6
+ end
7
+
8
+ context "when using default reason" do
9
+ its(:message) { should eq "Output from 'vagrant box list' was in an unexpected format" }
10
+ end
11
+
12
+ context "when using custom reason" do
13
+ subject { Derelict::Parser::BoxList::InvalidFormat.new "reason" }
14
+ its(:message) { should eq "Output from 'vagrant box list' was in an unexpected format: reason" }
15
+ end
16
+ end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::BoxList do
4
+ subject { Derelict::Parser::BoxList.new output }
5
+ let(:output) { nil }
6
+
7
+ it "is autoloaded" do
8
+ should be_a Derelict::Parser::BoxList
9
+ end
10
+
11
+ describe "#boxes" do
12
+ subject { Derelict::Parser::BoxList.new(output).boxes }
13
+
14
+ include_context "logged messages"
15
+ let(:expected_logs) {[
16
+ "DEBUG boxlist: Successfully initialized Derelict::Parser::BoxList instance\n",
17
+ ]}
18
+
19
+ context "with valid output" do
20
+ let(:output) {
21
+ <<-END.gsub /^ +/, ""
22
+ foobar (provider_one)
23
+ baz (provider_two)
24
+ END
25
+ }
26
+
27
+ let(:foobar) { Derelict::Box.new "foobar", "provider_one" }
28
+ let(:baz) { Derelict::Box.new "baz", "provider_two" }
29
+ it { should eq Set[foobar, baz] }
30
+
31
+ context "with versioned boxes" do
32
+ let(:output) { "qux (foo, 0)" }
33
+ let(:qux) { Derelict::Box.new "qux", "foo" }
34
+ it { should eq Set[qux] }
35
+ end
36
+ end
37
+
38
+ context "with invalid output" do
39
+ context "with text after brackets" do
40
+ let(:output) { "foobar (provider_one) lolwut" }
41
+ it "should raise InvalidFormat" do
42
+ expect { subject }.to raise_error Derelict::Parser::BoxList::InvalidFormat
43
+ end
44
+ end
45
+
46
+ context "with no brackets" do
47
+ let(:output) { "baz with no brackets" }
48
+ it "should raise InvalidFormat" do
49
+ expect { subject }.to raise_error Derelict::Parser::BoxList::InvalidFormat
50
+ end
51
+ end
52
+ end
53
+
54
+ context "with no boxes in list" do
55
+ let(:output) {
56
+ <<-END.gsub /^ +/, ""
57
+ There are no installed boxes! Use `vagrant box add` to add some.
58
+ END
59
+ }
60
+
61
+ it { should eq Set.new }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::PluginList::InvalidFormat do
4
+ it "is autoloaded" do
5
+ should be_a Derelict::Parser::PluginList::InvalidFormat
6
+ end
7
+
8
+ context "when using default reason" do
9
+ its(:message) { should eq "Output from 'vagrant plugin list' was in an unexpected format" }
10
+ end
11
+
12
+ context "when using custom reason" do
13
+ subject { Derelict::Parser::PluginList::InvalidFormat.new "reason" }
14
+ its(:message) { should eq "Output from 'vagrant plugin list' was in an unexpected format: reason" }
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::PluginList::NeedsReinstall do
4
+ let(:output) { double("output") }
5
+ subject { Derelict::Parser::PluginList::NeedsReinstall.new output }
6
+
7
+ it "is autoloaded" do
8
+ should be_a Derelict::Parser::PluginList::NeedsReinstall
9
+ end
10
+
11
+ its(:message) { should eq "Vagrant plugins installed before upgrading to version 1.4.x need to be uninstalled and re-installed." }
12
+ its(:output) { should be output }
13
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::PluginList do
4
+ let(:parser) { Derelict::Parser::PluginList.new output }
5
+ let(:output) { nil }
6
+ subject { parser }
7
+
8
+ it "is autoloaded" do
9
+ should be_a Derelict::Parser::PluginList
10
+ end
11
+
12
+ describe "#plugins" do
13
+ subject { parser.plugins }
14
+
15
+ context "with valid output" do
16
+ let(:output) {
17
+ <<-END.gsub /^ +/, ""
18
+ foo (2.3.4)
19
+ bar (1.2.3, system)
20
+ END
21
+ }
22
+
23
+ subject { Derelict::Parser::PluginList.new(output).plugins }
24
+ let(:foo) { Derelict::Plugin.new "foo", "2.3.4" }
25
+ let(:bar) { Derelict::Plugin.new "bar", "1.2.3" }
26
+ it { should eq Set[foo, bar] }
27
+
28
+ include_context "logged messages"
29
+ let(:expected_logs) {[
30
+ "DEBUG pluginlist: Successfully initialized Derelict::Parser::PluginList instance\n",
31
+ ]}
32
+
33
+ context "with version constraints" do
34
+ let(:output) {
35
+ <<-END.gsub /^ {12}/, ""
36
+ foo (5.6.7)
37
+ - Version Constraint: 5.6.7
38
+ bar-baz (0.1.1, system)
39
+ END
40
+ }
41
+
42
+ let(:foo) { Derelict::Plugin.new "foo", "5.6.7" }
43
+ let(:bar) { Derelict::Plugin.new "bar-baz", "0.1.1" }
44
+ it { should eq Set[foo, bar] }
45
+ end
46
+ end
47
+
48
+ context "with plugins needing re-install" do
49
+ let(:output) {
50
+ <<-END.gsub /^ {10}/, ""
51
+ The following plugins were installed with a version of Vagrant
52
+ that had different versions of underlying components. Because
53
+ these component versions were changed (which rarely happens),
54
+ the plugins must be uninstalled and reinstalled.
55
+
56
+ To ensure that all the dependencies are properly updated as well
57
+ it is _highly recommended_ to do a `vagrant plugin uninstall`
58
+ prior to reinstalling.
59
+
60
+ This message will not go away until all the plugins below are
61
+ either uninstalled or uninstalled then reinstalled.
62
+
63
+ The plugins below will not be loaded until they're uninstalled
64
+ and reinstalled:
65
+
66
+ foo, bar
67
+ foo (2.3.4)
68
+ bar (1.2.3)
69
+ END
70
+ }
71
+
72
+ it "should raise NeedsReinstall" do
73
+ expect { subject }.to raise_error(Derelict::Parser::PluginList::NeedsReinstall)
74
+ end
75
+
76
+ include_context "logged messages"
77
+ let(:expected_logs) {[
78
+ "DEBUG pluginlist: Successfully initialized Derelict::Parser::PluginList instance\n",
79
+ ]}
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::Status::InvalidFormat do
4
+ it "is autoloaded" do
5
+ should be_a Derelict::Parser::Status::InvalidFormat
6
+ end
7
+
8
+ context "when using default reason" do
9
+ its(:message) { should eq "Output from 'vagrant status' was in an unexpected format" }
10
+ end
11
+
12
+ context "when using custom reason" do
13
+ subject { Derelict::Parser::Status::InvalidFormat.new "reason" }
14
+ its(:message) { should eq "Output from 'vagrant status' was in an unexpected format: reason" }
15
+ end
16
+ end
@@ -0,0 +1,214 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::Status do
4
+ subject { Derelict::Parser::Status.new output }
5
+ let(:output) { nil }
6
+
7
+ it "is autoloaded" do
8
+ should be_a Derelict::Parser::Status
9
+ end
10
+
11
+ context "with valid output" do
12
+ let(:output) {
13
+ <<-END.gsub /^ +/, ""
14
+ Current machine states:
15
+
16
+ foo not created (virtualbox)
17
+
18
+ The environment has not yet been created. Run `vagrant up` to
19
+ create the environment. If a machine is not created, only the
20
+ default provider will be shown. So if a provider is not listed,
21
+ then the machine is not created for that environment.
22
+ END
23
+ }
24
+
25
+ describe "#vm_names" do
26
+ subject { Derelict::Parser::Status.new(output).vm_names }
27
+ it { should eq Set[:foo] }
28
+
29
+ include_context "logged messages"
30
+ let(:expected_logs) {[
31
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
32
+ "DEBUG status: Parsing states from VM list using Derelict::Parser::Status instance\n",
33
+ "DEBUG status: Parsing VM list from output using Derelict::Parser::Status instance\n",
34
+ ]}
35
+ end
36
+
37
+ describe "#exists?" do
38
+ it "should return true for 'foo' VM" do
39
+ expect(subject.exists?(:foo)).to be true
40
+ end
41
+
42
+ it "should return false for unknown VM" do
43
+ expect(subject.exists?(:bar)).to be false
44
+ end
45
+
46
+ include_context "logged messages"
47
+ let(:expected_logs) {[
48
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
49
+ ]}
50
+ end
51
+
52
+ describe "#state" do
53
+ it "should return :not_created for 'foo' VM" do
54
+ expect(subject.state(:foo)).to be :not_created
55
+ end
56
+
57
+ it "should return :not_created for unknown VM" do
58
+ type = Derelict::VirtualMachine::NotFound
59
+ expect { subject.state(:bar) }.to raise_error type
60
+ end
61
+
62
+ include_context "logged messages"
63
+ let(:expected_logs) {[
64
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
65
+ ]}
66
+ end
67
+ end
68
+
69
+ context "with multi-machine output" do
70
+ let(:output) {
71
+ <<-END.gsub /^ +/, ""
72
+ Current machine states:
73
+
74
+ foo not created (virtualbox)
75
+ bar not created (virtualbox)
76
+
77
+ This environment represents multiple VMs. The VMs are all listed
78
+ above with their current state. For more information about a specific
79
+ VM, run `vagrant status NAME`.
80
+ END
81
+ }
82
+
83
+ describe "#vm_names" do
84
+ subject { Derelict::Parser::Status.new(output).vm_names }
85
+ it { should eq Set[:foo, :bar] }
86
+
87
+ include_context "logged messages"
88
+ let(:expected_logs) {[
89
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
90
+ "DEBUG status: Parsing states from VM list using Derelict::Parser::Status instance\n",
91
+ "DEBUG status: Parsing VM list from output using Derelict::Parser::Status instance\n",
92
+ ]}
93
+ end
94
+
95
+ describe "#exists?" do
96
+ it "should return true for 'foo' VM" do
97
+ expect(subject.exists?(:foo)).to be true
98
+ end
99
+
100
+ it "should return true for 'bar' VM" do
101
+ expect(subject.exists?(:bar)).to be true
102
+ end
103
+
104
+ it "should return false for unknown VM" do
105
+ expect(subject.exists?(:baz)).to be false
106
+ end
107
+
108
+ include_context "logged messages"
109
+ let(:expected_logs) {[
110
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
111
+ ]}
112
+ end
113
+
114
+ describe "#state" do
115
+ it "should return :not_created for 'foo' VM" do
116
+ expect(subject.state(:foo)).to be :not_created
117
+ end
118
+
119
+ it "should return :not_created for 'bar' VM" do
120
+ expect(subject.state(:bar)).to be :not_created
121
+ end
122
+
123
+ it "should return :not_created for unknown VM" do
124
+ type = Derelict::VirtualMachine::NotFound
125
+ expect { subject.state(:baz) }.to raise_error type
126
+ end
127
+
128
+ include_context "logged messages"
129
+ let(:expected_logs) {[
130
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
131
+ ]}
132
+ end
133
+ end
134
+
135
+
136
+ context "with invalid list format" do
137
+ let(:output) {
138
+ <<-END.gsub /^ +/, ""
139
+ This output is missing the list of virtual machines.
140
+ END
141
+ }
142
+
143
+ describe "#vm_names" do
144
+ subject { Derelict::Parser::Status.new(output).vm_names }
145
+ it "should raise InvalidFormat" do
146
+ type = Derelict::Parser::Status::InvalidFormat
147
+ message = [
148
+ "Output from 'vagrant status' was in an unexpected format: ",
149
+ "Couldn't find VM list",
150
+ ].join
151
+ expect { subject }.to raise_error type, message
152
+ end
153
+
154
+ include_context "logged messages"
155
+ let(:expected_logs) {[
156
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
157
+ "DEBUG status: Parsing states from VM list using Derelict::Parser::Status instance\n",
158
+ "DEBUG status: Parsing VM list from output using Derelict::Parser::Status instance\n",
159
+ ]}
160
+ end
161
+
162
+ describe "#state" do
163
+ subject { Derelict::Parser::Status.new(output).state(:foo) }
164
+ it "should raise InvalidFormat" do
165
+ type = Derelict::Parser::Status::InvalidFormat
166
+ message = [
167
+ "Output from 'vagrant status' was in an unexpected format: ",
168
+ "Couldn't find VM list",
169
+ ].join
170
+ expect { subject }.to raise_error type, message
171
+ end
172
+
173
+ include_context "logged messages"
174
+ let(:expected_logs) {[
175
+ "DEBUG status: Successfully initialized Derelict::Parser::Status instance\n",
176
+ "DEBUG status: Parsing states from VM list using Derelict::Parser::Status instance\n",
177
+ "DEBUG status: Parsing VM list from output using Derelict::Parser::Status instance\n",
178
+ ]}
179
+ end
180
+ end
181
+
182
+ context "with invalid VM format" do
183
+ let(:output) {
184
+ <<-END.gsub /^ +/, ""
185
+ Current machine states:
186
+
187
+ foo this line is missing brackets!
188
+ bar not created (virtualbox)
189
+
190
+ This environment represents multiple VMs. The VMs are all listed
191
+ above with their current state. For more information about a specific
192
+ VM, run `vagrant status NAME`.
193
+ END
194
+ }
195
+
196
+ describe "#vm_names" do
197
+ subject { Derelict::Parser::Status.new(output).vm_names }
198
+ it "should raise InvalidFormat" do
199
+ type = Derelict::Parser::Status::InvalidFormat
200
+ message = "Output from 'vagrant status' was in an unexpected format: Couldn't parse VM list"
201
+ expect { subject.parse! }.to raise_error type, message
202
+ end
203
+ end
204
+
205
+ describe "#state" do
206
+ subject { Derelict::Parser::Status.new(output).state(:foo) }
207
+ it "should raise InvalidFormat" do
208
+ type = Derelict::Parser::Status::InvalidFormat
209
+ message = "Output from 'vagrant status' was in an unexpected format: Couldn't parse VM list"
210
+ expect { subject }.to raise_error type, message
211
+ end
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::Version::InvalidFormat do
4
+ it "is autoloaded" do
5
+ should be_a Derelict::Parser::Version::InvalidFormat
6
+ end
7
+
8
+ context "when using default reason" do
9
+ its(:message) { should eq "Output from 'vagrant --version' was in an unexpected format" }
10
+ end
11
+
12
+ context "when using custom reason" do
13
+ subject { Derelict::Parser::Version::InvalidFormat.new "reason" }
14
+ its(:message) { should eq "Output from 'vagrant --version' was in an unexpected format: reason" }
15
+ end
16
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser::Version do
4
+ let(:parser) { Derelict::Parser::Version.new stdout }
5
+
6
+ describe "#version" do
7
+ subject { parser.version }
8
+
9
+ context "with 'Vagrant version 1.0.7'" do
10
+ let(:stdout) { "Vagrant version 1.0.7\n" }
11
+ it { should eq "1.0.7" }
12
+
13
+ include_context "logged messages"
14
+ let(:expected_logs) {[
15
+ "DEBUG version: Successfully initialized Derelict::Parser::Version instance\n",
16
+ "DEBUG version: Parsing version from output using Derelict::Parser::Version instance\n",
17
+ ]}
18
+ end
19
+
20
+ context "with 'Vagrant v1.3.4'" do
21
+ let(:stdout) { "Vagrant v1.3.4\n" }
22
+ it { should eq "1.3.4" }
23
+
24
+ include_context "logged messages"
25
+ let(:expected_logs) {[
26
+ "DEBUG version: Successfully initialized Derelict::Parser::Version instance\n",
27
+ "DEBUG version: Parsing version from output using Derelict::Parser::Version instance\n",
28
+ ]}
29
+ end
30
+
31
+ context "with 'Vagrant 1.3.3'" do
32
+ let(:stdout) { "Vagrant 1.3.3\n" }
33
+ it { should eq "1.3.3" }
34
+
35
+ include_context "logged messages"
36
+ let(:expected_logs) {[
37
+ "DEBUG version: Successfully initialized Derelict::Parser::Version instance\n",
38
+ "DEBUG version: Parsing version from output using Derelict::Parser::Version instance\n",
39
+ ]}
40
+ end
41
+ end
42
+ end