test/plugin/base_test.rb in fluent-plugin-google-cloud-0.6.20 vs test/plugin/base_test.rb in fluent-plugin-google-cloud-0.6.21
- old
+ new
@@ -722,62 +722,69 @@
adjusted_to_last_year =
one_second_before_next_year.to_datetime.prev_year.to_time
one_second_into_next_year = next_year + 1
one_day_into_next_year = next_year.to_date.next_day.to_time
{
- Time.at(123_456.789) => Time.at(123_456.789),
- Time.at(0) => Time.at(0),
- current_time => current_time,
- one_second_before_next_year => adjusted_to_last_year,
- next_year => Time.at(0),
- one_second_into_next_year => Time.at(0),
- one_day_into_next_year => Time.at(0)
- }.each do |ts, adjusted_ts|
- expected_ts = []
- emit_index = 0
- setup_logging_stubs do
- @logs_sent = []
- d = create_driver
- # Test the "native" fluentd timestamp as well as our nanosecond tags.
- d.emit({ 'message' => log_entry(emit_index) }, ts.to_f)
- expected_ts.push(adjusted_ts)
- emit_index += 1
- d.emit('message' => log_entry(emit_index),
- 'timeNanos' => ts.tv_sec * 1_000_000_000 + ts.tv_nsec)
- expected_ts.push(adjusted_ts)
- emit_index += 1
- d.emit('message' => log_entry(emit_index),
- 'timestamp' => { 'seconds' => ts.tv_sec, 'nanos' => ts.tv_nsec })
- expected_ts.push(adjusted_ts)
- emit_index += 1
- d.emit('message' => log_entry(emit_index),
- 'timestampSeconds' => ts.tv_sec, 'timestampNanos' => ts.tv_nsec)
- expected_ts.push(adjusted_ts)
- emit_index += 1
- d.emit('message' => log_entry(emit_index),
- 'timestampSeconds' => ts.tv_sec.to_s,
- 'timestampNanos' => ts.tv_nsec.to_s)
- expected_ts.push(adjusted_ts)
- emit_index += 1
- d.run
- verify_index = 0
- verify_log_entries(emit_index, COMPUTE_PARAMS) do |entry, i|
- verify_default_log_entry_text(entry['textPayload'], i, entry)
- assert_equal_with_default entry['timestamp']['seconds'],
- expected_ts[verify_index].tv_sec, 0, entry
- assert_equal_with_default \
- entry['timestamp']['nanos'],
- expected_ts[verify_index].tv_nsec, 0, entry do
- # Fluentd v0.14 onwards supports nanosecond timestamp values.
- # Added in 600 ns delta to avoid flaky tests introduced
- # due to rounding error in double-precision floating-point numbers
- # (to account for the missing 9 bits of precision ~ 512 ns).
- # See http://wikipedia.org/wiki/Double-precision_floating-point_format.
- assert_in_delta expected_ts[verify_index].tv_nsec,
- entry['timestamp']['nanos'], 600, entry
+ APPLICATION_DEFAULT_CONFIG => {
+ Time.at(123_456.789) => Time.at(123_456.789),
+ Time.at(0) => Time.at(0),
+ current_time => current_time,
+ one_second_before_next_year => adjusted_to_last_year,
+ next_year => Time.at(0),
+ one_second_into_next_year => Time.at(0),
+ one_day_into_next_year => Time.at(0)
+ },
+ NO_ADJUST_TIMESTAMPS_CONFIG => {
+ Time.at(123_456.789) => Time.at(123_456.789),
+ Time.at(0) => Time.at(0),
+ current_time => current_time,
+ one_second_before_next_year => one_second_before_next_year,
+ next_year => next_year,
+ one_second_into_next_year => one_second_into_next_year,
+ one_day_into_next_year => one_day_into_next_year
+ }
+ }.each do |config, timestamps|
+ timestamps.each do |ts, expected_ts|
+ emit_index = 0
+ setup_logging_stubs do
+ @logs_sent = []
+ d = create_driver(config)
+ # Test the "native" fluentd timestamp as well as our nanosecond tags.
+ d.emit({ 'message' => log_entry(emit_index) }, ts.to_f)
+ emit_index += 1
+ d.emit('message' => log_entry(emit_index),
+ 'timeNanos' => ts.tv_sec * 1_000_000_000 + ts.tv_nsec)
+ emit_index += 1
+ d.emit('message' => log_entry(emit_index),
+ 'timestamp' => { 'seconds' => ts.tv_sec,
+ 'nanos' => ts.tv_nsec })
+ emit_index += 1
+ d.emit('message' => log_entry(emit_index),
+ 'timestampSeconds' => ts.tv_sec,
+ 'timestampNanos' => ts.tv_nsec)
+ emit_index += 1
+ d.emit('message' => log_entry(emit_index),
+ 'timestampSeconds' => ts.tv_sec.to_s,
+ 'timestampNanos' => ts.tv_nsec.to_s)
+ emit_index += 1
+ d.run
+ verify_log_entries(emit_index, COMPUTE_PARAMS) do |entry, i|
+ verify_default_log_entry_text(entry['textPayload'], i, entry)
+ assert_equal_with_default entry['timestamp']['seconds'],
+ expected_ts.tv_sec, 0, entry
+ assert_equal_with_default \
+ entry['timestamp']['nanos'],
+ expected_ts.tv_nsec, 0, entry do
+ # Fluentd v0.14 onwards supports nanosecond timestamp values.
+ # Added in 600 ns delta to avoid flaky tests introduced
+ # due to rounding error in double-precision floating-point numbers
+ # (to account for the missing 9 bits of precision ~ 512 ns).
+ # See http://wikipedia.org/wiki/Double-precision_floating-point_format.
+ assert_in_delta expected_ts.tv_nsec,
+ entry['timestamp']['nanos'], 600, entry
+ end
end
- verify_index += 1
end
end
end
end
@@ -1336,18 +1343,18 @@
{
config: APPLICATION_DEFAULT_CONFIG,
setup_metadata_agent_stub: true,
setup_k8s_stub: true,
log_entry: k8s_container_log_entry(log_entry(0)),
- expected_params: COMPUTE_PARAMS
+ expected_params: K8S_CONTAINER_PARAMS_FROM_LOCAL
},
{
config: APPLICATION_DEFAULT_CONFIG,
setup_metadata_agent_stub: false,
setup_k8s_stub: true,
log_entry: k8s_container_log_entry(log_entry(0)),
- expected_params: COMPUTE_PARAMS
+ expected_params: K8S_CONTAINER_PARAMS_FROM_LOCAL
},
# When enable_metadata_agent is true.
{
config: ENABLE_METADATA_AGENT_CONFIG,
setup_metadata_agent_stub: false,
@@ -1407,10 +1414,10 @@
{
config: APPLICATION_DEFAULT_CONFIG,
setup_metadata_agent_stub: true,
setup_k8s_stub: true,
log_entry: k8s_node_log_entry(log_entry(0)),
- expected_params: COMPUTE_PARAMS
+ expected_params: K8S_NODE_PARAMS_FROM_LOCAL
},
{
config: ENABLE_METADATA_AGENT_CONFIG,
setup_metadata_agent_stub: false,
setup_k8s_stub: true,