rhc 0.92.11 → 0.93.18
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.
- data/README.md +1 -9
- data/Rakefile +1 -55
- data/bin/rhc +31 -1
- data/bin/rhc-app +62 -127
- data/bin/rhc-chk +6 -7
- data/bin/rhc-create-app +8 -8
- data/bin/rhc-create-domain +6 -86
- data/bin/rhc-ctl-app +3 -3
- data/bin/rhc-ctl-domain +4 -4
- data/bin/rhc-domain +16 -18
- data/bin/rhc-domain-info +3 -3
- data/bin/rhc-port-forward +127 -24
- data/bin/rhc-snapshot +7 -46
- data/bin/rhc-sshkey +13 -79
- data/bin/rhc-tail-files +16 -8
- data/lib/rhc-common.rb +406 -230
- data/lib/rhc-rest.rb +3 -3
- data/lib/rhc-rest/client.rb +1 -1
- data/lib/rhc-rest/domain.rb +1 -1
- data/lib/rhc.rb +20 -0
- data/lib/rhc/cli.rb +38 -0
- data/lib/rhc/client.rb +15 -0
- data/lib/rhc/commands.rb +32 -0
- data/lib/rhc/commands/base.rb +67 -0
- data/lib/rhc/commands/server.rb +24 -0
- data/lib/rhc/config.rb +141 -0
- data/lib/rhc/core_ext.rb +15 -0
- data/lib/rhc/helpers.rb +142 -0
- data/lib/rhc/json.rb +52 -0
- data/lib/rhc/targz.rb +46 -0
- data/lib/rhc/vendor/okjson.rb +600 -0
- data/lib/rhc/vendor/zliby.rb +628 -0
- data/lib/rhc/wizard.rb +579 -0
- data/spec/rhc/assets/foo.txt +1 -0
- data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
- data/spec/rhc/assets/targz_sample.tar.gz +0 -0
- data/spec/rhc/cli_spec.rb +24 -0
- data/spec/rhc/command_spec.rb +88 -0
- data/spec/rhc/commands/server_spec.rb +39 -0
- data/spec/rhc/helpers_spec.rb +171 -0
- data/spec/rhc/json_spec.rb +30 -0
- data/spec/rhc/targz_spec.rb +42 -0
- data/spec/rhc/wizard_spec.rb +426 -0
- data/spec/spec_helper.rb +192 -0
- data/test/functional/application_test.rb +71 -0
- data/test/functional/domain_test.rb +123 -0
- data/test/functional/test_credentials.rb +5 -0
- data/test/sample-usage.rb +122 -0
- data/test/support/server.rb +14 -0
- data/test/support/testcase.rb +3 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/command_test.rb +19 -0
- metadata +181 -29
- data/ext/mkrf_conf.rb +0 -58
- data/lib/rhc +0 -115
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
@@ -0,0 +1 @@
|
|
1
|
+
foo
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RHC::CLI do
|
4
|
+
|
5
|
+
describe '#start' do
|
6
|
+
context 'with no arguments' do
|
7
|
+
let(:arguments) { [] }
|
8
|
+
it { expect { run }.should exit_with_code(1) }
|
9
|
+
it('should provide a message about --help') { run_output.should =~ /\-\-help/ }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with --help' do
|
13
|
+
let(:arguments) { ['--help'] }
|
14
|
+
it { expect { run }.should exit_with_code(0) }
|
15
|
+
it('should contain the program description') { run_output.should =~ /Command line interface for OpenShift/ }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#set_terminal' do
|
20
|
+
before(:each) { mock_terminal }
|
21
|
+
it('should update $terminal.wrap_at') { expect { RHC::CLI.set_terminal }.to change($terminal, :wrap_at) }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/commands/base'
|
3
|
+
|
4
|
+
describe RHC::Commands::Base do
|
5
|
+
|
6
|
+
describe '#object_name' do
|
7
|
+
subject { described_class }
|
8
|
+
its(:object_name) { should == 'base' }
|
9
|
+
|
10
|
+
context 'when the class is at the root' do
|
11
|
+
subject do
|
12
|
+
Kernel.module_eval do
|
13
|
+
class StaticRootClass < RHC::Commands::Base; def run; 1; end; end
|
14
|
+
end
|
15
|
+
StaticRootClass
|
16
|
+
end
|
17
|
+
its(:object_name) { should == 'staticrootclass' }
|
18
|
+
end
|
19
|
+
context 'when the class is nested in a module' do
|
20
|
+
subject do
|
21
|
+
Kernel.module_eval do
|
22
|
+
module Nested; class StaticRootClass < RHC::Commands::Base; def run; 1; end; end; end
|
23
|
+
end
|
24
|
+
Nested::StaticRootClass
|
25
|
+
end
|
26
|
+
its(:object_name) { should == 'staticrootclass' }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#inherited' do
|
31
|
+
|
32
|
+
let(:instance) { subject.new }
|
33
|
+
let(:commands) { RHC::Commands.send(:commands) }
|
34
|
+
|
35
|
+
context 'when dynamically instantiating without an object name' do
|
36
|
+
subject { const_for(Class.new(RHC::Commands::Base) { def run; 1; end }) }
|
37
|
+
|
38
|
+
it("should raise") { expect { subject }.to raise_exception( RHC::Commands::Base::InvalidCommand, /object_name/i ) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when dynamically instantiating with object_name' do
|
42
|
+
subject { const_for(Class.new(RHC::Commands::Base) { object_name :test; def run(args, options); 1; end }) }
|
43
|
+
|
44
|
+
it("should register itself") { expect { subject }.to change(commands, :length).by(1) }
|
45
|
+
it("should have an object name") { subject.object_name.should == 'test' }
|
46
|
+
it { expects_running('test').should call(:run).on(instance).with(no_args) }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when statically defined' do
|
50
|
+
subject do
|
51
|
+
Kernel.module_eval do
|
52
|
+
module Nested
|
53
|
+
class Static < RHC::Commands::Base
|
54
|
+
def run(args, options); 1; end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
Nested::Static
|
59
|
+
end
|
60
|
+
|
61
|
+
it("should register itself") { expect { subject }.to change(commands, :length).by(1) }
|
62
|
+
it("should have an object name of the class") { subject.object_name.should == 'static' }
|
63
|
+
it("invokes the right method") { expects_running('static').should call(:run).on(instance).with(no_args) }
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when statically defined with no default method' do
|
67
|
+
subject do
|
68
|
+
Kernel.module_eval do
|
69
|
+
class Static < RHC::Commands::Base
|
70
|
+
def test; 1; end
|
71
|
+
def execute; 1; end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
Static
|
75
|
+
end
|
76
|
+
|
77
|
+
it("should register itself") { expect { subject }.to change(commands, :length).by(2) }
|
78
|
+
it("should have an object name of the class") { subject.object_name.should == 'static' }
|
79
|
+
|
80
|
+
context 'and when test is called' do
|
81
|
+
it { expects_running('static', 'test').should call(:test).on(instance).with(no_args) }
|
82
|
+
end
|
83
|
+
context 'and when test is called' do
|
84
|
+
it { expects_running('static', 'execute').should call(:execute).on(instance).with(no_args) }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/commands/server'
|
3
|
+
require 'rhc/config'
|
4
|
+
|
5
|
+
describe RHC::Commands::Server do
|
6
|
+
before(:each) do
|
7
|
+
RHC::Config.initialize
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'run' do
|
11
|
+
let(:arguments) { ['server'] }
|
12
|
+
|
13
|
+
context 'when no issues' do
|
14
|
+
before { stub_request(:get, 'https://openshift.redhat.com/app/status/status.json').to_return(:body => {'issues' => []}.to_json) }
|
15
|
+
it { expect { run }.should exit_with_code(0) }
|
16
|
+
it('should output success') { run_output.should =~ /All systems running fine/ }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when 1 issue' do
|
20
|
+
before do
|
21
|
+
stub_request(:get, 'https://openshift.redhat.com/app/status/status.json').to_return(:body =>
|
22
|
+
{'open' => [
|
23
|
+
{'issue' => {
|
24
|
+
'created_at' => '2011-05-22T17:31:32-04:00',
|
25
|
+
'id' => 11,
|
26
|
+
'title' => 'Root cause',
|
27
|
+
'updates' => [{
|
28
|
+
'created_at' => '2012-05-22T13:48:20-04:00',
|
29
|
+
'description' => 'Working on update'
|
30
|
+
}]
|
31
|
+
}}]}.to_json)
|
32
|
+
end
|
33
|
+
it { expect { run }.should exit_with_code(1) }
|
34
|
+
it('should output message') { run_output.should =~ /1 open issue/ }
|
35
|
+
it('should output title') { run_output.should =~ /Root cause/ }
|
36
|
+
it('should contain update') { run_output.should =~ /Working on update/ }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/helpers'
|
3
|
+
require 'rhc/core_ext'
|
4
|
+
require 'highline/import'
|
5
|
+
require 'rhc/config'
|
6
|
+
|
7
|
+
describe RHC::Helpers do
|
8
|
+
before(:each) do
|
9
|
+
mock_terminal
|
10
|
+
RHC::Config.initialize
|
11
|
+
@tests = HelperTests.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
Class.new(Object) do
|
16
|
+
include RHC::Helpers
|
17
|
+
end.new
|
18
|
+
end
|
19
|
+
|
20
|
+
its(:openshift_server) { should == 'openshift.redhat.com' }
|
21
|
+
|
22
|
+
context 'with LIBRA_SERVER environment variable' do
|
23
|
+
before do
|
24
|
+
ENV['LIBRA_SERVER'] = 'test.com'
|
25
|
+
# need to reinit config to pick up env var
|
26
|
+
RHC::Config.initialize
|
27
|
+
end
|
28
|
+
its(:openshift_server) { should == 'test.com' }
|
29
|
+
after { ENV['LIBRA_SERVER'] = nil }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "Formatter" do
|
33
|
+
it "should print out a section without any line breaks" do
|
34
|
+
@tests.section_no_breaks
|
35
|
+
$terminal.read.should == "section 1 "
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should print out a section with trailing line break" do
|
39
|
+
@tests.section_one_break
|
40
|
+
$terminal.read.should == "section 1\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should print out 2 sections with matching bottom and top margins generating one space between" do
|
44
|
+
@tests.sections_equal_bottom_top
|
45
|
+
$terminal.read.should == "section 1\n\nsection 2\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should print out 2 sections with larger bottom margin generating two spaces between" do
|
49
|
+
@tests.sections_larger_bottom
|
50
|
+
$terminal.read.should == "section 1\n\n\nsection 2\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should print out 2 sections with larger top margin generating two spaces between" do
|
54
|
+
@tests.sections_larger_top
|
55
|
+
$terminal.read.should == "section 1\n\n\nsection 2\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should print out 4 sections with the middle two on the same line and a space between the lines" do
|
59
|
+
@tests.sections_four_on_three_lines
|
60
|
+
$terminal.read.should == "section 1\n\nsection 2 section 3\n\nsection 4\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should show the equivilance of paragaph to section(:top => 1, :bottom => 1)" do
|
64
|
+
@tests.section_1_1
|
65
|
+
section_1_1 = $terminal.read
|
66
|
+
@tests.reset
|
67
|
+
@tests.section_paragraph
|
68
|
+
paragraph = $terminal.read
|
69
|
+
|
70
|
+
section_1_1.should == paragraph
|
71
|
+
|
72
|
+
@tests.reset
|
73
|
+
@tests.section_1_1
|
74
|
+
@tests.section_paragraph
|
75
|
+
|
76
|
+
$terminal.read.should == "\nsection\n\nsection\n\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should show two line with one space between even though an outside newline was printed" do
|
80
|
+
@tests.outside_newline
|
81
|
+
$terminal.read.should == "section 1\n\nsection 2\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class HelperTests
|
86
|
+
include RHC::Helpers
|
87
|
+
|
88
|
+
def initialize
|
89
|
+
@print_num = 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def next_print_num
|
93
|
+
@print_num += 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def output
|
97
|
+
say "section #{next_print_num}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def output_no_breaks
|
101
|
+
say "section #{next_print_num} "
|
102
|
+
end
|
103
|
+
|
104
|
+
def section_no_breaks
|
105
|
+
section { output_no_breaks }
|
106
|
+
end
|
107
|
+
|
108
|
+
def section_one_break
|
109
|
+
section { output }
|
110
|
+
end
|
111
|
+
|
112
|
+
def sections_equal_bottom_top
|
113
|
+
section(:bottom => 1) { output }
|
114
|
+
section(:top => 1) { output }
|
115
|
+
end
|
116
|
+
|
117
|
+
def sections_larger_bottom
|
118
|
+
section(:bottom => 2) { output }
|
119
|
+
section(:top => 1) { output }
|
120
|
+
end
|
121
|
+
|
122
|
+
def sections_larger_top
|
123
|
+
section(:bottom => 1) { output }
|
124
|
+
section(:top => 2) { output }
|
125
|
+
end
|
126
|
+
|
127
|
+
def sections_four_on_three_lines
|
128
|
+
section { output }
|
129
|
+
section(:top => 1) { output_no_breaks }
|
130
|
+
section(:bottom => 1) { output }
|
131
|
+
section(:top => 1) { output }
|
132
|
+
end
|
133
|
+
|
134
|
+
def outside_newline
|
135
|
+
section(:bottom => -1) { output }
|
136
|
+
say "\n"
|
137
|
+
section(:top => 1) { output }
|
138
|
+
end
|
139
|
+
|
140
|
+
def section_1_1
|
141
|
+
section(:top => 1, :bottom => 1) { say "section" }
|
142
|
+
end
|
143
|
+
|
144
|
+
def section_paragraph
|
145
|
+
paragraph { say "section" }
|
146
|
+
end
|
147
|
+
|
148
|
+
# call section without output to reset spacing to 0
|
149
|
+
def reset
|
150
|
+
section {}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe Object do
|
156
|
+
context 'present?' do
|
157
|
+
specify('nil') { nil.present?.should be_false }
|
158
|
+
specify('empty array') { [].present?.should be_false }
|
159
|
+
specify('array') { [1].present?.should be_true }
|
160
|
+
specify('string') { 'a'.present?.should be_true }
|
161
|
+
specify('empty string') { ''.present?.should be_false }
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'blank?' do
|
165
|
+
specify('nil') { nil.blank?.should be_true }
|
166
|
+
specify('empty array') { [].blank?.should be_true }
|
167
|
+
specify('array') { [1].blank?.should be_false }
|
168
|
+
specify('string') { 'a'.blank?.should be_false }
|
169
|
+
specify('empty string') { ''.blank?.should be_true }
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/json'
|
3
|
+
|
4
|
+
describe RHC::Json do
|
5
|
+
|
6
|
+
context 'with simple decoded hash as a string' do
|
7
|
+
subject { RHC::Json.decode '{"abc":[123,-456.789e0],"def":[456,-456.789e0],"ghi":"ghj"}' }
|
8
|
+
its(:length) { should == 3 }
|
9
|
+
it('should contain key') { subject.has_key?("abc").should be_true }
|
10
|
+
it('should contain key') { subject.has_key?("def").should be_true }
|
11
|
+
it('should contain key') { subject.has_key?("ghi").should be_true }
|
12
|
+
it('should not contain invalid key') { subject.has_key?("ghj").should be_false }
|
13
|
+
it('should contain value for key') { subject.has_value?("ghj").should be_true }
|
14
|
+
it('should contain array value') { subject["abc"].is_a?(Array).should be_true }
|
15
|
+
it('should contain array with two elements') { subject["abc"].length.should == 2 }
|
16
|
+
it('should contain array with an integer') { subject["abc"][0].should == 123 }
|
17
|
+
it('should contain array with a float') { subject["abc"][1].should == -456.789e0 }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with simple hash' do
|
21
|
+
subject { RHC::Json.encode({"key" => "value"}) }
|
22
|
+
it('should encode to proper json') { subject.should == '{"key":"value"}' }
|
23
|
+
it('should encode and decode to the same hash') { RHC::Json.decode(subject).should == {"key" => "value"} }
|
24
|
+
it('should decode and encode to the same string') { RHC::Json.encode(RHC::Json.decode('{"x":"y"}')).should == '{"x":"y"}' }
|
25
|
+
it('should decode symbol keys') { RHC::Json.decode('{"key":"ok"}', {:symbolize_keys => true}).has_key?(:key).should be_true }
|
26
|
+
it('should decode symbol keys') { RHC::Json.decode('{"key":"ok"}', {:symbolize_keys => true})[:key].should == "ok" }
|
27
|
+
it('should encode symbol keys') { RHC::Json.encode({:key => "ok"}).should == '{"key":"ok"}' }
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rhc/targz'
|
3
|
+
|
4
|
+
describe RHC::TarGz do
|
5
|
+
|
6
|
+
context 'with simple compressed .tar.gz' do
|
7
|
+
subject { File.expand_path('../assets/targz_sample.tar.gz', __FILE__) }
|
8
|
+
it('should wrap the right filename') { File.basename(subject).should == 'targz_sample.tar.gz' }
|
9
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'foo').should be_true }
|
10
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'bar').should be_false }
|
11
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'test').should be_false }
|
12
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'foo').should be_true }
|
13
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'bar').should be_false }
|
14
|
+
it('should contain the right files') { RHC::TarGz.contains(subject, 'test').should be_false }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with file extension different than .tar.gz' do
|
18
|
+
subject { File.expand_path('../assets/foo.txt', __FILE__) }
|
19
|
+
it('should never return contains') { RHC::TarGz.contains(subject, 'foo').should be_false }
|
20
|
+
it('should never return contains') { RHC::TarGz.contains(subject, 'foo', true).should be_false }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with corrupted .tar.gz' do
|
24
|
+
subject { File.expand_path('../assets/targz_corrupted.tar.gz', __FILE__) }
|
25
|
+
it('should never return contains') { RHC::TarGz.contains(subject, 'foo').should be_false }
|
26
|
+
it('should never return contains') { RHC::TarGz.contains(subject, 'foo', true).should be_false }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with multiple threads' do
|
30
|
+
subject { File.expand_path('../assets/targz_sample.tar.gz', __FILE__) }
|
31
|
+
it('should be able to handle the same file') {
|
32
|
+
threads = []
|
33
|
+
30.times {
|
34
|
+
threads << Thread.new { Thread.current['result'] = RHC::TarGz.contains(subject, 'foo') }
|
35
|
+
threads << Thread.new { Thread.current['result'] = RHC::TarGz.contains(subject, 'foo', true) }
|
36
|
+
}
|
37
|
+
threads.each { |thread| thread.join }
|
38
|
+
threads.each { |thread| thread['result'].should be_true }
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,426 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fakefs/safe'
|
3
|
+
require 'rhc/wizard'
|
4
|
+
require 'parseconfig'
|
5
|
+
require 'rhc/config'
|
6
|
+
|
7
|
+
# monkey patch ParseConfig so it works with fakefs
|
8
|
+
# TODO: if this is useful elsewhere move to helpers
|
9
|
+
class ParseConfig
|
10
|
+
def open(*args)
|
11
|
+
File.open *args
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# chmod isn't implemented in the released fakefs gem
|
16
|
+
# but is in git. Once the git version is released we
|
17
|
+
# should remove this and actively check permissions
|
18
|
+
class FakeFS::File
|
19
|
+
def self.chmod(*args)
|
20
|
+
# noop
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe RHC::Wizard do
|
25
|
+
before(:all) do
|
26
|
+
mock_terminal
|
27
|
+
FakeFS.activate!
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:all) do
|
31
|
+
FakeFS.deactivate!
|
32
|
+
end
|
33
|
+
|
34
|
+
context "First run of rhc" do
|
35
|
+
before(:all) do
|
36
|
+
@wizard = FirstRunWizardDriver.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should print out first run greeting" do
|
40
|
+
@wizard.run_next_stage
|
41
|
+
greeting = $terminal.read
|
42
|
+
greeting.count("\n").should == 8
|
43
|
+
greeting.should match(Regexp.escape("It looks like you have not configured or used OpenShift client tools on this computer."))
|
44
|
+
greeting.should match(Regexp.escape("\n#{@wizard.config_path}\n"))
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should ask for login and hide password input" do
|
48
|
+
# queue up input
|
49
|
+
$terminal.write_line "#{@wizard.mock_user}"
|
50
|
+
$terminal.write_line "password"
|
51
|
+
|
52
|
+
@wizard.stub_user_info
|
53
|
+
@wizard.stub_rest_api
|
54
|
+
|
55
|
+
@wizard.run_next_stage
|
56
|
+
|
57
|
+
output = $terminal.read
|
58
|
+
output.should match("OpenShift login")
|
59
|
+
output.should =~ /(#{Regexp.escape("Password: ********\n")})$/
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should write out a config" do
|
63
|
+
File.exists?(@wizard.config_path).should be false
|
64
|
+
@wizard.run_next_stage
|
65
|
+
File.readable?(@wizard.config_path).should be true
|
66
|
+
cp = ParseConfig.new @wizard.config_path
|
67
|
+
cp.get_value("default_rhlogin").should == @wizard.mock_user
|
68
|
+
cp.get_value("libra_server").should == @wizard.libra_server
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should write out generated ssh keys" do
|
72
|
+
@wizard.setup_mock_ssh
|
73
|
+
private_key_file = File.join(@wizard.ssh_dir, "id_rsa")
|
74
|
+
public_key_file = File.join(@wizard.ssh_dir, "id_rsa.pub")
|
75
|
+
File.exists?(private_key_file).should be false
|
76
|
+
File.exists?(public_key_file).should be false
|
77
|
+
@wizard.run_next_stage
|
78
|
+
File.exists?(private_key_file).should be true
|
79
|
+
File.exists?(public_key_file).should be true
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should upload ssh keys" do
|
83
|
+
@wizard.stub_ssh_keys
|
84
|
+
# don't upload
|
85
|
+
$terminal.write_line('no')
|
86
|
+
@wizard.run_next_stage
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should check for client tools" do
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should ask for a namespace" do
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should show app creation commands" do
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should show a thank you message" do
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "Repeat run of rhc setup without anything set" do
|
107
|
+
|
108
|
+
|
109
|
+
it "should print out repeat run greeting" do
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should ask for login and hide password input" do
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should write out a config" do
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should write out generated ssh keys" do
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should upload ssh key as default" do
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should check for client tools and print they need to be installed" do
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should ask for a namespace" do
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should show app creation commands" do
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should show a thank you message" do
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "Repeat run of rhc setup with config set" do
|
147
|
+
|
148
|
+
it "should print out repeat run greeting" do
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should ask for password input (no login)" do
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should write out generated ssh keys" do
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should find out that you do not have not uploaded the keys and ask to name the key" do
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should check for client tools and find them" do
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should ask for a namespace" do
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should show app creation commands" do
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should show a thank you message" do
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "Repeat run of rhc setup with config and ssh keys set" do
|
182
|
+
|
183
|
+
it "should print out repeat run greeting" do
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should ask for password input (no login)" do
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should check for ssh tools and find a match" do
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should check for client tools and find them" do
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should ask for a namespace" do
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should show app creation commands" do
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should show a thank you message" do
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "Repeat run of rhc setup with everything set" do
|
213
|
+
|
214
|
+
it "should print out repeat run greeting" do
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should ask password input (not login)" do
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should check for ssh keys and find they are uploaded" do
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should check for client tools and find them" do
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should show namespace" do
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
it "should list apps" do
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should show a thank you message" do
|
239
|
+
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "Repeat run of rhc setup with everything set but platform set to Windows" do
|
244
|
+
|
245
|
+
it "should print out repeat run greeting" do
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should ask password input (not login)" do
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should check for ssh keys and find they are uploaded" do
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should print out windows client tool info" do
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should show namespace" do
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should list apps" do
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should show a thank you message" do
|
270
|
+
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
module WizardDriver
|
275
|
+
attr_accessor :mock_user, :libra_server, :config_path, :ssh_dir
|
276
|
+
def initialize
|
277
|
+
RHC::Config.home_dir = '/home/mock_user'
|
278
|
+
super '/home/mock_user/.openshift/openshift.conf'
|
279
|
+
@ssh_dir = "#{RHC::Config.home_dir}/.ssh/"
|
280
|
+
@libra_server = 'mock.openshift.redhat.com'
|
281
|
+
@mock_user = 'mock_user@foo.bar'
|
282
|
+
@mock_git_installed = true
|
283
|
+
@mock_package_kit_installed = false
|
284
|
+
@current_wizard_stage = nil
|
285
|
+
@platform_windows = false
|
286
|
+
end
|
287
|
+
|
288
|
+
def run_next_stage
|
289
|
+
if @current_wizard_stage.nil?
|
290
|
+
@current_wizard_stage = 0
|
291
|
+
else
|
292
|
+
return false if @current_wizard_stage >= stages.length + 1
|
293
|
+
@current_wizard_stage += 1
|
294
|
+
end
|
295
|
+
|
296
|
+
self.send stages[@current_wizard_stage]
|
297
|
+
end
|
298
|
+
|
299
|
+
def stub_user_info
|
300
|
+
data = {:ssh_key => "",
|
301
|
+
:ssh_key_type => "",
|
302
|
+
:rhlogin => @mock_user,
|
303
|
+
}
|
304
|
+
|
305
|
+
data = RHC::json_encode(data)
|
306
|
+
stub_request(:post, "https://#{@libra_server}/broker/userinfo").to_return(:status => 200, :body => RHC::json_encode({:data => data}), :headers => {})
|
307
|
+
end
|
308
|
+
|
309
|
+
def stub_rest_api
|
310
|
+
body = {
|
311
|
+
"data" => {
|
312
|
+
"LIST_ESTIMATES" => {
|
313
|
+
"optional_params" => [],
|
314
|
+
"rel" => "List available estimates",
|
315
|
+
"method" => "GET",
|
316
|
+
"href" => "https => //@{libra_server}/broker/rest/estimates",
|
317
|
+
"required_params" => []
|
318
|
+
},
|
319
|
+
"API" => {"optional_params" => [],
|
320
|
+
"rel" => "API entry point",
|
321
|
+
"method" => "GET",
|
322
|
+
"href" => "https => //#{libra_server}/broker/rest/api",
|
323
|
+
"required_params" => []
|
324
|
+
},
|
325
|
+
"LIST_CARTRIDGES" => {
|
326
|
+
"optional_params" => [],
|
327
|
+
"rel" => "List cartridges",
|
328
|
+
"method" => "GET","href" => "https => //@{libra_server}/broker/rest/cartridges",
|
329
|
+
"required_params" => []
|
330
|
+
},
|
331
|
+
"GET_USER" => {
|
332
|
+
"optional_params" => [],
|
333
|
+
"rel" => "Get user information",
|
334
|
+
"method" => "GET",
|
335
|
+
"href" => "https => //#{libra_server}/broker/rest/user",
|
336
|
+
"required_params" => []
|
337
|
+
},
|
338
|
+
"LIST_DOMAINS" => {
|
339
|
+
"optional_params" => [],
|
340
|
+
"rel" => "List domains",
|
341
|
+
"method" => "GET",
|
342
|
+
"href" => "https => //@libra_server/broker/rest/domains",
|
343
|
+
"required_params" => []
|
344
|
+
},
|
345
|
+
"LIST_TEMPLATES" => {
|
346
|
+
"optional_params" => [],
|
347
|
+
"rel" => "List application templates",
|
348
|
+
"method" => "GET",
|
349
|
+
"href" => "https => //@{libra_server}/broker/rest/application_template",
|
350
|
+
"required_params" => []
|
351
|
+
},
|
352
|
+
"ADD_DOMAIN" => {
|
353
|
+
"optional_params" => [],
|
354
|
+
"rel" => "Create new domain",
|
355
|
+
"method" => "POST",
|
356
|
+
"href" => "https => //@{libra_server}/broker/rest/domains",
|
357
|
+
"required_params" => [
|
358
|
+
{"description" => "Name of the domain",
|
359
|
+
"valid_options" => [],
|
360
|
+
"type" => "string",
|
361
|
+
"name" => "id"
|
362
|
+
}
|
363
|
+
]
|
364
|
+
}
|
365
|
+
},
|
366
|
+
"version" => "1.0",
|
367
|
+
"type" => "links",
|
368
|
+
"supported_api_versions" => ["1.0"],
|
369
|
+
"messages" => [],
|
370
|
+
"status" => "ok"
|
371
|
+
}
|
372
|
+
|
373
|
+
stub_request(:get, "https://mock_user%40foo.bar:password@mock.openshift.redhat.com/broker/rest/api").to_return(:status => 200, :body => RHC::json_encode(body), :headers => {})
|
374
|
+
end
|
375
|
+
|
376
|
+
def stub_ssh_keys
|
377
|
+
# TODO: add ssh keys if requests
|
378
|
+
data = {:ssh_key => "",
|
379
|
+
:keys => []
|
380
|
+
}
|
381
|
+
|
382
|
+
data = RHC::json_encode(data)
|
383
|
+
stub_request(:post, "https://#{@libra_server}/broker/ssh_keys").to_return(:status => 200, :body => RHC::json_encode({:data => data}))
|
384
|
+
end
|
385
|
+
|
386
|
+
def setup_mock_config
|
387
|
+
FileUtils.mkdir_p File.dirname(@config_path)
|
388
|
+
File.open(@config_path, "w") do |file|
|
389
|
+
file.puts <<EOF
|
390
|
+
# Default user login
|
391
|
+
default_rhlogin='#{@mock_user}'
|
392
|
+
|
393
|
+
# Server API
|
394
|
+
libra_server = '#{@libra_server}'
|
395
|
+
EOF
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def setup_mock_ssh(add_ssh_key=false)
|
400
|
+
FileUtils.mkdir_p @ssh_dir
|
401
|
+
if add_ssh_key
|
402
|
+
#TODO: add and ssh key to the directory
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
def has_git?
|
407
|
+
@mock_git_installed
|
408
|
+
end
|
409
|
+
|
410
|
+
def has_package_kit?
|
411
|
+
@mock_package_kit_installed
|
412
|
+
end
|
413
|
+
|
414
|
+
def windows?
|
415
|
+
@platform_windows
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
class FirstRunWizardDriver < RHC::Wizard
|
420
|
+
include WizardDriver
|
421
|
+
end
|
422
|
+
|
423
|
+
class RerunWizardDriver < RHC::RerunWizard
|
424
|
+
include WizardDriver
|
425
|
+
end
|
426
|
+
end
|