Skip to content

Commit

Permalink
Merge pull request #3426 from kenhys/generate-storage
Browse files Browse the repository at this point in the history
Support to generate storage plugin template
  • Loading branch information
ashie committed Jul 2, 2021
2 parents da162e1 + b74be97 commit 91b12e8
Show file tree
Hide file tree
Showing 5 changed files with 91 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
40 changes: 40 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,40 @@
<%= preamble %>

require "fluent/plugin/storage"

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

def initialize
super
end

def configure(conf)
super
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 91b12e8

Please sign in to comment.