logger_pipe 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b2b4ad0b32253f85caaa05aa06c57e5d6841dbb
4
- data.tar.gz: d4a939d57414b7a46f28b6a74782bca37224a2e4
3
+ metadata.gz: e30183b69fa830729b5728e0c716b115fbc4670c
4
+ data.tar.gz: a9483ca5b578d2067d0154353a83708dc0f4faa2
5
5
  SHA512:
6
- metadata.gz: 7ed86179cfc46951c8c330ad461a458f8e16919dde9ecfdff190fba758ea4ec86888ed395d5d1ee222b61eac4657bce2dd518841e6fab47c7f872d15d6a2418f
7
- data.tar.gz: 22ea00786ffbe99ef4b200465256bd0b854e99ba4cf67d4df0c05a638ca526b9e09a188bd6057e1dadd32c799a3d50e0459b48ec9f794aee11c74e1e6982c46e
6
+ metadata.gz: 89dfe1e4d6939a991fc2125a3a8dd43640e6618a18c30b13939ba7ff27bd59c918684f41a8e0b9aad333c1ad9a3b60e129113fdcb47a1972814047b2dcbde5a4
7
+ data.tar.gz: 50980ce8de4b57538d603cb7a2bac720abed0d0d7cf1cff8e86bdf4b06b31f55f85c0a9963e39654a8ab7a05c70254d467aad4bc492a17f4dba06b94725d3939
@@ -19,9 +19,14 @@ module LoggerPipe
19
19
  def initialize(logger, cmd, options = {})
20
20
  @logger, @cmd = logger, cmd
21
21
  @timeout = options[:timeout]
22
+ @dry_run = options[:dry_run]
22
23
  end
23
24
 
24
25
  def execute
26
+ if @dry_run
27
+ logger.info("dry run: #{cmd}")
28
+ return nil
29
+ end
25
30
  logger.info("executing: #{cmd}")
26
31
  buf = []
27
32
  # systemをタイムアウトさせることはできないので、popenの戻り値を使っています。
@@ -1,3 +1,3 @@
1
1
  module LoggerPipe
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,7 +7,7 @@ require 'timeout'
7
7
 
8
8
  describe LoggerPipe do
9
9
  it 'should have a version number' do
10
- LoggerPipe::VERSION.should_not be_nil
10
+ expect(LoggerPipe::VERSION).to_not be_nil
11
11
  end
12
12
 
13
13
  let(:buffer){ StringIO.new }
@@ -20,20 +20,35 @@ describe LoggerPipe do
20
20
  let(:cmd){ "date +'Foo: %Y-%m-%dT%H:%M:%S'; sleep 1; date +'Bar: %Y-%m-%dT%H:%M:%S'" }
21
21
  it "returns STDOUT" do
22
22
  res = LoggerPipe.run(logger, cmd)
23
- res.should_not == ""
24
- res.lines.length.should == 2
25
- res.lines[0].should =~ /Foo: /
26
- res.lines[1].should =~ /Bar: /
23
+ expect(res).to_not eq ""
24
+ expect(res.lines.length).to eq 2
25
+ expect(res.lines[0]).to match /Foo: /
26
+ expect(res.lines[1]).to match /Bar: /
27
27
  end
28
28
 
29
29
  it "logging output" do
30
30
  LoggerPipe.run(logger, cmd)
31
31
  msg = buffer.string
32
- msg.lines.length.should == 4
33
- msg.lines[0].should =~ /executing: #{Regexp.escape(cmd)}/
34
- msg.lines[1].should =~ /Foo: /
35
- msg.lines[2].should =~ /Bar: /
36
- msg.lines[3].should =~ /SUCCESS: #{Regexp.escape(cmd)}/
32
+ expect(msg.lines.length).to eq 4
33
+ expect(msg.lines[0]).to match /executing: #{Regexp.escape(cmd)}/
34
+ expect(msg.lines[1]).to match /Foo: /
35
+ expect(msg.lines[2]).to match /Bar: /
36
+ expect(msg.lines[3]).to match /SUCCESS: #{Regexp.escape(cmd)}/
37
+ end
38
+ end
39
+
40
+ context "dry_run: true" do
41
+ let(:cmd){ "date +'Foo: %Y-%m-%dT%H:%M:%S'; sleep 1; date +'Bar: %Y-%m-%dT%H:%M:%S'" }
42
+ it "returns nil" do
43
+ res = LoggerPipe.run(logger, cmd, dry_run: true)
44
+ expect(res).to eq nil
45
+ end
46
+
47
+ it "logging output" do
48
+ LoggerPipe.run(logger, cmd, dry_run: true)
49
+ msg = buffer.string
50
+ expect(msg.lines.length).to eq 1
51
+ expect(msg.lines[0]).to match /dry run: #{Regexp.escape(cmd)}/
37
52
  end
38
53
  end
39
54
 
@@ -47,10 +62,10 @@ describe LoggerPipe do
47
62
  it "failure" do
48
63
  LoggerPipe.run(logger, cmd) rescue nil
49
64
  msg = buffer.string
50
- msg.lines.length.should == 3
51
- msg.lines[0].should =~ /executing: #{Regexp.escape(cmd)}/
52
- msg.lines[1].should =~ /Foo: /
53
- msg.lines[2].should =~ /FAILURE: date \+'Foo: /
65
+ expect(msg.lines.length).to eq 3
66
+ expect(msg.lines[0]).to match /executing: #{Regexp.escape(cmd)}/
67
+ expect(msg.lines[1]).to match /Foo: /
68
+ expect(msg.lines[2]).to match /FAILURE: date \+'Foo: /
54
69
  end
55
70
 
56
71
  it "returns buffer from LoggerPipe::Failure" do
@@ -75,10 +90,10 @@ describe LoggerPipe do
75
90
  it "failure" do
76
91
  LoggerPipe.run(logger, cmd, timeout: 3) rescue nil
77
92
  msg = buffer.string
78
- msg.lines[0].should =~ /executing: #{Regexp.escape(cmd)}/
79
- msg.lines[1].should =~ /Foo: /
80
- msg.lines[2].should =~ /now killing process/
81
- msg.lines.any?{|line| line =~ /EXECUTION Timeout/}.should == true
93
+ expect(msg.lines[0]).to match /executing: #{Regexp.escape(cmd)}/
94
+ expect(msg.lines[1]).to match /Foo: /
95
+ expect(msg.lines[2]).to match /now killing process/
96
+ expect(msg.lines.any?{|line| line =~ /EXECUTION Timeout/}).to eq true
82
97
  end
83
98
  end
84
99
 
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger_pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: logger_pipe helps to connect child process STDOUT to Logger on realtime
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
64
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -82,21 +82,20 @@ require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.4.5
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: logger_pipe helps to connect child process STDOUT to Logger on realtime
99
99
  test_files:
100
100
  - spec/logger_pipe_spec.rb
101
101
  - spec/spec_helper.rb
102
- has_rdoc: