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.
- checksums.yaml +7 -0
- data/.cane +2 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +18 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +22 -0
- data/derelict.gemspec +63 -0
- data/lib/derelict.rb +74 -0
- data/lib/derelict/box.rb +29 -0
- data/lib/derelict/box/manager.rb +111 -0
- data/lib/derelict/box/not_found.rb +16 -0
- data/lib/derelict/connection.rb +84 -0
- data/lib/derelict/connection/invalid.rb +14 -0
- data/lib/derelict/connection/not_found.rb +13 -0
- data/lib/derelict/exception.rb +6 -0
- data/lib/derelict/exception/optional_reason.rb +32 -0
- data/lib/derelict/executer.rb +237 -0
- data/lib/derelict/instance.rb +147 -0
- data/lib/derelict/instance/command_failed.rb +30 -0
- data/lib/derelict/instance/invalid.rb +14 -0
- data/lib/derelict/instance/missing_binary.rb +13 -0
- data/lib/derelict/instance/non_directory.rb +13 -0
- data/lib/derelict/instance/not_found.rb +13 -0
- data/lib/derelict/parser.rb +27 -0
- data/lib/derelict/parser/box_list.rb +53 -0
- data/lib/derelict/parser/box_list/invalid_format.rb +16 -0
- data/lib/derelict/parser/plugin_list.rb +63 -0
- data/lib/derelict/parser/plugin_list/invalid_format.rb +16 -0
- data/lib/derelict/parser/plugin_list/needs_reinstall.rb +22 -0
- data/lib/derelict/parser/status.rb +90 -0
- data/lib/derelict/parser/status/invalid_format.rb +16 -0
- data/lib/derelict/parser/version.rb +28 -0
- data/lib/derelict/parser/version/invalid_format.rb +16 -0
- data/lib/derelict/plugin.rb +29 -0
- data/lib/derelict/plugin/manager.rb +107 -0
- data/lib/derelict/plugin/not_found.rb +14 -0
- data/lib/derelict/utils.rb +11 -0
- data/lib/derelict/utils/logger.rb +59 -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/version.rb +3 -0
- data/lib/derelict/virtual_machine.rb +190 -0
- data/lib/derelict/virtual_machine/invalid.rb +14 -0
- data/lib/derelict/virtual_machine/not_found.rb +18 -0
- data/spec/coverage_helper.rb +19 -0
- data/spec/derelict/box/manager_spec.rb +171 -0
- data/spec/derelict/box/not_found_spec.rb +13 -0
- data/spec/derelict/box_spec.rb +37 -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/executer_spec.rb +129 -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 +258 -0
- data/spec/derelict/parser/box_list/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/box_list_spec.rb +64 -0
- data/spec/derelict/parser/plugin_list/invalid_format_spec.rb +16 -0
- data/spec/derelict/parser/plugin_list/needs_reinstall_spec.rb +13 -0
- data/spec/derelict/parser/plugin_list_spec.rb +82 -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 +42 -0
- data/spec/derelict/parser_spec.rb +24 -0
- data/spec/derelict/plugin/manager_spec.rb +208 -0
- data/spec/derelict/plugin/not_found_spec.rb +13 -0
- data/spec/derelict/plugin_spec.rb +37 -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 +356 -0
- data/spec/derelict_spec.rb +50 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/log_context.rb +36 -0
- metadata +332 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Executer do
|
4
|
+
let(:executer) { described_class.new }
|
5
|
+
let(:command) { double("command") }
|
6
|
+
let(:options) { Hash.new }
|
7
|
+
let(:block) { Proc.new do end }
|
8
|
+
let(:result) { double("result") }
|
9
|
+
|
10
|
+
describe ".execute" do
|
11
|
+
before do
|
12
|
+
expect(described_class).to receive(:new).with(options).and_return(executer)
|
13
|
+
expect(executer).to receive(:execute).with(command, &block).and_return(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { described_class.execute command, options, &block }
|
17
|
+
it { should be result }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
subject { described_class.new options }
|
22
|
+
it { should be_a described_class }
|
23
|
+
its(:stdout) { should eq "" }
|
24
|
+
its(:stderr) { should eq "" }
|
25
|
+
its(:success?) { should be_nil }
|
26
|
+
its(:status) { should be_nil }
|
27
|
+
|
28
|
+
context "with :chars mode specified" do
|
29
|
+
let(:options) { {:mode => :chars} }
|
30
|
+
it { should be_a described_class }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# The way #execute is tested is much slower than a unit test
|
35
|
+
# (obviously), but I ran into some difficulty implementing a proper
|
36
|
+
# unit test for this method.
|
37
|
+
#
|
38
|
+
# TODO: rewrite as a unit test
|
39
|
+
describe "#execute" do
|
40
|
+
subject { executer.execute command, &block }
|
41
|
+
|
42
|
+
context "without a block" do
|
43
|
+
let(:command) { "echo 'test 1'" }
|
44
|
+
its(:stdout) { should eq "test 1\n" }
|
45
|
+
its(:stderr) { should eq "" }
|
46
|
+
its(:success?) { should be_true }
|
47
|
+
its(:status) { should be 0 }
|
48
|
+
|
49
|
+
context "with non-existent command" do
|
50
|
+
let(:command) { "not_actually_a_command" }
|
51
|
+
it "should raise ENOENT" do
|
52
|
+
expect { subject }.to raise_error(Errno::ENOENT)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with unsuccessful command" do
|
57
|
+
let(:command) { "false" }
|
58
|
+
its(:success?) { should be_false }
|
59
|
+
its(:status) { should be 1 }
|
60
|
+
end
|
61
|
+
|
62
|
+
# Unfortunately this part is even worse. It seems to work though!
|
63
|
+
# The basic idea is for a thread to kill *this* process once the
|
64
|
+
# sub-process has started. It's still relatively fast, and is at
|
65
|
+
# least an accurate way to model the real-world use.
|
66
|
+
context "when main process is receives a signal" do
|
67
|
+
subject {
|
68
|
+
Thread.new do
|
69
|
+
# Wait for the sub-process to start
|
70
|
+
sleep 0.01 while executer.pid.nil?
|
71
|
+
|
72
|
+
# Send SIGINT to this process, it should get forwarded on
|
73
|
+
# to the sub-process
|
74
|
+
Process.kill "INT", Process.pid
|
75
|
+
end
|
76
|
+
|
77
|
+
# Start the sub-process
|
78
|
+
executer.execute "sleep 10"
|
79
|
+
}
|
80
|
+
|
81
|
+
specify "the sub-process should get killed" do
|
82
|
+
expect(subject.success?).to be_false
|
83
|
+
expect(subject.status).to be nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with a block" do
|
89
|
+
context "with one argument" do
|
90
|
+
let(:command) { "echo 'test 2'" }
|
91
|
+
let(:block) do
|
92
|
+
@buffer = ""
|
93
|
+
Proc.new do |stdout|
|
94
|
+
@buffer << stdout
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
its(:stdout) { should eq "test 2\n" }
|
99
|
+
its(:stderr) { should eq "" }
|
100
|
+
its(:success?) { should be_true }
|
101
|
+
its(:status) { should be 0 }
|
102
|
+
specify "the block should get called" do
|
103
|
+
subject; expect(@buffer).to eq executer.stdout
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with two arguments" do
|
108
|
+
let(:command) { "echo 'test 3'; echo 'test 4' 1>&2" }
|
109
|
+
let(:block) do
|
110
|
+
@stdout = ""; @stderr = ""
|
111
|
+
Proc.new do |stdout, stderr|
|
112
|
+
@stdout << stdout unless stdout.nil?
|
113
|
+
@stderr << stderr unless stderr.nil?
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
its(:stdout) { should eq "test 3\n" }
|
118
|
+
its(:stderr) { should eq "test 4\n" }
|
119
|
+
its(:success?) { should be_true }
|
120
|
+
its(:status) { should be 0 }
|
121
|
+
specify "the block should get called" do
|
122
|
+
subject
|
123
|
+
expect(@stdout).to eq executer.stdout
|
124
|
+
expect(@stderr).to eq executer.stderr
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance::CommandFailed do
|
4
|
+
it "is autoloaded" do
|
5
|
+
should be_a Derelict::Instance::CommandFailed
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
let(:command) { nil }
|
10
|
+
let(:result) { nil }
|
11
|
+
subject { Derelict::Instance::CommandFailed.new command, result }
|
12
|
+
|
13
|
+
context "with no arguments" do
|
14
|
+
its(:message) { should eq "Error executing Vagrant command" }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with custom command" do
|
18
|
+
let(:command) { "my_command" }
|
19
|
+
its(:message) { should eq "Error executing Vagrant command 'my_command'" }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with custom result" do
|
23
|
+
let(:result) { double("result", :stderr => "my_stderr") }
|
24
|
+
its(:message) {
|
25
|
+
should eq "Error executing Vagrant command, STDERR output:\nmy_stderr"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with custom command and result" do
|
30
|
+
let(:command) { "my_command" }
|
31
|
+
let(:result) { double("result", :stderr => "my_stderr") }
|
32
|
+
its(:message) {
|
33
|
+
should eq [
|
34
|
+
"Error executing Vagrant command 'my_command', ",
|
35
|
+
"STDERR output:\nmy_stderr"
|
36
|
+
].join
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance::Invalid do
|
4
|
+
it "is autoloaded" do
|
5
|
+
should be_a Derelict::Instance::Invalid
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when using default reason" do
|
9
|
+
its(:message) { should eq "Invalid Derelict instance" }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when using custom reason" do
|
13
|
+
subject { Derelict::Instance::Invalid.new "reason" }
|
14
|
+
its(:message) { should eq "Invalid Derelict instance: reason" }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance::MissingBinary do
|
4
|
+
subject { Derelict::Instance::MissingBinary.new "/foo/bar" }
|
5
|
+
|
6
|
+
it "is autoloaded" do
|
7
|
+
should be_a Derelict::Instance::MissingBinary
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:message) {
|
11
|
+
should eq "Invalid Derelict instance: 'vagrant' binary not found at /foo/bar"
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance::NonDirectory do
|
4
|
+
subject { Derelict::Instance::NonDirectory.new "/foo/bar" }
|
5
|
+
|
6
|
+
it "is autoloaded" do
|
7
|
+
should be_a Derelict::Instance::NonDirectory
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:message) {
|
11
|
+
should eq "Invalid Derelict instance: expected directory, found file: /foo/bar"
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance::NotFound do
|
4
|
+
subject { Derelict::Instance::NotFound.new "/foo/bar" }
|
5
|
+
|
6
|
+
it "is autoloaded" do
|
7
|
+
should be_a Derelict::Instance::NotFound
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:message) {
|
11
|
+
should eq "Invalid Derelict instance: directory doesn't exist: /foo/bar"
|
12
|
+
}
|
13
|
+
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Derelict::Instance do
|
4
|
+
let(:instance) { Derelict::Instance.new path }
|
5
|
+
let(:path) { nil }
|
6
|
+
|
7
|
+
subject { instance }
|
8
|
+
|
9
|
+
it "is autoloaded" do
|
10
|
+
should be_a Derelict::Instance
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#version" do
|
14
|
+
let(:result) { double("result", :stdout => stdout) }
|
15
|
+
let(:stdout) { double("stdout") }
|
16
|
+
let(:parser) { double("parser", :version => "the version") }
|
17
|
+
subject { instance.version }
|
18
|
+
before {
|
19
|
+
expect(instance).to receive(:execute!).with("--version").and_return(result)
|
20
|
+
expect(Derelict::Parser::Version).to receive(:new).with(stdout).and_return(parser)
|
21
|
+
}
|
22
|
+
|
23
|
+
it "should execute --version and parse the result" do
|
24
|
+
expect(subject).to eq "the version"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#plugins" do
|
29
|
+
subject { instance.plugins }
|
30
|
+
it { should be_a Derelict::Plugin::Manager }
|
31
|
+
its(:instance) { should be instance }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#boxes" do
|
35
|
+
subject { instance.boxes }
|
36
|
+
it { should be_a Derelict::Box::Manager }
|
37
|
+
its(:instance) { should be instance }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with path parameter" do
|
41
|
+
let(:path) { "/foo/bar" }
|
42
|
+
|
43
|
+
describe "#initialize" do
|
44
|
+
its(:path) { should eq "/foo/bar" }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#validate!" do
|
48
|
+
subject { instance.validate! }
|
49
|
+
|
50
|
+
context "with valid path" do
|
51
|
+
before {
|
52
|
+
expect(File).to receive(:exists?).with("/foo/bar").and_return(true)
|
53
|
+
expect(File).to receive(:directory?).with("/foo/bar").and_return(true)
|
54
|
+
expect(File).to receive(:exists?).with("/foo/bar/bin/vagrant").and_return(true)
|
55
|
+
expect(File).to receive(:executable?).with("/foo/bar/bin/vagrant").and_return(true)
|
56
|
+
}
|
57
|
+
|
58
|
+
it "shouldn't raise any exceptions" do
|
59
|
+
expect { subject }.to_not raise_error
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should be chainable" do
|
63
|
+
expect(subject).to be_a Derelict::Instance
|
64
|
+
end
|
65
|
+
|
66
|
+
include_context "logged messages"
|
67
|
+
let(:expected_logs) {[
|
68
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
69
|
+
"DEBUG instance: Starting validation for Derelict::Instance at '/foo/bar'\n",
|
70
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
71
|
+
" INFO instance: Successfully validated Derelict::Instance at '/foo/bar'\n",
|
72
|
+
]}
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with non-existent path" do
|
76
|
+
before {
|
77
|
+
expect(File).to receive(:exists?).with("/foo/bar").and_return(false)
|
78
|
+
}
|
79
|
+
|
80
|
+
it "should raise NotFound" do
|
81
|
+
expect { subject }.to raise_error Derelict::Instance::NotFound
|
82
|
+
end
|
83
|
+
|
84
|
+
include_context "logged messages"
|
85
|
+
let(:expected_logs) {[
|
86
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
87
|
+
"DEBUG instance: Starting validation for Derelict::Instance at '/foo/bar'\n",
|
88
|
+
]}
|
89
|
+
end
|
90
|
+
|
91
|
+
context "with path pointing to a file" do
|
92
|
+
before {
|
93
|
+
expect(File).to receive(:exists?).with("/foo/bar").and_return(true)
|
94
|
+
expect(File).to receive(:directory?).with("/foo/bar").and_return(false)
|
95
|
+
}
|
96
|
+
|
97
|
+
it "should raise NonDirectory" do
|
98
|
+
expect { subject }.to raise_error Derelict::Instance::NonDirectory
|
99
|
+
end
|
100
|
+
|
101
|
+
include_context "logged messages"
|
102
|
+
let(:expected_logs) {[
|
103
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
104
|
+
"DEBUG instance: Starting validation for Derelict::Instance at '/foo/bar'\n",
|
105
|
+
]}
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with vagrant binary missing" do
|
109
|
+
before {
|
110
|
+
expect(File).to receive(:exists?).with("/foo/bar").and_return(true)
|
111
|
+
expect(File).to receive(:directory?).with("/foo/bar").and_return(true)
|
112
|
+
expect(File).to receive(:exists?).with("/foo/bar/bin/vagrant").and_return(false)
|
113
|
+
}
|
114
|
+
|
115
|
+
it "should raise MissingBinary" do
|
116
|
+
expect { subject }.to raise_error Derelict::Instance::MissingBinary
|
117
|
+
end
|
118
|
+
|
119
|
+
include_context "logged messages"
|
120
|
+
let(:expected_logs) {[
|
121
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
122
|
+
"DEBUG instance: Starting validation for Derelict::Instance at '/foo/bar'\n",
|
123
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
124
|
+
]}
|
125
|
+
end
|
126
|
+
|
127
|
+
context "with vagrant binary non-executable" do
|
128
|
+
before {
|
129
|
+
expect(File).to receive(:exists?).with("/foo/bar").and_return(true)
|
130
|
+
expect(File).to receive(:directory?).with("/foo/bar").and_return(true)
|
131
|
+
expect(File).to receive(:exists?).with("/foo/bar/bin/vagrant").and_return(true)
|
132
|
+
expect(File).to receive(:executable?).with("/foo/bar/bin/vagrant").and_return(false)
|
133
|
+
}
|
134
|
+
|
135
|
+
it "should raise MissingBinary" do
|
136
|
+
expect { subject }.to raise_error Derelict::Instance::MissingBinary
|
137
|
+
end
|
138
|
+
|
139
|
+
include_context "logged messages"
|
140
|
+
let(:expected_logs) {[
|
141
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
142
|
+
"DEBUG instance: Starting validation for Derelict::Instance at '/foo/bar'\n",
|
143
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
144
|
+
]}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#connect" do
|
149
|
+
let(:connection) { double("connection") }
|
150
|
+
let(:connection_path) { double("connection_path", :inspect => "connection_path") }
|
151
|
+
subject { instance.connect connection_path }
|
152
|
+
before do
|
153
|
+
con = Derelict::Connection
|
154
|
+
args = [instance, connection_path]
|
155
|
+
expect(con).to receive(:new).with(*args).and_return(connection)
|
156
|
+
expect(connection).to receive(:validate!).and_return(connection)
|
157
|
+
end
|
158
|
+
|
159
|
+
it { should be connection }
|
160
|
+
|
161
|
+
include_context "logged messages"
|
162
|
+
let(:expected_logs) {[
|
163
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
164
|
+
" INFO instance: Creating connection for 'connection_path' by Derelict::Instance at '/foo/bar'\n",
|
165
|
+
]}
|
166
|
+
end
|
167
|
+
|
168
|
+
context "with mock Executer" do
|
169
|
+
let(:expected_command) { "/foo/bar/bin/vagrant test arg\\ 1" }
|
170
|
+
before do
|
171
|
+
expect(Derelict::Executer).to receive(:execute).with(expected_command, options).and_return(result)
|
172
|
+
end
|
173
|
+
|
174
|
+
let(:options) { Hash.new }
|
175
|
+
|
176
|
+
let(:result) do
|
177
|
+
double("result", {
|
178
|
+
:stdout => "stdout\n",
|
179
|
+
:stderr => "stderr\n",
|
180
|
+
:success? => success,
|
181
|
+
})
|
182
|
+
end
|
183
|
+
|
184
|
+
let(:success) { double("success") }
|
185
|
+
|
186
|
+
describe "#execute" do
|
187
|
+
subject { instance.execute :test, "arg 1" }
|
188
|
+
its(:stdout) { should eq "stdout\n" }
|
189
|
+
its(:stderr) { should eq "stderr\n" }
|
190
|
+
its(:success?) { should be success }
|
191
|
+
|
192
|
+
include_context "logged messages"
|
193
|
+
let(:expected_logs) {[
|
194
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
195
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
196
|
+
"DEBUG instance: Generated command '/foo/bar/bin/vagrant test arg\\ 1' from subcommand 'test' with arguments [\"arg 1\"]\n",
|
197
|
+
"DEBUG instance: Executing /foo/bar/bin/vagrant test arg\\ 1 using Derelict::Instance at '/foo/bar'\n",
|
198
|
+
]}
|
199
|
+
|
200
|
+
context "with options hash" do
|
201
|
+
let(:options) { {:foo => :bar} }
|
202
|
+
subject { instance.execute :test, "arg 1", options }
|
203
|
+
its(:stdout) { should eq "stdout\n" }
|
204
|
+
its(:stderr) { should eq "stderr\n" }
|
205
|
+
its(:success?) { should be success }
|
206
|
+
end
|
207
|
+
|
208
|
+
context "with :sudo option enabled" do
|
209
|
+
let(:options_argument) { {:sudo => true} }
|
210
|
+
let(:options) { Hash.new } # Don't pass sudo opt to Executer.execute
|
211
|
+
let(:expected_command) { "sudo -- /foo/bar/bin/vagrant test arg\\ 1" }
|
212
|
+
subject { instance.execute :test, "arg 1", options_argument }
|
213
|
+
its(:stdout) { should eq "stdout\n" }
|
214
|
+
its(:stderr) { should eq "stderr\n" }
|
215
|
+
its(:success?) { should be success }
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#execute!" do
|
220
|
+
subject { instance.execute! :test, "arg 1" }
|
221
|
+
|
222
|
+
context "on success" do
|
223
|
+
let(:success) { true }
|
224
|
+
|
225
|
+
its(:stdout) { should eq "stdout\n" }
|
226
|
+
its(:stderr) { should eq "stderr\n" }
|
227
|
+
its(:success?) { should be true }
|
228
|
+
|
229
|
+
include_context "logged messages"
|
230
|
+
let(:expected_logs) {[
|
231
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
232
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
233
|
+
"DEBUG instance: Generated command '/foo/bar/bin/vagrant test arg\\ 1' from subcommand 'test' with arguments [\"arg 1\"]\n",
|
234
|
+
"DEBUG instance: Executing /foo/bar/bin/vagrant test arg\\ 1 using Derelict::Instance at '/foo/bar'\n",
|
235
|
+
]}
|
236
|
+
end
|
237
|
+
|
238
|
+
context "on failure" do
|
239
|
+
let(:success) { false }
|
240
|
+
|
241
|
+
it "should raise CommandFailed" do
|
242
|
+
expect { subject }.to raise_error Derelict::Instance::CommandFailed
|
243
|
+
end
|
244
|
+
|
245
|
+
include_context "logged messages"
|
246
|
+
let(:expected_logs) {[
|
247
|
+
"DEBUG instance: Successfully initialized Derelict::Instance at '/foo/bar'\n",
|
248
|
+
"DEBUG instance: Vagrant binary for Derelict::Instance at '/foo/bar' is '/foo/bar/bin/vagrant'\n",
|
249
|
+
"DEBUG instance: Generated command '/foo/bar/bin/vagrant test arg\\ 1' from subcommand 'test' with arguments [\"arg 1\"]\n",
|
250
|
+
"DEBUG instance: Executing /foo/bar/bin/vagrant test arg\\ 1 using Derelict::Instance at '/foo/bar'\n",
|
251
|
+
"DEBUG instance: Generated command '/foo/bar/bin/vagrant test arg\\ 1' from subcommand 'test' with arguments [\"arg 1\"]\n",
|
252
|
+
" WARN instance: Command /foo/bar/bin/vagrant test arg\\ 1 failed: Error executing Vagrant command '/foo/bar/bin/vagrant test arg\\ 1', STDERR output:\nstderr\n\n",
|
253
|
+
]}
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|