diff --git a/test/lib/fluentd_ui_test.rb b/test/lib/fluentd_ui_test.rb new file mode 100644 index 0000000..6ab7b23 --- /dev/null +++ b/test/lib/fluentd_ui_test.rb @@ -0,0 +1,36 @@ +require "test_helper" + +class FluentdUITest < ActiveSupport::TestCase + sub_test_case ".update_available?" do + setup do + @current_version = FluentdUI::VERSION + end + + test "unavailable" do + FluentdUI.latest_version = @current_version + assert do + !FluentdUI.update_available? + end + end + + test "available" do + FluentdUI.latest_version = @current_version.succ + assert do + FluentdUI.update_available? + end + end + end + + sub_test_case ".fluentd_version" do + test "not ready" do + stub(Fluentd).instance { nil } + assert_nil(FluentdUI.fluentd_version) + end + + test "ready" do + target = FactoryBot.build(:fluentd) + stub(Fluentd).instance{ target } + assert_equal(target.agent.version, FluentdUI.fluentd_version) + end + end +end diff --git a/test/lib/regexp_preview/multi_line_test.rb b/test/lib/regexp_preview/multi_line_test.rb new file mode 100644 index 0000000..8b546ea --- /dev/null +++ b/test/lib/regexp_preview/multi_line_test.rb @@ -0,0 +1,86 @@ +require "test_helper" + +module RegexpPreview + class MultilineTest < ActiveSupport::TestCase + test "simple usage" do + config = { + "format_firstline" => "/foo/", + "time_format" => "time_format", + } + config["format1"] = "/(?foo)\n/" + config["format2"] = "/(?bar)/" + 3.upto(Fluentd::Setting::InTail::MULTI_LINE_MAX_FORMAT_COUNT) do |i| + config["format#{i}"] = "//" + end + preview = RegexpPreview::MultiLine.new(fixture_path("error0.log"), "multiline", config) + matches = [ + { + whole: "foo\nbar\nbaz\n1\n2\n3\n4\n5\n6\n10\n11\n12", + matches: [ + { key: "foo", matched: "foo", pos: [0, 3] }, + { key: "bar", matched: "bar", pos: [4, 7] } + ] + } + ] + assert_equal(matches, preview.matches[:matches]) + end + + test "detect only continuous patterns" do + config = { + "format_firstline" => "/foo/", + "time_format" => "time_format", + } + config["format1"] = "/(?foo)\n/" + config["format2"] = "/(?baz)/" + 3.upto(Fluentd::Setting::InTail::MULTI_LINE_MAX_FORMAT_COUNT) do |i| + config["format#{i}"] = "//" + end + preview = RegexpPreview::MultiLine.new(fixture_path("error0.log"), "multiline", config) + assert_equal([], preview.matches[:matches]) + end + + # http://docs.fluentd.org/articles/in_tail + test "example on document" do + config = { + "format_firstline" => "/\\d{4}-\\d{1,2}-\\d{1,2}/", + "format1" => "/^(?