fluent-format 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 885cab275f6fb1fd2c3985502fe7c4af090e04f3
4
- data.tar.gz: 7bed0b502af72155bec463042b4c76897478cc93
3
+ metadata.gz: 60872a23fdf2060c3e94c301c8b6f5e1e3eb3a66
4
+ data.tar.gz: 155f128a5bd00841a294aa2beeb4b3f6718d96ca
5
5
  SHA512:
6
- metadata.gz: 97d236a5c5afa4a85d568856f254f35c991e0def0721651e776ed543c8492ea9e84921dc03ce006ff10556d5c169311e7e6ce49c3354743960dda61cd07e975d
7
- data.tar.gz: abf9334f02803e4a628711c6fb639f2d0470720c519be167e87c830a908f806ed8b5feefbbae84d2ad042bdbd553552e033c09f4faa0fc09db72880f545d49c8
6
+ metadata.gz: d852f71daed2299560ba8b8bbbdce60eb2ec6d09d27d15fcc455390b79cbf6bc89fb422dc418169e0778ec21a1d6219c4a05f083340fdf610bb813d751230258
7
+ data.tar.gz: f0c342aebc5a321dd7e59196200a91b5b0a19cee46d4cadb551c91ce01f8f99fdde936b0480e46e17e3c1fc40b49ea2abf0c950090f5601ed22f8fd95a925261
@@ -1,3 +1,9 @@
1
+ ## 0.2.1 (2014/02/05)
2
+
3
+ Enhancement:
4
+
5
+ * Add tests
6
+
1
7
  ## 0.2.0 (2014/02/05)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -38,10 +38,6 @@ File.open(path) {|config|
38
38
  }
