Skip to content

Commit

Permalink
Support to generate storage plugin template
Browse files Browse the repository at this point in the history
E.g.

  $ fluent-plugin-generate storage example

Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
  • Loading branch information
kenhys committed Jul 2, 2021
1 parent da162e1 commit 54258cf
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/fluent/command/plugin_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FluentPluginGenerator
attr_reader :type, :name
attr_reader :license_name

SUPPORTED_TYPES = ["input", "output", "filter", "parser", "formatter"]
SUPPORTED_TYPES = ["input", "output", "filter", "parser", "formatter", "storage"]

def initialize(argv = ARGV)
@argv = argv
Expand Down
30 changes: 30 additions & 0 deletions lib/fluent/test/driver/storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Fluentd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'fluent/test/driver/base_owned'

module Fluent
module Test
module Driver
class Storage < BaseOwned
def initialize(klass, **kwargs, &block)
super
@section_name = "storage"
end
end
end
end
end
50 changes: 50 additions & 0 deletions templates/new_gem/lib/fluent/plugin/storage.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<%= preamble %>

require "fluent/plugin/storage"

module Fluent
module Plugin
class <%= class_name %> < Fluent::Plugin::Storage
Fluent::Plugin.register_storage("<%= plugin_name %>", self)

attr_reader :store

# Set persistent true by default
config_set_default :persistent, true

def initialize
super
@store = {}
end

def configure(conf)
super
end

def multi_workers_ready?
true
end

def load
end

def save
end

def get(key)
end

def fetch(key, defval)
end

def put(key, value)
end

def delete(key)
end

def update(key, &block)
end
end
end
end
18 changes: 18 additions & 0 deletions templates/new_gem/test/plugin/test_storage.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "helper"
require "fluent/plugin/<%= plugin_filename %>"

class <%= class_name %>Test < Test::Unit::TestCase
setup do
Fluent::Test.setup
end

test "failure" do
flunk
end

private

def create_driver(conf)
Fluent::Test::Driver::Storage.new(Fluent::Plugin::<%= class_name %>).configure(conf)
end
end
3 changes: 2 additions & 1 deletion test/command/test_plugin_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def stub_git_process(target)
output: ["output", "out"],
filter: ["filter", "filter"],
parser: ["parser", "parser"],
formatter: ["formatter", "formatter"])
formatter: ["formatter", "formatter"],
storage: ["storage", "storage"])
test "generate plugin" do |(type, part)|
generator = FluentPluginGenerator.new([type, "fake"])
stub_git_process(generator)
Expand Down

0 comments on commit 54258cf

Please sign in to comment.