derelict_m 0.6.2a

Sign up to get free protection for your applications and to get access to all the features.
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,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Parser do
4
+ let(:output) { nil }
5
+ subject { Derelict::Parser.new output }
6
+
7
+ it "is autoloaded" do
8
+ should be_a Derelict::Parser
9
+ end
10
+
11
+ describe "#initialize" do
12
+ let(:output) { "the output" }
13
+ let(:description) { "test parser" }
14
+
15
+ it "should store output" do
16
+ expect(subject.output).to eq "the output"
17
+ end
18
+
19
+ include_context "logged messages"
20
+ let(:expected_logs) {[
21
+ "DEBUG parser: Successfully initialized Derelict::Parser (unknown type)\n",
22
+ ]}
23
+ end
24
+ end
@@ -0,0 +1,208 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Plugin::Manager do
4
+ let(:instance) { double("instance", :description => "test instance") }
5
+ let(:manager) { Derelict::Plugin::Manager.new instance }
6
+ subject { manager }
7
+
8
+ it "is autoloaded" do
9
+ should be_a Derelict::Plugin::Manager
10
+ end
11
+
12
+ include_context "logged messages"
13
+ let(:expected_logs) {[
14
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n"
15
+ ]}
16
+
17
+ describe "#list" do
18
+ let(:stdout) { "stdout\n" }
19
+ let(:result) { double("result", :stdout => stdout) }
20
+ let(:parser) { double("parser", :plugins => plugins) }
21
+ let(:plugins) { [:foo, :bar] }
22
+
23
+ subject { manager.list }
24
+
25
+ before do
26
+ expect(instance).to receive(:execute!).with(:plugin, "list").and_return(result)
27
+ expect(Derelict::Parser::PluginList).to receive(:new).with(stdout).and_return(parser)
28
+ end
29
+
30
+ it { should be plugins }
31
+
32
+ include_context "logged messages"
33
+ let(:expected_logs) {[
34
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
35
+ " INFO manager: Retrieving Vagrant plugin list for Derelict::Plugin::Manager for test instance\n",
36
+ ]}
37
+ end
38
+
39
+ describe "#installed?" do
40
+ let(:plugin_name) { double("plugin_name") }
41
+ let(:plugin) { double("plugin", :version => plugin_version) }
42
+ let(:plugin_version) { nil }
43
+ let(:version) { nil }
44
+ subject { manager.installed? plugin_name, version }
45
+
46
+ context "with known plugin" do
47
+ before { expect(manager).to receive(:fetch).with(plugin_name).and_return(plugin) }
48
+
49
+ context "with version" do
50
+ let(:version) { "1.2.3" }
51
+ let(:plugin_version) { "1.2.3" }
52
+ it { should be true }
53
+ end
54
+
55
+ context "with wrong version" do
56
+ let(:version) { "1.2.3" }
57
+ let(:plugin_version) { "2.3.4" }
58
+ it { should be false }
59
+ end
60
+
61
+ context "without version" do
62
+ it { should be true }
63
+ end
64
+ end
65
+
66
+ context "with unknown plugin" do
67
+ before { expect(manager).to receive(:fetch).with(plugin_name).and_raise(Derelict::Plugin::NotFound.new plugin_name) }
68
+
69
+ context "with version" do
70
+ let(:version) { "3.4.5" }
71
+ it { should be false }
72
+ end
73
+
74
+ context "without version" do
75
+ it { should be false }
76
+ end
77
+ end
78
+
79
+ include_context "logged messages"
80
+ let(:expected_logs) {[
81
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
82
+ " INFO manager: Retrieving Vagrant plugin list for Derelict::Plugin::Manager for test instance\n",
83
+ ]}
84
+ end
85
+
86
+ describe "#install" do
87
+ let(:log) { true }
88
+ let(:plugin_name) { double("plugin_name", :to_s => "test plugin") }
89
+ let(:version) { double("version") }
90
+ let(:result) { double("result") }
91
+ subject { manager.install plugin_name, :version => version, :log => log }
92
+
93
+ before do
94
+ expect(instance).to receive(:execute!).with(:plugin, "install", plugin_name, '--plugin-version', version).and_yield("test", nil).and_return(result)
95
+ end
96
+
97
+ it { should be result }
98
+
99
+ context "with logging enabled" do
100
+ include_context "logged messages"
101
+ let(:expected_logs) {[
102
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
103
+ " INFO manager: Installing plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
104
+ " INFO external: test\n",
105
+ ]}
106
+ end
107
+
108
+ context "with logging disabled" do
109
+ let(:log) { false }
110
+ include_context "logged messages"
111
+ let(:expected_logs) {[
112
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
113
+ " INFO manager: Installing plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
114
+ ]}
115
+ end
116
+ end
117
+
118
+ describe "#uninstall" do
119
+ let(:log) { true }
120
+ let(:plugin_name) { double("plugin_name", :to_s => "test plugin") }
121
+ let(:result) { double("result") }
122
+ subject { manager.uninstall plugin_name, :log => log }
123
+
124
+ before do
125
+ expect(instance).to receive(:execute!).with(:plugin, "uninstall", plugin_name).and_yield("test", nil).and_return(result)
126
+ end
127
+
128
+ it { should be result }
129
+
130
+ context "with logging enabled" do
131
+ include_context "logged messages"
132
+ let(:expected_logs) {[
133
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
134
+ " INFO manager: Uninstalling plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
135
+ " INFO external: test\n",
136
+ ]}
137
+ end
138
+
139
+ context "with logging disabled" do
140
+ let(:log) { false }
141
+ include_context "logged messages"
142
+ let(:expected_logs) {[
143
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
144
+ " INFO manager: Uninstalling plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
145
+ ]}
146
+ end
147
+ end
148
+
149
+ describe "#update" do
150
+ let(:log) { true }
151
+ let(:plugin_name) { double("plugin_name", :to_s => "test plugin") }
152
+ let(:result) { double("result") }
153
+ subject { manager.update plugin_name, :log => log }
154
+
155
+ before do
156
+ expect(instance).to receive(:execute!).with(:plugin, "update", plugin_name).and_yield("test", nil).and_return(result)
157
+ end
158
+
159
+ it { should be result }
160
+
161
+ context "with logging enabled" do
162
+ include_context "logged messages"
163
+ let(:expected_logs) {[
164
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
165
+ " INFO manager: Updating plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
166
+ " INFO external: test\n",
167
+ ]}
168
+ end
169
+
170
+ context "with logging disabled" do
171
+ let(:log) { false }
172
+ include_context "logged messages"
173
+ let(:expected_logs) {[
174
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
175
+ " INFO manager: Updating plugin 'test plugin' using Derelict::Plugin::Manager for test instance\n",
176
+ ]}
177
+ end
178
+ end
179
+
180
+
181
+ describe "#fetch" do
182
+ let(:foo) { double("foo", :name => "foo") }
183
+ let(:bar) { double("bar", :name => "bar") }
184
+ let(:plugins) { [foo, bar] }
185
+
186
+ let(:plugin_name) { double("plugin_name") }
187
+ subject { manager.fetch plugin_name }
188
+ before { expect(manager).to receive(:list).and_return(plugins) }
189
+
190
+ context "with known plugin" do
191
+ let(:plugin_name) { "foo" }
192
+ it { should be foo }
193
+ end
194
+
195
+ context "with unknown plugin" do
196
+ let(:plugin_name) { "qux" }
197
+ it "should raise NotFound" do
198
+ expect { subject }.to raise_error Derelict::Plugin::NotFound
199
+ end
200
+ end
201
+
202
+ include_context "logged messages"
203
+ let(:expected_logs) {[
204
+ "DEBUG manager: Successfully initialized Derelict::Plugin::Manager for test instance\n",
205
+ ]}
206
+ end
207
+
208
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Plugin::NotFound do
4
+ subject { Derelict::Plugin::NotFound.new "test" }
5
+
6
+ it "is autoloaded" do
7
+ should be_a Derelict::Plugin::NotFound
8
+ end
9
+
10
+ its(:message) {
11
+ should eq "Plugin 'test' is not currently installed"
12
+ }
13
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Plugin do
4
+ let(:name) { double("name") }
5
+ let(:version) { double("version") }
6
+ let(:plugin) { Derelict::Plugin.new name, version }
7
+ subject { plugin }
8
+
9
+ it "is autoloaded" do
10
+ should be_a Derelict::Plugin
11
+ end
12
+
13
+ its(:name) { should be name }
14
+ its(:version) { should be version }
15
+
16
+ context "when comparing to an equivalent" do
17
+ let(:other) { plugin.dup }
18
+
19
+ it { should eq other }
20
+ its(:hash) { should eq other.hash }
21
+
22
+ specify "#eql?(other) should be true" do
23
+ expect(subject.eql? other).to be true
24
+ end
25
+ end
26
+
27
+ context "when comparing to a non-equivalent" do
28
+ let(:other) { plugin.class.new "not_foo", "1.0" }
29
+
30
+ it { should_not eq other }
31
+ its(:hash) { should_not eq other.hash }
32
+
33
+ specify "#eql?(other) should be false" do
34
+ expect(subject.eql? other).to be false
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Utils::Logger::ArrayOutputter do
4
+ let(:logger) { Log4r::Logger.new "test::array_outputter_spec" }
5
+ let(:outputter) { Derelict::Utils::Logger::ArrayOutputter.new "test" }
6
+ before { logger.outputters = [outputter] }
7
+ subject { outputter }
8
+
9
+ describe "#level" do
10
+ subject { outputter.level }
11
+ it { should be Log4r::ALL }
12
+ end
13
+
14
+ context "with no data" do
15
+ describe "#messages" do
16
+ subject { outputter.messages }
17
+ it { should eq [] }
18
+ end
19
+
20
+ describe "#flush" do
21
+ subject { outputter.flush }
22
+ it { should eq [] }
23
+ end
24
+ end
25
+
26
+ context "after INFO level log" do
27
+ before { logger.info "test info message" }
28
+ let(:message) { " INFO array_outputter_spec: test info message\n" }
29
+
30
+ describe "#messages" do
31
+ subject { outputter.messages }
32
+ it { should eq [message] }
33
+ end
34
+
35
+ context "then #flush" do
36
+ subject { outputter.flush }
37
+ it { should eq [message] }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Utils::Logger::InvalidType do
4
+ subject { Derelict::Utils::Logger::InvalidType.new "test type" }
5
+
6
+ it "is autoloaded" do
7
+ should be_a Derelict::Utils::Logger::InvalidType
8
+ end
9
+
10
+ its(:message) {
11
+ should eq "Invalid logger type 'test type'"
12
+ }
13
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Utils::Logger::RawFormatter do
4
+ let(:formatter) { Derelict::Utils::Logger::RawFormatter.new }
5
+ subject { formatter }
6
+
7
+ it "is autoloaded" do
8
+ should be_a Derelict::Utils::Logger::RawFormatter
9
+ end
10
+
11
+ describe "#format" do
12
+ let(:data) { double("data") }
13
+ let(:event) { double("event", :data => data) }
14
+ subject { formatter.format event }
15
+ it { should be data }
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::Utils::Logger do
4
+ let(:logger) do
5
+ Module.new do
6
+ extend Derelict::Utils::Logger
7
+ private
8
+ def self.logger_name
9
+ "test"
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "#logger" do
15
+ subject { logger.logger options }
16
+ let(:options) { {:type => type} }
17
+ let(:type) { :nil }
18
+
19
+ context "internal type" do
20
+ let(:type) { :internal }
21
+ it { should be_a Log4r::Logger }
22
+ end
23
+
24
+ context "external type" do
25
+ let(:type) { :external }
26
+ it { should be_a Log4r::Logger }
27
+ end
28
+
29
+ context "invalid type" do
30
+ it "should raise InvalidType" do
31
+ expect { subject }.to raise_error Derelict::Utils::Logger::InvalidType
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::VirtualMachine::Invalid do
4
+ it "is autoloaded" do
5
+ should be_a Derelict::VirtualMachine::Invalid
6
+ end
7
+
8
+ context "when using default reason" do
9
+ its(:message) { should eq "Invalid Derelict virtual machine" }
10
+ end
11
+
12
+ context "when using custom reason" do
13
+ subject { Derelict::VirtualMachine::Invalid.new "reason" }
14
+ its(:message) { should eq "Invalid Derelict virtual machine: reason" }
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe Derelict::VirtualMachine::NotFound do
4
+ let(:connection) { double("connection") }
5
+ let(:name) { "foo" }
6
+ let(:exception) { Derelict::VirtualMachine::NotFound.new name, connection }
7
+ subject { exception }
8
+
9
+ it "is autoloaded" do
10
+ should be_a Derelict::VirtualMachine::NotFound
11
+ end
12
+
13
+ describe "#message" do
14
+ subject { exception.message }
15
+
16
+ context "with invalid connection" do
17
+ let(:expected) {
18
+ "Invalid Derelict virtual machine: Virtual machine foo not found"
19
+ }
20
+ it { should eq expected }
21
+ end
22
+
23
+ context "with invalid connection" do
24
+ let(:connection) { double("connection", :path => "/foo") }
25
+ let(:expected) {
26
+ [
27
+ "Invalid Derelict virtual machine: Virtual machine ",
28
+ "foo not found in /foo",
29
+ ].join
30
+ }
31
+ it { should eq expected }
32
+ end
33
+ end
34
+ end