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) expected_s = "#{expected}" actual_s = "#{actual}" message = build_message(message, "<?> time expected but was <?>. ", expected_s, actual_s) assert_block(message) do expected.is_a?(Integer) && actual.is_a?(Integer) && expected == actual end end
# File lib/fluent/test/helpers.rb, line 76 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 37 def config_element(name = 'test', argument = '', params = {}, elements = []) Fluent::Config::Element.new(name, argument, params, elements) end
# File lib/fluent/test/helpers.rb, line 41 def event_time(str = nil, format: nil) if str if format Time.strptime(str, format).to_i else Time.parse(str).to_i end else Time.now.to_i end end
# File lib/fluent/test/helpers.rb, line 60 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 53 def with_timezone(tz) oldtz, ENV['TZ'] = ENV['TZ'], tz yield ensure ENV['TZ'] = oldtz end