Skip to content

Commit 39a58da

Browse files
committed
Quiet(er) spec output
- Introduce `Output.say` which we stub in specs - Hoist some behavior up to `spec_helper`, and require this in all specs
1 parent 8c1a3a8 commit 39a58da

File tree

32 files changed

+96
-83
lines changed

32 files changed

+96
-83
lines changed

Rakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
require_relative 'lib/stemcell/builder'
1+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
2+
3+
require 'output'
4+
require 'stemcell/builder'
25

36
import 'lib/tasks/build/aws.rake'
47
import 'lib/tasks/build/azure.rake'

lib/exec_command.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'open3'
2+
require_relative 'output'
23

34
class Executor
45
def self.exec_command(cmd)
@@ -9,7 +10,7 @@ def self.exec_command(cmd)
910
Open3.popen2(cmd) do |stdin, out, wait_thr|
1011
out.each_line do |line|
1112
ret += line
12-
puts line
13+
Output.say line
1314
end
1415
exit_status = wait_thr.value
1516
if exit_status != 0

lib/output.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Output
2+
def self.say(something)
3+
puts something
4+
end
5+
end

lib/packer/runner.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'json'
33
require 'English'
44
require 'open3'
5+
require_relative '../output'
56

67
module Packer
78
class Runner
@@ -25,7 +26,7 @@ def run(command, args={})
2526
log_config(config_file.path)
2627

2728
packer_command = "packer #{command} -machine-readable #{args_combined} #{config_file.path}"
28-
puts packer_command
29+
Output.say packer_command
2930

3031
Open3.popen2e(packer_command) do |_stdin, out, wait_thr|
3132
yield(out) if block_given?
@@ -38,7 +39,7 @@ def log_config(path)
3839
unless "#{ENV['NEW_PASSWORD']}".empty?
3940
config_contents.gsub! ENV['NEW_PASSWORD'], "( redacted )"
4041
end
41-
puts "config file contents: #{config_contents}"
42+
Output.say "config file contents: #{config_contents}"
4243
end
4344
end
4445
end

lib/s3.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'aws-sdk-s3'
2+
require_relative 'output'
23
require_relative 'exec_command'
34