39
39
  ```
40
40
 
41
- ## ToDo
42
-
43
- 1. write tests
44
-
45
41
  ## Contributing
46
42
 
47
43
  1. Fork it
@@ -26,7 +26,9 @@ module Fluent
26
26
 
27
27
  # Check config file
28
28
  #
29
- # @return [Boolean]
29
+ # @raise Fluent::ConfigParseError if conf has syntax errors
30
+ # @raise Fluent::ConfigError if plugin raises config error
31
+ # @return true if success
30
32
  def run
31
33
  Fluent::Supervisor.new(@opts).ext_dry_run
32
34
  end
@@ -37,6 +39,10 @@ end
37
39
  module Fluent
38
40
  class Supervisor
39
41
  # Extended to accept IO object
42
+ #
43
+ # @raise Fluent::ConfigParseError if conf has syntax errors
44
+ # @raise Fluent::ConfigError if plugin raises config error
45
+ # @return true if success
40
46
  def ext_dry_run
41
47
  ext_read_config
42
48
  change_privilege
@@ -44,8 +50,6 @@ module Fluent
44
50
  install_main_process_signal_handlers
45
51
  run_configure
46
52
  true
47
- rescue => e
48
- false
49
53
  end
50
54
 
51
55
  # Extended to accept IO object
@@ -53,7 +57,6 @@ module Fluent
53
57
  if @config_path.respond_to?(:read) # IO object
54
58
  @config_data = @config_path.read
55
59
  else
56
- $log.info "reading config file", :path=>@config_path
57
60
  @config_fname = File.basename(@config_path)
58
61
  @config_basedir = File.dirname(@config_path)
59
62
  @config_data = File.read(@config_path)
@@ -9,7 +9,7 @@ module Fluent
9
9
  option :config, :aliases => ["-c"], :type => :string, :default => 'fluent.conf', :desc => 'Fluentd configuration file'
10
10
  def format
11
11
  config = @options[:config]
12
- puts Fluent::Format.format(config)
12
+ taputs Fluent::Format.format(config)
13
13
  rescue => e
14
14
  $log.error "#{e.class}: #{e}"
15
15
  exit 1
@@ -21,11 +21,18 @@ module Fluent
21
21
  def check
22
22
  config = @options[:config]
23
23
  plugin = @options[:plugin]
24
- Fluent::Format.check(config, plugin) || exit(1)
24
+ Fluent::Format.check(config, plugin)
25
25
  rescue => e
26
26
  $log.error "#{e.class}: #{e}"
27
27
  exit 1
28
28
  end
29
+
30
+ private
31
+
32
+ def taputs(str)
33
+ puts str
34
+ str
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -10,6 +10,7 @@ module Fluent
10
10
 
11
11
  # Format config
12
12
  #
13
+ # @raise Fluent::ConfigParseError if conf has syntax errors
13
14
  # @return [String] the formatted config
14
15
  def run
15
16
  config = read_config(@config_dev)
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  class Format
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fluent::Format::Check do
4
+ let(:subject) { Fluent::Format.check(config) }
5
+
6
+ context "valid" do
7
+ let(:config) { StringIO.new(%[<match>\ntype stdout\n</match>]) }
8
+ it { should be_true }
9
+ end
10
+
11
+ context "syntax error" do
12
+ let(:config) { StringIO.new(%[<source>\ntype stdout\n</match>]) }
13
+ it { expect { subject }.to raise_error(Fluent::ConfigParseError) }
14
+ end
15
+
16
+ context "plugin error" do
17
+ let(:config) { StringIO.new(%[<match>\ntype foobar\n</match>]) }
18
+ it { expect { subject }.to raise_error(Fluent::ConfigError) }
19
+ end
20
+ end
21
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'fluent/format/cli'
3
+
4
+ describe Fluent::Format::CLI do
5
+ let(:cli) { Fluent::Format::CLI.new }
6
+
7
+ context "#format" do
8
+ let(:subject) { cli.invoke(:format, [], opts) }
9
+
10
+ context "success" do
11
+ let(:opts) { {config: "fluent.conf"} }
12
+ it { expect { subject }.not_to raise_error }
13
+ end
14
+
15
+ context "failure" do
16
+ let(:opts) { {config: "unknown.conf"} }
17
+ it { expect { subject }.to raise_error(SystemExit) }
18
+ end
19
+ end
20
+
21
+ context "#check" do
22
+ let(:subject) { cli.invoke(:check, [], opts) }
23
+
24
+ context "success" do
25
+ let(:opts) { {config: "fluent.conf"} }
26
+ it { expect { subject }.not_to raise_error }
27
+ end
28
+
29
+ context "failure" do
30
+ let(:opts) { {config: "unknown.conf"} }
31
+ it { expect { subject }.to raise_error(SystemExit) }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fluent::Format::Format do
4
+ let(:subject) { Fluent::Format.format(config) }
5
+
6
+ context "valid" do
7
+ let(:config) { StringIO.new(%[<match>\ntype stdout\n</match>]) }
8
+ it { should == %[<match>\n type stdout\n</match>] }
9
+ end
10
+
11
+ context "syntax error" do
12
+ let(:config) { StringIO.new(%[<source>\ntype stdout\n</match>]) }
13
+ it { expect { subject }.to raise_error(Fluent::ConfigParseError) }
14
+ end
15
+
16
+ context "plugin error is not checked" do
17
+ let(:config) { StringIO.new(%[<match>\ntype foobar\n</match>]) }
18
+ it { should == %[<match>\n type foobar\n</match>] }
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require "bundler/setup"
3
+ require "pry"
4
+ require 'fluent-format'
5
+
6
+ ROOT = File.dirname(__FILE__)
7
+ Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
@@ -121,6 +121,10 @@ files:
121
121
  - lib/fluent/format/cli.rb
122
122
  - lib/fluent/format/format.rb
123
123
  - lib/fluent/format/version.rb
124
+ - spec/fluent/format/check_spec.rb
125
+ - spec/fluent/format/cli_spec.rb
126
+ - spec/fluent/format/format_spec.rb
127
+ - spec/spec_helper.rb
124
128
  homepage: https://github.com/sonots/fluent-format
125
129
  licenses:
126
130
  - MIT
@@ -145,4 +149,8 @@ rubygems_version: 2.0.3
145
149
  signing_key:
146
150
  specification_version: 4
147
151
  summary: A command line utility to format fluentd configuration beautifully
148
- test_files: []
152
+ test_files:
153
+ - spec/fluent/format/check_spec.rb
154
+ - spec/fluent/format/cli_spec.rb
155
+ - spec/fluent/format/format_spec.rb
156
+ - spec/spec_helper.rb