fluentd-ui/test/models/fluentd/setting/out_tdlog_test.rb
Kenji Okimoto 5b882568f7
Add test/models/fluentd/setting/*_test.rb
Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2018-08-02 14:10:46 +09:00

61 lines
1.4 KiB
Ruby

require "test_helper"
require "fluent/plugin/buf_file"
module Fluentd::Setting
class OutTdlogTest < ActiveSupport::TestCase
setup do
@klass = Fluentd::Setting::OutTdlog
@valid_attributes = {
pattern: "td.*.*",
apikey: "APIKEY",
auto_create_table: "true",
buffer: {
"0" => {
type: "file",
path: "/tmp/buffer"
}
}
}
@instance = @klass.new(@valid_attributes)
end
sub_test_case "#valid?" do
test "valid" do
assert do
@instance.valid?
end
end
test "invalid if apikey is missing" do
params = @valid_attributes.dup
params.delete(:apikey)
instance = @klass.new(params)
assert_false(instance.valid?)
assert_equal(["'apikey' parameter is required"], instance.errors.full_messages)
end
end
test "#plugin_name" do
assert_equal("tdlog", @instance.plugin_name)
end
test "#plugin_type" do
assert_equal("output", @instance.plugin_type)
end
test "#to_config" do
expected = <<-CONFIG.strip_heredoc
<match td.*.*>
@type tdlog
apikey APIKEY
<buffer>
@type file
path /tmp/buffer
</buffer>
</match>
CONFIG
assert_equal(expected, @instance.to_config.to_s)
end
end
end