45
module S3
@@ -15,23 +16,23 @@ def initialize(endpoint: "")
1516
end
1617
def get(bucket,key,file_name)
1718
bucket, key = rationalize(bucket, key)
18-
puts "Downloading the #{key} from #{bucket} to #{file_name}"
19+
Output.say "Downloading the #{key} from #{bucket} to #{file_name}"
1920
path = File.dirname(file_name)
2021
FileUtils.mkdir_p(path)
2122
File.open(file_name, 'wb') do |file|
2223
@s3.get_object({ bucket:bucket , key:key, response_target: file })
2324
end
24-
puts "Finished Downloading the #{key} from #{bucket} to #{file_name}"
25+
Output.say "Finished Downloading the #{key} from #{bucket} to #{file_name}"
2526
end
2627
def put(bucket,key,file_name)
2728
bucket, key = rationalize(bucket, key)
28-
puts "Uploading the #{file_name} to #{bucket}:#{key}"
29+
Output.say "Uploading the #{file_name} to #{bucket}:#{key}"
2930
@s3_resource.bucket(bucket).object(key).upload_file(file_name)
30-
puts "Finished uploading the #{file_name} to #{bucket}:#{key}"
31+
Output.say "Finished uploading the #{file_name} to #{bucket}:#{key}"
3132
end
3233
def list(bucket)
3334
bucket, prefix = rationalize(bucket, '')
34-
puts "Listing bucket #{bucket} with prefix #{prefix}"
35+
Output.say "Listing bucket #{bucket} with prefix #{prefix}"
3536
resp = @s3.list_objects({
3637
bucket: bucket,
3738
delimiter: '/',
@@ -40,9 +41,9 @@ def list(bucket)
4041
resp.to_h[:contents].map { |x| x[:key] }
4142
end
4243
def clear(bucket)
43-
puts "Clearing bucket #{bucket}"
44+
Output.say "Clearing bucket #{bucket}"
4445
@s3_resource.bucket(bucket).clear!
45-
puts "Finished: clearing bucket #{bucket}"
46+
Output.puts "Finished: clearing bucket #{bucket}"
4647
end
4748
private
4849
# Our ci passes the bucket and key as bucket: bucket/path/to/file,
@@ -56,7 +57,7 @@ def rationalize(bucket, key)
5657
end
5758

5859
def self.test_upload_permissions(bucket, endpoint="")
59-
puts "Testing upload permissions for #{bucket}"
60+
Output.say "Testing upload permissions for #{bucket}"
6061
tempfile = Tempfile.new("stemcell-permissions-tempfile")
6162
s3_client = Client.new(endpoint: endpoint)
6263
s3_client.put(bucket, 'test-upload-permissions', tempfile.path)

lib/stemcell/builder/aws.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def parse_packer_output(packer_output)
4848
amis = []
4949
packer_output.each_line do |line|
5050
if !(line.include?('secret_key') || line.include?('access_key'))
51-
puts line
51+
Output.say line
5252
end
5353
ami = parse_ami(line)
5454
if !ami.nil?

lib/stemcell/builder/azure.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def build
3434
end
3535

3636
def stage_image(disk_uri)
37-
puts 'TODO: stage azure disk image'
37+
Output.say 'TODO: stage azure disk image'
3838
end
3939

4040
def publish_image(disk_uri)
41-
puts 'TODO: publish azure disk image'
41+
Output.say 'TODO: publish azure disk image'
4242
end
4343

4444
private
@@ -63,7 +63,7 @@ def packer_config
6363
def parse_packer_output(packer_output)
6464
disk_uri = nil
6565
packer_output.each_line do |line|
66-
puts line
66+
Output.say line
6767
disk_uri ||= parse_disk_uri(line)
6868
end
6969
disk_uri

lib/stemcell/builder/base.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require_relative '../../output'
2+
13
module Stemcell
24
class Builder
35
class PackerFailure < RuntimeError
@@ -51,7 +53,7 @@ def run_packer
5153
packer_artifact = parse_packer_output(stdout)
5254
end
5355
if exit_status != 0
54-
puts "packer_artifact is: #{packer_artifact}"
56+
Output.say "packer_artifact is: #{packer_artifact}"
5557
raise PackerFailure
5658
end
5759
packer_artifact
@@ -63,7 +65,7 @@ def exec_command(cmd)
6365
STDOUT.sync = true
6466
Open3.popen2(cmd) do |stdin, out, wait_thr|
6567
out.each_line do |line|
66-
puts line
68+
Output.say line
6769
end
6870
exit_status = wait_thr.value
6971
if exit_status != 0
@@ -74,15 +76,15 @@ def exec_command(cmd)
7476

7577
def parse_packer_output(packer_output)
7678
packer_output.each_line do |line|
77-
puts line
79+
Output.say line
7880
end
7981
end
8082

8183
def update_list_path
8284
if File.exist?(File.join(@output_directory, 'updates.txt'))
8385
File.join(@output_directory, 'updates.txt')
8486
else
85-
puts "'updates.txt' does not exist in #{@output_directory}"
87+
Output.say "'updates.txt' does not exist in #{@output_directory}"
8688
end
8789
end
8890
end

lib/stemcell/builder/gcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def packer_config
4242
def parse_packer_output(packer_output)
4343
image_name = nil
4444
packer_output.each_line do |line|
45-
puts line
45+
Output.say line
4646
image_name ||= parse_image_name(line)
4747
end
4848
get_image_url(image_name)

lib/stemcell/packager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'zlib'
22
require 'rubygems/package'
3+
require_relative '../output'
34

45
module Stemcell
56
class Packager
@@ -190,14 +191,13 @@ def self.exec_command(cmd)
190191
STDOUT.sync = true
191192
Open3.popen2(cmd) do |stdin, out, wait_thr|
192193
out.each_line do |line|
193-
puts line
194+
Output.say line
194195
end
195196
exit_status = wait_thr.value
196197
if exit_status != 0
197198
raise "error running command: #{cmd}"
198199
end
199200
end
200201
end
201-
202202
end
203203
end

0 commit comments

Comments
 (0)