derelict 0.0.1 → 0.1.0
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.
- checksums.yaml +5 -13
- data/.cane +2 -0
- data/.coveralls.yml +1 -0
- data/.travis.yml +13 -0
- data/README.md +55 -9
- data/Rakefile +21 -0
- data/derelict.gemspec +25 -1
- data/lib/derelict/connection/invalid.rb +14 -0
- data/lib/derelict/connection/not_found.rb +13 -0
- data/lib/derelict/connection.rb +84 -0
- data/lib/derelict/exception/optional_reason.rb +32 -0
- data/lib/derelict/exception.rb +3 -2
- data/lib/derelict/instance/command_failed.rb +28 -0
- data/lib/derelict/instance/invalid.rb +11 -11
- data/lib/derelict/instance/missing_binary.rb +13 -0
- data/lib/derelict/instance/non_directory.rb +10 -8
- data/lib/derelict/instance/not_found.rb +10 -8
- data/lib/derelict/instance.rb +105 -33
- data/lib/derelict/parser/status/invalid_format.rb +16 -0
- data/lib/derelict/parser/status.rb +89 -0
- data/lib/derelict/parser/version/invalid_format.rb +16 -0
- data/lib/derelict/parser/version.rb +28 -0
- data/lib/derelict/parser.rb +25 -0
- data/lib/derelict/utils/logger/array_outputter.rb +43 -0
- data/lib/derelict/utils/logger/invalid_type.rb +15 -0
- data/lib/derelict/utils/logger/raw_formatter.rb +12 -0
- data/lib/derelict/utils/logger.rb +51 -0
- data/lib/derelict/utils.rb +11 -0
- data/lib/derelict/version.rb +2 -2
- data/lib/derelict/virtual_machine/invalid.rb +14 -0
- data/lib/derelict/virtual_machine/not_found.rb +18 -0
- data/lib/derelict/virtual_machine.rb +154 -0
- data/lib/derelict.rb +61 -14
- data/spec/coverage_helper.rb +16 -0
- data/spec/derelict/connection/invalid_spec.rb +16 -0
- data/spec/derelict/connection/not_found_spec.rb +13 -0
- data/spec/derelict/connection_spec.rb +107 -0
- data/spec/derelict/exception/optional_reason_spec.rb +41 -0
- data/spec/derelict/exception_spec.rb +11 -0
- data/spec/derelict/instance/command_failed_spec.rb +40 -0
- data/spec/derelict/instance/invalid_spec.rb +16 -0
- data/spec/derelict/instance/missing_binary_spec.rb +13 -0
- data/spec/derelict/instance/non_directory_spec.rb +13 -0
- data/spec/derelict/instance/not_found_spec.rb +13 -0
- data/spec/derelict/instance_spec.rb +226 -0
- data/spec/derelict/parser/status/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/status_spec.rb +214 -0
- data/spec/derelict/parser/version/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/version_spec.rb +31 -0
- data/spec/derelict/parser_spec.rb +24 -0
- data/spec/derelict/utils/logger/array_outputter_spec.rb +40 -0
- data/spec/derelict/utils/logger/invalid_type_spec.rb +13 -0
- data/spec/derelict/utils/logger/raw_formatter_spec.rb +17 -0
- data/spec/derelict/utils/logger_spec.rb +35 -0
- data/spec/derelict/virtual_machine/invalid_spec.rb +16 -0
- data/spec/derelict/virtual_machine/not_found_spec.rb +34 -0
- data/spec/derelict/virtual_machine_spec.rb +295 -0
- data/spec/derelict_spec.rb +50 -0
- data/spec/spec_helper.rb +28 -3
- data/spec/support/log_context.rb +36 -0
- metadata +175 -22
- data/lib/derelict/instance/already_active.rb +0 -9
- data/spec/system_spec.spec +0 -10
@@ -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,31 @@
|
|
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 "on Vagrant 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 "on Vagrant 1.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
|
+
end
|
31
|
+
end
|
@@ -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,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
|