## 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'require'fluent/test/driver/test_event_router'moduleFluentmoduleTestmoduleDriverclassBaseOwner<Basedefinitialize(klass,opts: {},&block)superifopts@instance.system_config_override(opts)end@instance.log=TestLogger.new@logs=@instance.log.out.logs@event_streams=nil@error_events=nilenddefconfigure(conf,syntax: :v1)ifconf.is_a?(Fluent::Config::Element)@config=confelse@config=Config.parse(conf,"(test)","(test_dir)",syntax: syntax)endif@instance.respond_to?(:router=)@event_streams=[]@error_events=[]driver=selfmojule=Module.newdodefine_method(:event_emitter_router)do|label_name|TestEventRouter.new(driver)endend@instance.singleton_class.prependmojuleend@instance.configure(@config)selfendEmit=Struct.new(:tag,:es)ErrorEvent=Struct.new(:tag,:time,:record,:error)# via TestEventRouterdefemit_event_stream(tag,es)@event_streams<<Emit.new(tag,es)enddefemit_error_event(tag,time,record,error)@error_events<<ErrorEvent.new(tag,time,record,error)enddefevents(tag: nil)ifblock_given?event_streams(tag: tag)do|t,es|es.eachdo|time,record|yieldt,time,recordendendelselist=[]event_streams(tag: tag)do|t,es|es.eachdo|time,record|list<<[t,time,record]endendlistendenddefevent_streams(tag: nil)return[]if@event_streams.nil?selected=@event_streams.select{|e|tag.nil??true:e.tag==tag}ifblock_given?selected.eachdo|e|yielde.tag,e.esendelseselected.map{|e|[e.tag,e.es]}endenddefemit_count@event_streams.sizeenddefrecord_count@event_streams.reduce(0){|a,e|a+e.es.size}enddeferror_events(tag: nil)selected=@error_events.select{|e|tag.nil??true:e.tag==tag}ifblock_given?selected.eachdo|e|yielde.tag,e.time,e.record,e.errorendelseselected.map{|e|[e.tag,e.time,e.record,e.error]}endenddefrun(expect_emits: nil,expect_records: nil,timeout: nil,start: true,shutdown: true,&block)ifexpect_emits@run_post_conditions<<->(){emit_count>=expect_emits}endifexpect_records@run_post_conditions<<->(){record_count>=expect_records}endsuper(timeout: timeout,start: start,shutdown: shutdown,&block)endendendendend