See “Example Custom Assertion: test-unit.github.io/test-unit/en/Test/Unit/Assertions.html
# File lib/fluent/test/helpers.rb, line 25 def assert_equal_event_time(expected, actual, message = nil) message = build_message(message, "<?> expected but was <?>. ", expected, actual) assert_block(message) do expected.is_a?(Fluent::EventTime) && actual.is_a?(Fluent::EventTime) && expected.sec == actual.sec && expected.nsec == actual.nsec end end
# File lib/fluent/test/helpers.rb, line 87 def capture_log(driver) tmp = driver.instance.log.out driver.instance.log.out = StringIO.new yield return driver.instance.log.out.string ensure driver.instance.log.out = tmp end
# File lib/fluent/test/helpers.rb, line 35 def config_element(name = 'test', argument = '', params = {}, elements = []) Fluent::Config::Element.new(name, argument, params, elements) end
# File lib/fluent/test/helpers.rb, line 39 def event_time(str=nil, format: nil) if str if format Fluent::EventTime.from_time(Time.strptime(str, format)) else Fluent::EventTime.parse(str) end else Fluent::EventTime.now end end
# File lib/fluent/test/helpers.rb, line 74 def msgpack(type) case type when :factory Fluent::MessagePackFactory.factory when :packer Fluent::MessagePackFactory.packer when :unpacker Fluent::MessagePackFactory.unpacker else raise ArgumentError, "unknown msgpack object type '#{type}'" end end
# File lib/fluent/test/helpers.rb, line 58 def time2str(time, localtime: false, format: nil) if format if localtime Time.at(time).strftime(format) else Time.at(time).utc.strftime(format) end else if localtime Time.at(time).iso8601 else Time.at(time).utc.iso8601 end end end
# File lib/fluent/test/helpers.rb, line 51 def with_timezone(tz) oldtz, ENV['TZ'] = ENV['TZ'], tz yield ensure ENV['TZ'] = oldtz end