test/plugin/base_test.rb
# The caller can optionally provide a block which is called for each entry.
The caller can optionally provide a block which is called for each entry.
The caller can optionally provide a block which is called for each entry .
def verify_json_log_entries(n, params, payload_type = 'textPayload',
                              check_exact_entry_labels = true)
    entry_count = 0
    @logs_sent.each do |request|
      request['entries'].each do |entry|
        unless payload_type.empty?
          assert entry.key?(payload_type),
                 "Entry ##{entry_count} did not contain expected" \
                 " #{payload_type} key: #{entry}."
        end
        resource = entry['resource'] || request['resource']
        log_name = entry['logName'] || request['logName']
        labels ||= request['labels']
        labels.merge!(entry['labels'] || {})
        if params[:log_name]
          assert_equal \
            "projects/#{params[:project_id]}/logs/#{params[:log_name]}",
            log_name
        end
        assert_equal params[:resource][:type], resource['type']
        check_labels params[:resource][:labels], resource['labels']
        check_labels params[:labels], labels, check_exact_entry_labels
        if block_given?
          yield(entry, entry_count)
        elsif payload_type == 'textPayload'
          verify_default_log_entry_text(entry['textPayload'], entry_count,
                                        entry)
        end
        entry_count += 1
        assert entry_count <= n,
               "Number of entries #{entry_count} exceeds expected number #{n}."
      end
    end
    assert_equal n, entry_count
  end
def verify_json_log_entries ( n , params , payload_type = 'textPayload' , check_exact_entry_labels = true ) entry_count = 0 @logs_sent . each do | request | request [ 'entries' ] . each do | entry | unless payload_type . empty? assert entry . key? ( payload_type ) , "Entry ##{entry_count} did not contain expected" " #{payload_type} key: #{entry}." end resource = entry [ 'resource' ] || request [ 'resource' ] log_name = entry [ 'logName' ] || request [ 'logName' ] labels ||= request [ 'labels' ] labels . merge! ( entry [ 'labels' ] || { } ) if params [ :log_name ] assert_equal "projects/#{params[:project_id]}/logs/#{params[:log_name]}" , log_name end assert_equal params [ :resource ] [ :type ] , resource [ 'type' ] check_labels params [ :resource ] [ :labels ] , resource [ 'labels' ] check_labels params [ :labels ] , labels , check_exact_entry_labels if block_given? yield ( entry , entry_count ) elsif payload_type == 'textPayload' verify_default_log_entry_text ( entry [ 'textPayload' ] , entry_count , entry ) end entry_count += 1 assert entry_count <= n , "Number of entries #{entry_count} exceeds expected number #{n}." end end assert_equal n , entry_count end
The caller can optionally provide a block which is called for each entry.
The caller can optionally provide a block which is called for each entry .
# per-entry resource or log_name overrides the corresponding field # from the request.  Labels are merged, with the per-entry label # taking precedence in case of overlap. # Check the payload for textPayload, otherwise it's up to the caller.
n
<not_specific>
params
<not_specific>
payload_type
<not_specific>
check_exact_entry_labels
<not_specific>