reservoir 0.0.3 → 0.0.4
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/examples/rails_server.yml +6 -6
- data/lib/reservoir/application.rb +32 -29
- data/lib/reservoir/caller.rb +6 -1
- data/lib/reservoir/project.rb +14 -5
- data/lib/reservoir/version.rb +64 -7
- data/lib/reservoir/version_arguments.rb +13 -0
- data/lib/reservoir/which_script.rb +0 -5
- data/lib/reservoir.rb +2 -0
- data/spec/application_spec.rb +53 -17
- data/spec/caller_spec.rb +6 -0
- data/spec/project_spec.rb +23 -16
- data/spec/sample_project.yml +2 -1
- data/spec/sample_project2.yml +2 -1
- data/spec/version_spec.rb +94 -20
- data/spec/which_script_spec.rb +9 -19
- metadata +11 -10
data/examples/rails_server.yml
CHANGED
|
@@ -2,42 +2,52 @@ module Reservoir
|
|
|
2
2
|
|
|
3
3
|
class Application
|
|
4
4
|
|
|
5
|
+
attr_accessor :print_mode
|
|
6
|
+
|
|
7
|
+
def initialize(data = {})
|
|
8
|
+
@print_mode = data[:print_mode] || :stdio
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def print_mode=(val)
|
|
12
|
+
@print_mode = val || :stdio
|
|
13
|
+
end
|
|
14
|
+
|
|
5
15
|
def welcome_message
|
|
6
|
-
"reservoir, version #{Reservoir::VERSION}\n"
|
|
16
|
+
print "reservoir, version #{Reservoir::VERSION}\n"
|
|
7
17
|
end
|
|
8
18
|
|
|
9
19
|
def usage_message
|
|
10
|
-
"USAGE: reservoir <project_file1> <project_file2> ...\n or reservoir help to see this message\n"
|
|
20
|
+
print "USAGE: reservoir <project_file1> <project_file2> ...\n or reservoir help to see this message\n"
|
|
11
21
|
end
|
|
12
22
|
|
|
13
23
|
def exception_message(error)
|
|
14
|
-
"ERROR: #{error.message}\n\n #{error.backtrace.join('\n ')}"
|
|
24
|
+
print "ERROR: #{error.message}\n\n #{error.backtrace.join('\n ')}"
|
|
15
25
|
end
|
|
16
26
|
|
|
17
27
|
def project_message(project)
|
|
18
|
-
"\n===\nLoading Project: #{project.name} [#{project.file}]\n===\n"
|
|
28
|
+
print "\n===\nLoading Project: #{project.name} [#{project.file}]\n===\n"
|
|
19
29
|
end
|
|
20
30
|
|
|
21
|
-
def
|
|
22
|
-
|
|
31
|
+
def which_version_message(script,version,path)
|
|
32
|
+
print "#{script} : #{version} : #{path}\n"
|
|
23
33
|
end
|
|
24
|
-
|
|
34
|
+
|
|
25
35
|
|
|
26
36
|
def run(args)
|
|
27
37
|
|
|
28
38
|
if args.nil? || args.empty?
|
|
29
|
-
|
|
39
|
+
usage_message
|
|
30
40
|
return
|
|
31
41
|
end
|
|
32
42
|
|
|
33
|
-
|
|
43
|
+
welcome_message
|
|
34
44
|
|
|
35
45
|
if ["--version","-version","-v","--v","version"].include?(args[0])
|
|
36
46
|
return
|
|
37
47
|
end
|
|
38
48
|
|
|
39
49
|
if ["--help","-help","-h","--h","help"].include?(args[0])
|
|
40
|
-
|
|
50
|
+
usage_message
|
|
41
51
|
return
|
|
42
52
|
end
|
|
43
53
|
|
|
@@ -45,35 +55,28 @@ module Reservoir
|
|
|
45
55
|
args.each do |filename|
|
|
46
56
|
all_projects = Project.load_from_file(filename)
|
|
47
57
|
all_projects.each do |p|
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
print_mode = p.output
|
|
59
|
+
project_message(p)
|
|
50
60
|
p.scripts.each do |script|
|
|
61
|
+
which_script = p.template(WhichScript)
|
|
62
|
+
version = p.template(Version)
|
|
51
63
|
which_script.go(script)
|
|
52
|
-
|
|
64
|
+
version.go(script)
|
|
65
|
+
which_version_message(script,version.version,which_script.response)
|
|
53
66
|
end
|
|
54
67
|
end
|
|
55
68
|
end
|
|
56
69
|
rescue
|
|
57
|
-
|
|
70
|
+
exception_message($!)
|
|
58
71
|
end
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# Provide the ability to direct the stdio with a print_mode switch
|
|
63
|
-
@@print_mode = :stdio
|
|
64
|
-
def self.print_mode=(val)
|
|
65
|
-
@@print_mode = val
|
|
66
|
-
end
|
|
67
|
-
def self.print_mode
|
|
68
|
-
@@print_mode
|
|
69
|
-
end
|
|
70
|
-
def self.reset_print_mode
|
|
71
|
-
@@print_mode = :stdio
|
|
72
|
+
print ""
|
|
72
73
|
end
|
|
73
74
|
|
|
74
|
-
def
|
|
75
|
-
if
|
|
75
|
+
def print(output)
|
|
76
|
+
if @print_mode == :stdio
|
|
76
77
|
STDOUT.puts output
|
|
78
|
+
elsif @print_mode.kind_of?(Hash) && !@print_mode[:file].nil?
|
|
79
|
+
open(@print_mode[:file], 'a') { |f| f.puts(output) }
|
|
77
80
|
else
|
|
78
81
|
output
|
|
79
82
|
end
|
data/lib/reservoir/caller.rb
CHANGED
|
@@ -18,7 +18,7 @@ module Reservoir
|
|
|
18
18
|
def go(command = nil)
|
|
19
19
|
begin
|
|
20
20
|
@command = command unless command.nil?
|
|
21
|
-
@response =
|
|
21
|
+
@response = Caller.exec(full_command).strip
|
|
22
22
|
@success = true
|
|
23
23
|
rescue
|
|
24
24
|
@response = "#{$!}"
|
|
@@ -44,6 +44,11 @@ module Reservoir
|
|
|
44
44
|
"#{ssh} '#{@command}'"
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
def self.exec(full_command)
|
|
48
|
+
`#{full_command}`
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
47
52
|
end
|
|
48
53
|
|
|
49
54
|
end
|
data/lib/reservoir/project.rb
CHANGED
|
@@ -2,18 +2,19 @@ module Reservoir
|
|
|
2
2
|
|
|
3
3
|
class Project
|
|
4
4
|
|
|
5
|
-
attr_accessor :scripts, :file, :remote_user, :remote_server
|
|
5
|
+
attr_accessor :scripts, :file, :remote_user, :remote_server, :output
|
|
6
6
|
|
|
7
7
|
def initialize(data = {})
|
|
8
8
|
@file = data[:file]
|
|
9
9
|
@remote_user = data[:remote_user]
|
|
10
10
|
@remote_server = data[:remote_server]
|
|
11
11
|
@scripts = data[:scripts] || []
|
|
12
|
+
@output = data[:output]
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def self.load_from_file(file)
|
|
15
16
|
options = YAML::load( File.open( file ) )
|
|
16
|
-
default_args = { file: file, scripts: options["scripts"].each.collect { |script| script["name"] } }
|
|
17
|
+
default_args = { file: file, scripts: options["scripts"].each.collect { |script| script["name"] }, output: options["output"] }
|
|
17
18
|
|
|
18
19
|
all_projects = []
|
|
19
20
|
all_servers = options["remotes"]
|
|
@@ -21,14 +22,14 @@ module Reservoir
|
|
|
21
22
|
all_projects << Project.new(default_args)
|
|
22
23
|
else
|
|
23
24
|
all_servers.each do |remote|
|
|
24
|
-
all_projects << Project.new(default_args.merge( remote_user: remote["user"], remote_server: remote["server"]))
|
|
25
|
+
all_projects << Project.new(default_args.merge( remote_user: remote["user"], remote_server: remote["server"], output: resolve_placeholders(default_args[:output],remote)))
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
all_projects
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
def
|
|
31
|
-
|
|
31
|
+
def template(clazz)
|
|
32
|
+
clazz.new(remote_user: @remote_user, remote_server: @remote_server)
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
def name
|
|
@@ -37,6 +38,14 @@ module Reservoir
|
|
|
37
38
|
"#{@remote_user}@#{@remote_server}"
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def self.resolve_placeholders(var,remote)
|
|
44
|
+
return var if var.nil?
|
|
45
|
+
var = var.gsub("@@SERVER_NAME@@",remote["server"])
|
|
46
|
+
var
|
|
47
|
+
end
|
|
48
|
+
|
|
40
49
|
end
|
|
41
50
|
|
|
42
51
|
end
|
data/lib/reservoir/version.rb
CHANGED
|
@@ -1,34 +1,91 @@
|
|
|
1
1
|
module Reservoir
|
|
2
2
|
|
|
3
|
-
VERSION = "0.0.
|
|
3
|
+
VERSION = "0.0.4"
|
|
4
4
|
|
|
5
5
|
class Version
|
|
6
6
|
|
|
7
7
|
attr_accessor :version_info, :version, :version_parts
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@caller = Caller.new(:remote_server => data[:remote_server], :remote_user => data[:remote_user])
|
|
11
|
+
@success = false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def remote_user
|
|
15
|
+
@caller.remote_user
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def remote_server
|
|
19
|
+
@caller.remote_server
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def possible_commands(script_name)
|
|
24
|
+
return [] if script_name.nil? || script_name == ""
|
|
25
|
+
known_arguments = Version.arguments[script_name]
|
|
26
|
+
return ["#{script_name} #{known_arguments}"] unless known_arguments.nil?
|
|
27
|
+
["--version","-version"].collect { |args| "#{script_name} #{args}"}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def go(script_name)
|
|
31
|
+
@success = false
|
|
32
|
+
possible_commands(script_name).each do |command|
|
|
33
|
+
if @caller.go(command) && read(@caller.response)
|
|
34
|
+
break
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
@success
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def success?
|
|
41
|
+
@success
|
|
42
|
+
end
|
|
8
43
|
|
|
9
44
|
def read(version_info)
|
|
10
45
|
@version_info = version_info
|
|
46
|
+
@version_parts = nil
|
|
47
|
+
@version = nil
|
|
48
|
+
@success = false
|
|
11
49
|
|
|
12
50
|
major_minor_revision_match = /(\d*)\.(\d*)\.(\d*)/
|
|
13
51
|
mmr_patchlevel_match = /(\d*)\.(\d*)\.(\d*).*(patchlevel)\s*(\d*)/
|
|
52
|
+
rvm_match = /rvm\s*(\d*)\.(\d*)\.(\d*)/
|
|
14
53
|
|
|
15
54
|
|
|
16
55
|
m = version_info.match(mmr_patchlevel_match)
|
|
17
56
|
unless m.nil?
|
|
18
57
|
@version_parts = [ m[1], m[2], m[3], m[5] ]
|
|
19
58
|
@version = @version_parts[0..2].join(".") + "-p" + m[5]
|
|
20
|
-
|
|
59
|
+
@success = true
|
|
60
|
+
return @success
|
|
21
61
|
end
|
|
22
62
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
63
|
+
if major_minor_revision(rvm_match)
|
|
64
|
+
return @success
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if major_minor_revision(major_minor_revision_match)
|
|
68
|
+
return @success
|
|
28
69
|
end
|
|
29
70
|
|
|
71
|
+
@version_info = nil
|
|
72
|
+
@success
|
|
30
73
|
end
|
|
31
74
|
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def major_minor_revision(matcher)
|
|
78
|
+
m = @version_info.match(matcher)
|
|
79
|
+
if m.nil?
|
|
80
|
+
false
|
|
81
|
+
else
|
|
82
|
+
@version_parts = [ m[1], m[2], m[3] ]
|
|
83
|
+
@version = @version_parts.join(".")
|
|
84
|
+
@success = true
|
|
85
|
+
@success
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
32
89
|
end
|
|
33
90
|
|
|
34
91
|
end
|
|
@@ -17,11 +17,6 @@ module Reservoir
|
|
|
17
17
|
@caller.remote_server
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def to_s
|
|
21
|
-
return "WhichScript called before any #go(script) was performed" if @script.nil?
|
|
22
|
-
"#{@script} : #{@response}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
20
|
def go(app_name)
|
|
26
21
|
@script = app_name
|
|
27
22
|
@path = @caller.go_with_response("which #{app_name}")
|
data/lib/reservoir.rb
CHANGED
data/spec/application_spec.rb
CHANGED
|
@@ -8,7 +8,25 @@ module Reservoir
|
|
|
8
8
|
@project_file = File.dirname(__FILE__) + '/sample_project.yml'
|
|
9
9
|
@project_file2 = File.dirname(__FILE__) + '/sample_project2.yml'
|
|
10
10
|
@application = Application.new
|
|
11
|
-
|
|
11
|
+
@application.print_mode = :string
|
|
12
|
+
|
|
13
|
+
Caller.stub!(:exec).with("which ruby").and_return("/path/to/ruby")
|
|
14
|
+
Caller.stub!(:exec).with("which rvm").and_return("/path/to/rvm")
|
|
15
|
+
Caller.stub!(:exec).with("which node").and_return("/path/to/node")
|
|
16
|
+
Caller.stub!(:exec).with("ssh aforward@a4word.com 'which ruby'").and_return("/path/to/a4word/ruby")
|
|
17
|
+
|
|
18
|
+
Caller.stub!(:exec).with("ruby --version").and_return("v1.2.3")
|
|
19
|
+
Caller.stub!(:exec).with("rvm --version").and_return("1.2.4")
|
|
20
|
+
Caller.stub!(:exec).with("node --version").and_return("")
|
|
21
|
+
Caller.stub!(:exec).with("node -version").and_return("")
|
|
22
|
+
Caller.stub!(:exec).with("ssh aforward@a4word.com 'ruby --version'").and_return("1.2.6")
|
|
23
|
+
|
|
24
|
+
File.delete("output.txt") if File.exist?("output.txt")
|
|
25
|
+
File.delete("a4word.com.reservoir") if File.exist?("a4word.com.reservoir")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
after(:all) do
|
|
29
|
+
File.delete("output.txt") if File.exist?("output.txt")
|
|
12
30
|
end
|
|
13
31
|
|
|
14
32
|
describe "#run" do
|
|
@@ -66,20 +84,20 @@ module Reservoir
|
|
|
66
84
|
it "should handle one file" do
|
|
67
85
|
@application.should_receive(:welcome_message)
|
|
68
86
|
@application.should_receive(:project_message)
|
|
69
|
-
@application.should_receive(:
|
|
87
|
+
@application.should_receive(:which_version_message).with("ruby","1.2.3","/path/to/ruby")
|
|
88
|
+
@application.should_receive(:which_version_message).with("rvm","1.2.4","/path/to/rvm")
|
|
89
|
+
@application.should_receive(:which_version_message).with("node",nil,"/path/to/node")
|
|
70
90
|
@application.should_not_receive(:exception_message)
|
|
71
91
|
@application.run([@project_file])
|
|
72
92
|
end
|
|
73
93
|
|
|
74
94
|
it "should handle multiple file" do
|
|
75
|
-
@mock = Caller.new
|
|
76
|
-
@mock.stub!(:go).and_return(true)
|
|
77
|
-
Caller.stub!(:new).and_return(@mock)
|
|
78
95
|
@application.should_receive(:welcome_message)
|
|
79
96
|
@application.should_receive(:project_message).exactly(2).times
|
|
80
|
-
@application.should_receive(:
|
|
97
|
+
@application.should_receive(:which_version_message).exactly(4).times
|
|
81
98
|
@application.should_not_receive(:exception_message)
|
|
82
99
|
@application.run([@project_file,@project_file2])
|
|
100
|
+
File.exists?("a4word.com.reservoir")
|
|
83
101
|
end
|
|
84
102
|
|
|
85
103
|
end
|
|
@@ -89,14 +107,21 @@ module Reservoir
|
|
|
89
107
|
describe "#print_mode" do
|
|
90
108
|
|
|
91
109
|
it "should be settable" do
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
@application.print_mode = :a
|
|
111
|
+
@application.print_mode.should == :a
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "should default to stdio" do
|
|
115
|
+
@application.print_mode = nil
|
|
116
|
+
@application.print_mode.should == :stdio
|
|
94
117
|
end
|
|
95
118
|
|
|
96
|
-
it "should
|
|
97
|
-
Application.print_mode
|
|
98
|
-
|
|
99
|
-
|
|
119
|
+
it "should default to :stdio" do
|
|
120
|
+
Application.new.print_mode.should == :stdio
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "should be settable in constructor" do
|
|
124
|
+
Application.new(print_mode: :blah).print_mode.should == :blah
|
|
100
125
|
end
|
|
101
126
|
|
|
102
127
|
end
|
|
@@ -104,7 +129,7 @@ module Reservoir
|
|
|
104
129
|
describe "#messages" do
|
|
105
130
|
|
|
106
131
|
it "should welcome_message" do
|
|
107
|
-
@application.welcome_message.should == "reservoir, version 0.0.
|
|
132
|
+
@application.welcome_message.should == "reservoir, version 0.0.4\n"
|
|
108
133
|
end
|
|
109
134
|
|
|
110
135
|
it "should usage_message" do
|
|
@@ -124,20 +149,31 @@ module Reservoir
|
|
|
124
149
|
end
|
|
125
150
|
end
|
|
126
151
|
|
|
152
|
+
it "should which_version_message" do
|
|
153
|
+
@application.which_version_message("a","1.2.3","/path/to/a").should == "a : 1.2.3 : /path/to/a\n"
|
|
154
|
+
end
|
|
155
|
+
|
|
127
156
|
|
|
128
157
|
end
|
|
129
158
|
|
|
130
159
|
describe "#print" do
|
|
131
160
|
|
|
132
161
|
it "should return a string if print_mode :string" do
|
|
133
|
-
|
|
134
|
-
|
|
162
|
+
@application.print_mode = :string
|
|
163
|
+
@application.print("x").should == "x"
|
|
135
164
|
end
|
|
136
165
|
|
|
137
166
|
it "should write to output if print_mode :stdio" do
|
|
138
167
|
STDOUT.should_receive(:puts).with("x")
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
@application.print_mode = :stdio
|
|
169
|
+
@application.print("x")
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "should write to file" do
|
|
173
|
+
@application.print_mode = { file: "output.txt" }
|
|
174
|
+
@application.print("x")
|
|
175
|
+
@application.print("y")
|
|
176
|
+
IO.read("output.txt").should == "x\ny\n"
|
|
141
177
|
end
|
|
142
178
|
|
|
143
179
|
end
|
data/spec/caller_spec.rb
CHANGED
|
@@ -51,6 +51,12 @@ module Reservoir
|
|
|
51
51
|
@caller.response.should == "No such file or directory - garbligook"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
it "should strip whitespace" do
|
|
55
|
+
Caller.stub!(:exec).with("garble").and_return("blah\n")
|
|
56
|
+
@caller.command = "garble"
|
|
57
|
+
@caller.go_with_response.should == "blah"
|
|
58
|
+
end
|
|
59
|
+
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
|
data/spec/project_spec.rb
CHANGED
|
@@ -30,30 +30,37 @@ module Reservoir
|
|
|
30
30
|
all.size.should == 1
|
|
31
31
|
project = all.first
|
|
32
32
|
project.scripts.should == [ "ruby", "rvm", "node"]
|
|
33
|
+
project.output.should == :string
|
|
33
34
|
end
|
|
34
35
|
|
|
35
36
|
end
|
|
36
37
|
|
|
37
|
-
describe "#
|
|
38
|
+
describe "#template" do
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
all = Project.load_from_file(File.dirname(__FILE__) + '/sample_project2.yml')
|
|
41
|
-
all.size.should == 1
|
|
42
|
-
project = all.first
|
|
40
|
+
[WhichScript,Version].each do |clazz|
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
it "should set the remote_user and remote_server for #{clazz}" do
|
|
43
|
+
all = Project.load_from_file(File.dirname(__FILE__) + '/sample_project2.yml')
|
|
44
|
+
all.size.should == 1
|
|
45
|
+
project = all.first
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
t = project.template(clazz)
|
|
48
|
+
t.remote_user.should == 'aforward'
|
|
49
|
+
t.remote_server.should == 'a4word.com'
|
|
50
|
+
project.output.should == "a4word.com.reservoir"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "should ignore remote data if not set" do
|
|
54
|
+
all = Project.load_from_file(File.dirname(__FILE__) + '/sample_project.yml')
|
|
55
|
+
all.size.should == 1
|
|
56
|
+
project = all.first
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
t = project.template(clazz)
|
|
59
|
+
t.remote_user.should == nil
|
|
60
|
+
t.remote_server.should == nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
|
|
57
64
|
end
|
|
58
65
|
|
|
59
66
|
|
data/spec/sample_project.yml
CHANGED
data/spec/sample_project2.yml
CHANGED
data/spec/version_spec.rb
CHANGED
|
@@ -5,46 +5,120 @@ module Reservoir
|
|
|
5
5
|
describe Version do
|
|
6
6
|
|
|
7
7
|
before (:each) do
|
|
8
|
-
@
|
|
8
|
+
@version = Version.new
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
describe "#
|
|
11
|
+
describe "#go" do
|
|
12
12
|
|
|
13
|
-
it "should
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
it "should use arguments if set" do
|
|
14
|
+
Version.stub!(:arguments).and_return({ "garble" => "-vgarble" })
|
|
15
|
+
Caller.stub!(:exec).with("garble -vgarble").and_return("garble v1.2.3")
|
|
16
|
+
@version.go("garble").should == true
|
|
17
|
+
@version.success?.should == true
|
|
18
|
+
@version.version_info.should == "garble v1.2.3"
|
|
19
|
+
@version.version.should == "1.2.3"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should return false if unable to locate version" do
|
|
23
|
+
Caller.stub!(:exec).with("garble --version").and_return("blah")
|
|
24
|
+
Caller.stub!(:exec).with("garble -version").and_return("")
|
|
25
|
+
@version.go("garble").should == false
|
|
26
|
+
@version.success?.should == false
|
|
27
|
+
@version.version_info.should == nil
|
|
28
|
+
@version.version.should == nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should support remote calls" do
|
|
32
|
+
Caller.stub!(:exec).with("ssh a@b 'garble --version'").and_return("v1.2.4")
|
|
33
|
+
version = Version.new(remote_user: "a", remote_server: "b")
|
|
34
|
+
version.go("garble").should == true
|
|
35
|
+
version.version_info.should == "v1.2.4"
|
|
36
|
+
version.version_parts.should == ["1","2","4"]
|
|
37
|
+
version.version.should == "1.2.4"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should support multiple gos" do
|
|
41
|
+
Caller.stub!(:exec).with("garble --version").and_return("v1.2.4")
|
|
42
|
+
Caller.stub!(:exec).with("marble --version").and_return("")
|
|
43
|
+
Caller.stub!(:exec).with("marble -version").and_return("")
|
|
44
|
+
|
|
45
|
+
@version.go("garble").should == true
|
|
46
|
+
@version.version_info.should == "v1.2.4"
|
|
47
|
+
@version.version_parts.should == ["1","2","4"]
|
|
48
|
+
@version.version.should == "1.2.4"
|
|
49
|
+
|
|
50
|
+
@version.go("marble").should == false
|
|
51
|
+
@version.version_info.should == nil
|
|
52
|
+
@version.version_parts.should == nil
|
|
53
|
+
@version.version.should == nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#command" do
|
|
60
|
+
|
|
61
|
+
it "should support nil" do
|
|
62
|
+
@version.possible_commands(nil).should == []
|
|
63
|
+
@version.possible_commands("").should == []
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should use arguments if set" do
|
|
67
|
+
Version.stub!(:arguments).and_return({ "garble" => "-vgarble" })
|
|
68
|
+
@version.possible_commands("garble").should == ["garble -vgarble"]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should provide possible answers if not in known set" do
|
|
72
|
+
@version.possible_commands("garble").should == ["garble --version","garble -version"]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
describe "#read" do
|
|
79
|
+
|
|
80
|
+
it "should store version_info if found" do
|
|
81
|
+
@version.read("blah").should == false
|
|
82
|
+
@version.version_info.should == nil
|
|
83
|
+
@version.version.should == nil
|
|
16
84
|
end
|
|
17
85
|
|
|
18
86
|
describe "#version" do
|
|
19
87
|
|
|
20
88
|
it "should understand RVM" do
|
|
21
|
-
@
|
|
22
|
-
@
|
|
23
|
-
@
|
|
89
|
+
@version.read("rvm 1.2.3 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]").should == true
|
|
90
|
+
@version.version_parts.should == ["1","2","3"]
|
|
91
|
+
@version.version.should == "1.2.3"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should understand RVM under a gemset" do
|
|
95
|
+
@version.read("Using /Users/aforward/.rvm/gems/ruby-1.9.2-p180 with gemset reservoirc\nrvm 1.2.3 by Wayne E. Seguin (wayneeseguin@gmail.com) [https://rvm.beginrescueend.com/]").should == true
|
|
96
|
+
@version.version_parts.should == ["1","2","3"]
|
|
97
|
+
@version.version.should == "1.2.3"
|
|
24
98
|
end
|
|
25
99
|
|
|
26
100
|
it "should understand node.js" do
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
@
|
|
101
|
+
@version.read("v0.4.8").should == true
|
|
102
|
+
@version.version_parts.should == ["0","4","8"]
|
|
103
|
+
@version.version.should == "0.4.8"
|
|
30
104
|
end
|
|
31
105
|
|
|
32
106
|
it "should understand ruby" do
|
|
33
|
-
@
|
|
34
|
-
@
|
|
35
|
-
@
|
|
107
|
+
@version.read("ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]").should == true
|
|
108
|
+
@version.version_parts.should == ["1","8","7","72"]
|
|
109
|
+
@version.version.should == "1.8.7-p72"
|
|
36
110
|
end
|
|
37
111
|
|
|
38
112
|
it "should understand nginx" do
|
|
39
|
-
@
|
|
40
|
-
@
|
|
41
|
-
@
|
|
113
|
+
@version.read("nginx: nginx version: nginx/1.4.5").should == true
|
|
114
|
+
@version.version_parts.should == ["1","4","5"]
|
|
115
|
+
@version.version.should == "1.4.5"
|
|
42
116
|
end
|
|
43
117
|
|
|
44
118
|
it "should understand passenger" do
|
|
45
|
-
@
|
|
46
|
-
@
|
|
47
|
-
@
|
|
119
|
+
@version.read("Phusion Passenger version 3.0.7").should == true
|
|
120
|
+
@version.version_parts.should == ["3","0","7"]
|
|
121
|
+
@version.version.should == "3.0.7"
|
|
48
122
|
end
|
|
49
123
|
|
|
50
124
|
end
|
data/spec/which_script_spec.rb
CHANGED
|
@@ -6,8 +6,6 @@ module Reservoir
|
|
|
6
6
|
|
|
7
7
|
before (:each) do
|
|
8
8
|
@which_script = WhichScript.new
|
|
9
|
-
@caller = Caller.new
|
|
10
|
-
Caller.stub!(:new).and_return(@caller)
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
describe "#initialize" do
|
|
@@ -24,7 +22,7 @@ module Reservoir
|
|
|
24
22
|
it "should set the path" do
|
|
25
23
|
@which_script.go('ruby').should == true
|
|
26
24
|
@which_script.success?.should == true
|
|
27
|
-
@which_script.path.should == `which ruby
|
|
25
|
+
@which_script.path.should == `which ruby`.strip
|
|
28
26
|
@which_script.response.should == @which_script.path
|
|
29
27
|
end
|
|
30
28
|
|
|
@@ -36,30 +34,22 @@ module Reservoir
|
|
|
36
34
|
end
|
|
37
35
|
|
|
38
36
|
it "should analyze on remote server if set in constructor" do
|
|
39
|
-
Caller.
|
|
40
|
-
@caller.should_receive(:go_with_response).with("which ruby").and_return("blah")
|
|
37
|
+
Caller.stub!(:exec).with("ssh b@a 'which ruby'").and_return("blah")
|
|
41
38
|
@which_script = WhichScript.new(remote_server: 'a', remote_user: 'b')
|
|
42
39
|
@which_script.go('ruby').should == true
|
|
43
40
|
@which_script.success?.should == true
|
|
44
41
|
@which_script.path.should == "blah"
|
|
45
42
|
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@which_script.to_s.should == "WhichScript called before any #go(script) was performed"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "should say where the script went" do
|
|
56
|
-
@which_script.script = "a"
|
|
57
|
-
@which_script.response = "b"
|
|
58
|
-
@which_script.to_s.should == "a : b"
|
|
43
|
+
|
|
44
|
+
it "should strip extra white space" do
|
|
45
|
+
Caller.stub!(:exec).with("which ruby").and_return("blah\n")
|
|
46
|
+
@which_script.go('ruby').should == true
|
|
47
|
+
@which_script.success?.should == true
|
|
48
|
+
@which_script.path.should == "blah"
|
|
59
49
|
end
|
|
60
50
|
|
|
61
51
|
end
|
|
62
|
-
|
|
52
|
+
|
|
63
53
|
end
|
|
64
54
|
|
|
65
55
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reservoir
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,11 +9,11 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2011-
|
|
12
|
+
date: 2011-09-15 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &70343763104020 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :development
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *70343763104020
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: autotest
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &70343763103600 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *70343763103600
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: autotest-fsevent
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &70343763103140 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *70343763103140
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: rb-fsevent
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &70343763102720 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ! '>='
|
|
@@ -54,7 +54,7 @@ dependencies:
|
|
|
54
54
|
version: '0'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *70343763102720
|
|
58
58
|
description: Helps manage cloud-based server instances by enumerating, comparing and
|
|
59
59
|
diff'ing application configurations
|
|
60
60
|
email:
|
|
@@ -76,6 +76,7 @@ files:
|
|
|
76
76
|
- lib/reservoir/caller.rb
|
|
77
77
|
- lib/reservoir/project.rb
|
|
78
78
|
- lib/reservoir/version.rb
|
|
79
|
+
- lib/reservoir/version_arguments.rb
|
|
79
80
|
- lib/reservoir/which_script.rb
|
|
80
81
|
- reservoir.gemspec
|
|
81
82
|
- spec/application_spec.rb
|