test/plugin/base_test.rb in fluent-plugin-google-cloud-0.6.8 vs test/plugin/base_test.rb in fluent-plugin-google-cloud-0.6.9.pre.1
- old
+ new
@@ -91,10 +91,22 @@
end
assert_equal 1, exception_count, "Index #{index} failed."
end
end
+ def test_configure_partial_success
+ setup_gce_metadata_stubs
+ {
+ APPLICATION_DEFAULT_CONFIG => false,
+ PARTIAL_SUCCESS_CONFIG => true
+ }.each do |(config, partial_success)|
+ d = create_driver(config)
+ assert_equal partial_success,
+ d.instance.instance_variable_get(:@partial_success)
+ end
+ end
+
def test_metadata_loading
setup_gce_metadata_stubs
d = create_driver
d.run
assert_equal PROJECT_ID, d.instance.project_id
@@ -959,10 +971,30 @@
d.run
end
verify_log_entries(1, DATAPROC_PARAMS, 'jsonPayload')
end
+ def test_cloud_ml_log
+ setup_gce_metadata_stubs
+ setup_logging_stubs do
+ d = create_driver(CONFIG_ML, ML_TAG)
+ d.emit(ml_log_entry(0))
+ d.run
+ end
+ verify_log_entries(1, ML_PARAMS)
+ end
+
+ def test_cloud_dataflow_log
+ setup_gce_metadata_stubs
+ setup_logging_stubs do
+ d = create_driver(CONFIG_DATAFLOW, DATAFLOW_TAG)
+ d.emit(dataflow_log_entry(0))
+ d.run
+ end
+ verify_log_entries(1, DATAFLOW_PARAMS)
+ end
+
def test_log_entry_http_request_field_from_record
verify_subfields_from_record(DEFAULT_HTTP_REQUEST_KEY)
end
def test_log_entry_source_location_field_from_record
@@ -1021,15 +1053,15 @@
setup_gce_metadata_stubs
latency_conversion.each do |input, expected|
setup_logging_stubs do
d = create_driver
@logs_sent = []
- d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
+ d.emit('httpRequest' => http_request_message.merge('latency' => input))
d.run
end
verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
- assert_equal HTTP_REQUEST_MESSAGE.merge('latency' => expected),
+ assert_equal http_request_message.merge('latency' => expected),
entry['httpRequest'], entry
assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
end
end
end
@@ -1042,15 +1074,15 @@
' 123 s econds ', '1min', 'abc&^!$*('
].each do |input|
setup_logging_stubs do
d = create_driver
@logs_sent = []
- d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
+ d.emit('httpRequest' => http_request_message.merge('latency' => input))
d.run
end
verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
- assert_equal HTTP_REQUEST_MESSAGE, entry['httpRequest'], entry
+ assert_equal http_request_message, entry['httpRequest'], entry
assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
end
end
end
@@ -1595,12 +1627,26 @@
assert_equal CONTAINER_SEVERITY, entry['severity'], entry
end
end
end
+ def log_entry_subfields_params
+ {
+ # The keys are the names of fields in the payload that we are extracting
+ # LogEntry info from. The values are lists of two elements: the name of
+ # the subfield in LogEntry object and the expected value of that field.
+ DEFAULT_HTTP_REQUEST_KEY => [
+ 'httpRequest', http_request_message],
+ DEFAULT_SOURCE_LOCATION_KEY => [
+ 'sourceLocation', source_location_message],
+ DEFAULT_OPERATION_KEY => [
+ 'operation', OPERATION_MESSAGE]
+ }
+ end
+
def verify_subfields_from_record(payload_key)
- destination_key, payload_value = LOG_ENTRY_SUBFIELDS_PARAMS[payload_key]
+ destination_key, payload_value = log_entry_subfields_params[payload_key]
@logs_sent = []
setup_gce_metadata_stubs
setup_logging_stubs do
d = create_driver
d.emit(payload_key => payload_value)
@@ -1612,11 +1658,11 @@
assert_nil fields[payload_key], entry
end
end
def verify_subfields_partial_from_record(payload_key)
- destination_key, payload_value = LOG_ENTRY_SUBFIELDS_PARAMS[payload_key]
+ destination_key, payload_value = log_entry_subfields_params[payload_key]
@logs_sent = []
setup_gce_metadata_stubs
setup_logging_stubs do
d = create_driver
d.emit(payload_key => payload_value.merge('otherKey' => 'value'))
@@ -1629,11 +1675,11 @@
assert_equal 'value', get_string(request['otherKey']), entry
end
end
def verify_subfields_when_not_hash(payload_key)
- destination_key = LOG_ENTRY_SUBFIELDS_PARAMS[payload_key][0]
+ destination_key = log_entry_subfields_params[payload_key][0]
@logs_sent = []
setup_gce_metadata_stubs
setup_logging_stubs do
d = create_driver
d.emit(payload_key => 'a_string')
@@ -1644,17 +1690,25 @@
assert_equal 'a_string', get_string(field), entry
assert_nil entry[destination_key], entry
end
end
+ def http_request_message
+ HTTP_REQUEST_MESSAGE
+ end
+
+ def source_location_message
+ SOURCE_LOCATION_MESSAGE
+ end
+
# Replace the 'referer' field with nil.
def http_request_message_with_nil_referer
- HTTP_REQUEST_MESSAGE.merge('referer' => nil)
+ http_request_message.merge('referer' => nil)
end
# Unset the 'referer' field.
def http_request_message_with_absent_referer
- HTTP_REQUEST_MESSAGE.reject do |k, _|
+ http_request_message.reject do |k, _|
k == 'referer'
end
end
# The conversions from user input to output.