Skip to content

Commit 2533a99

Browse files
committed
chore(sinks): Drop the custom SinkContext::default implementation
The `fn SinkContext::new_test` is actually just `SinkContext::default` in disguise, so drop the custom function in favour of the auto-derived implementation.
1 parent 062224b commit 2533a99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+106
-116
lines changed

src/config/sink.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub trait SinkConfig: DynClone + NamedComponent + core::fmt::Debug + Send + Sync
235235

236236
dyn_clone::clone_trait_object!(SinkConfig);
237237

238-
#[derive(Debug, Clone)]
238+
#[derive(Clone, Debug, Default)]
239239
pub struct SinkContext {
240240
pub healthcheck: SinkHealthcheckOptions,
241241
pub globals: GlobalOptions,
@@ -244,16 +244,6 @@ pub struct SinkContext {
244244
}
245245

246246
impl SinkContext {
247-
#[cfg(test)]
248-
pub fn new_test() -> Self {
249-
Self {
250-
healthcheck: SinkHealthcheckOptions::default(),
251-
globals: GlobalOptions::default(),
252-
proxy: ProxyConfig::default(),
253-
schema: schema::Options::default(),
254-
}
255-
}
256-
257247
pub const fn globals(&self) -> &GlobalOptions {
258248
&self.globals
259249
}

src/sinks/amqp/integration_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn amqp_happy_path() {
7272
.await
7373
.unwrap();
7474

75-
let cx = SinkContext::new_test();
75+
let cx = SinkContext::default();
7676
let (sink, healthcheck) = config.build(cx).await.unwrap();
7777
healthcheck.await.expect("Health check failed");
7878

@@ -153,7 +153,7 @@ async fn amqp_round_trip() {
153153
.await
154154
.unwrap();
155155

156-
let cx = SinkContext::new_test();
156+
let cx = SinkContext::default();
157157
let (amqp_sink, healthcheck) = config.build(cx).await.unwrap();
158158
healthcheck.await.expect("Health check failed");
159159

src/sinks/appsignal/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod test {
251251
.expect("config should be valid");
252252
config.endpoint = mock_endpoint.to_string();
253253

254-
let context = SinkContext::new_test();
254+
let context = SinkContext::default();
255255
let (sink, _healthcheck) = config.build(context).await.unwrap();
256256

257257
let event = Event::Log(LogEvent::from("simple message"));

src/sinks/aws_cloudwatch_logs/integration_tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async fn cloudwatch_insert_log_event() {
5151
acknowledgements: Default::default(),
5252
};
5353

54-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
54+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
5555

5656
let timestamp = chrono::Utc::now();
5757

@@ -101,7 +101,7 @@ async fn cloudwatch_insert_log_events_sorted() {
101101
acknowledgements: Default::default(),
102102
};
103103

104-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
104+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
105105

106106
let timestamp = chrono::Utc::now() - Duration::days(1);
107107

@@ -176,7 +176,7 @@ async fn cloudwatch_insert_out_of_range_timestamp() {
176176
acknowledgements: Default::default(),
177177
};
178178

179-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
179+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
180180

181181
let now = chrono::Utc::now();
182182

@@ -255,7 +255,7 @@ async fn cloudwatch_dynamic_group_and_stream_creation() {
255255
acknowledgements: Default::default(),
256256
};
257257

258-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
258+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
259259

260260
let timestamp = chrono::Utc::now();
261261

@@ -310,7 +310,7 @@ async fn cloudwatch_insert_log_event_batched() {
310310
acknowledgements: Default::default(),
311311
};
312312

313-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
313+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
314314

315315
let timestamp = chrono::Utc::now();
316316

@@ -360,7 +360,7 @@ async fn cloudwatch_insert_log_event_partitioned() {
360360
acknowledgements: Default::default(),
361361
};
362362

363-
let (sink, _) = config.build(SinkContext::new_test()).await.unwrap();
363+
let (sink, _) = config.build(SinkContext::default()).await.unwrap();
364364

365365
let timestamp = chrono::Utc::now();
366366

src/sinks/aws_cloudwatch_metrics/integration_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn cloudwatch_metrics_healthcheck() {
3535

3636
#[tokio::test]
3737
async fn cloudwatch_metrics_put_data() {
38-
let cx = SinkContext::new_test();
38+
let cx = SinkContext::default();
3939
let config = config();
4040
let client = config.create_client(&cx.globals.proxy).await.unwrap();
4141
let sink = CloudWatchMetricsSvc::new(config, client).unwrap();
@@ -94,7 +94,7 @@ async fn cloudwatch_metrics_put_data() {
9494

9595
#[tokio::test]
9696
async fn cloudwatch_metrics_namespace_partitioning() {
97-
let cx = SinkContext::new_test();
97+
let cx = SinkContext::default();
9898
let config = config();
9999
let client = config.create_client(&cx.globals.proxy).await.unwrap();
100100
let sink = CloudWatchMetricsSvc::new(config, client).unwrap();

src/sinks/aws_kinesis/firehose/integration_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async fn firehose_put_records() {
6262

6363
let config = KinesisFirehoseSinkConfig { batch, base };
6464

65-
let cx = SinkContext::new_test();
65+
let cx = SinkContext::default();
6666

6767
let (sink, _) = config.build(cx).await.unwrap();
6868

src/sinks/aws_kinesis/firehose/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async fn check_batch_size() {
3939

4040
let config = KinesisFirehoseSinkConfig { batch, base };
4141

42-
let cx = SinkContext::new_test();
42+
let cx = SinkContext::default();
4343
let res = config.build(cx).await;
4444

4545
assert_eq!(
@@ -69,7 +69,7 @@ async fn check_batch_events() {
6969

7070
let config = KinesisFirehoseSinkConfig { batch, base };
7171

72-
let cx = SinkContext::new_test();
72+
let cx = SinkContext::default();
7373
let res = config.build(cx).await;
7474

7575
assert_eq!(

src/sinks/aws_kinesis/streams/integration_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn kinesis_address() -> String {
5252
// base,
5353
// };
5454
//
55-
// let cx = SinkContext::new_test();
55+
// let cx = SinkContext::default();
5656
//
5757
// let sink = config.build(cx).await.unwrap().0;
5858
//
@@ -107,7 +107,7 @@ async fn kinesis_put_records_without_partition_key() {
107107
base,
108108
};
109109

110-
let cx = SinkContext::new_test();
110+
let cx = SinkContext::default();
111111

112112
let sink = config.build(cx).await.unwrap().0;
113113

src/sinks/aws_s3/integration_tests.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn s3_address() -> String {
5151

5252
#[tokio::test]
5353
async fn s3_insert_message_into_with_flat_key_prefix() {
54-
let cx = SinkContext::new_test();
54+
let cx = SinkContext::default();
5555

5656
let bucket = uuid::Uuid::new_v4().to_string();
5757

@@ -85,7 +85,7 @@ async fn s3_insert_message_into_with_flat_key_prefix() {
8585

8686
#[tokio::test]
8787
async fn s3_insert_message_into_with_folder_key_prefix() {
88-
let cx = SinkContext::new_test();
88+
let cx = SinkContext::default();
8989

9090
let bucket = uuid::Uuid::new_v4().to_string();
9191

@@ -119,7 +119,7 @@ async fn s3_insert_message_into_with_folder_key_prefix() {
119119

120120
#[tokio::test]
121121
async fn s3_insert_message_into_with_ssekms_key_id() {
122-
let cx = SinkContext::new_test();
122+
let cx = SinkContext::default();
123123

124124
let bucket = uuid::Uuid::new_v4().to_string();
125125

@@ -156,7 +156,7 @@ async fn s3_insert_message_into_with_ssekms_key_id() {
156156

157157
#[tokio::test]
158158
async fn s3_rotate_files_after_the_buffer_size_is_reached() {
159-
let cx = SinkContext::new_test();
159+
let cx = SinkContext::default();
160160

161161
let bucket = uuid::Uuid::new_v4().to_string();
162162

@@ -213,7 +213,7 @@ async fn s3_gzip() {
213213
// to 1000, and using gzip compression. We test to ensure that all of the keys we end up
214214
// writing represent the sum total of the lines: we expect 3 batches, each of which should
215215
// have 1000 lines.
216-
let cx = SinkContext::new_test();
216+
let cx = SinkContext::default();
217217

218218
let bucket = uuid::Uuid::new_v4().to_string();
219219

@@ -258,7 +258,7 @@ async fn s3_zstd() {
258258
// to 1000, and using zstd compression. We test to ensure that all of the keys we end up
259259
// writing represent the sum total of the lines: we expect 3 batches, each of which should
260260
// have 1000 lines.
261-
let cx = SinkContext::new_test();
261+
let cx = SinkContext::default();
262262

263263
let bucket = uuid::Uuid::new_v4().to_string();
264264

@@ -303,7 +303,7 @@ async fn s3_zstd() {
303303
// https://github.com/localstack/localstack/issues/4166
304304
#[tokio::test]
305305
async fn s3_insert_message_into_object_lock() {
306-
let cx = SinkContext::new_test();
306+
let cx = SinkContext::default();
307307

308308
let bucket = uuid::Uuid::new_v4().to_string();
309309

@@ -357,7 +357,7 @@ async fn s3_insert_message_into_object_lock() {
357357

358358
#[tokio::test]
359359
async fn acknowledges_failures() {
360-
let cx = SinkContext::new_test();
360+
let cx = SinkContext::default();
361361

362362
let bucket = uuid::Uuid::new_v4().to_string();
363363

@@ -408,7 +408,7 @@ async fn s3_healthchecks_invalid_bucket() {
408408

409409
#[tokio::test]
410410
async fn s3_flush_on_exhaustion() {
411-
let cx = SinkContext::new_test();
411+
let cx = SinkContext::default();
412412

413413
let bucket = uuid::Uuid::new_v4().to_string();
414414
create_bucket(&bucket, false).await;

src/sinks/axiom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod integration_tests {
162162
assert!(!token.is_empty(), "$AXIOM_TOKEN required");
163163
let dataset = env::var("AXIOM_DATASET").unwrap();
164164

165-
let cx = SinkContext::new_test();
165+
let cx = SinkContext::default();
166166

167167
let config = AxiomConfig {
168168
url: Some(url.clone()),

src/sinks/azure_monitor_logs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ mod tests {
459459
default_headers: HeaderMap::new(),
460460
};
461461

462-
let context = SinkContext::new_test();
462+
let context = SinkContext::default();
463463
let client =
464464
HttpClient::new(None, &context.proxy).expect("should not fail to create HTTP client");
465465

@@ -617,7 +617,7 @@ mod tests {
617617
"#,
618618
)
619619
.unwrap();
620-
if config.build(SinkContext::new_test()).await.is_ok() {
620+
if config.build(SinkContext::default()).await.is_ok() {
621621
panic!("config.build failed to error");
622622
}
623623
}
@@ -657,7 +657,7 @@ mod tests {
657657
"#,
658658
)
659659
.unwrap();
660-
if config.build(SinkContext::new_test()).await.is_ok() {
660+
if config.build(SinkContext::default()).await.is_ok() {
661661
panic!("config.build failed to error");
662662
}
663663
}

src/sinks/clickhouse/integration_tests.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async fn insert_events() {
6363
)
6464
.await;
6565

66-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
66+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
6767

6868
let (mut input_event, mut receiver) = make_event();
6969
input_event
@@ -114,7 +114,7 @@ async fn skip_unknown_fields() {
114114
.create_table(&table, "host String, timestamp String, message String")
115115
.await;
116116

117-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
117+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
118118

119119
let (mut input_event, mut receiver) = make_event();
120120
input_event.as_mut_log().insert("unknown", "mysteries");
@@ -167,7 +167,7 @@ async fn insert_events_unix_timestamps() {
167167
)
168168
.await;
169169

170-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
170+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
171171

172172
let (mut input_event, _receiver) = make_event();
173173

@@ -235,7 +235,7 @@ timestamp_format = "unix""#,
235235
)
236236
.await;
237237

238-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
238+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
239239

240240
let (mut input_event, _receiver) = make_event();
241241

@@ -298,7 +298,7 @@ async fn no_retry_on_incorrect_data() {
298298
.create_table(&table, "host String, timestamp String")
299299
.await;
300300

301-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
301+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
302302

303303
let (input_event, mut receiver) = make_event();
304304

@@ -340,7 +340,7 @@ async fn no_retry_on_incorrect_data_warp() {
340340
batch,
341341
..Default::default()
342342
};
343-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
343+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
344344

345345
let (input_event, mut receiver) = make_event();
346346

src/sinks/databend/integration_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async fn insert_event_with_cfg(cfg: String, table: String, client: DatabendAPICl
124124
.unwrap();
125125

126126
let (config, _) = load_sink::<DatabendConfig>(&cfg).unwrap();
127-
let (sink, _hc) = config.build(SinkContext::new_test()).await.unwrap();
127+
let (sink, _hc) = config.build(SinkContext::default()).await.unwrap();
128128

129129
let (input_event, mut receiver) = make_event();
130130
run_and_assert_sink_compliance(

src/sinks/elasticsearch/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl ElasticsearchCommon {
238238
#[cfg(test)]
239239
pub async fn parse_single(config: &ElasticsearchConfig) -> crate::Result<Self> {
240240
let mut commons =
241-
Self::parse_many(config, crate::config::SinkContext::new_test().proxy()).await?;
241+
Self::parse_many(config, crate::config::SinkContext::default().proxy()).await?;
242242
assert_eq!(commons.len(), 1);
243243
Ok(commons.remove(0))
244244
}

src/sinks/elasticsearch/integration_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ async fn structures_events_correctly() {
146146
.expect("Config error");
147147
let base_url = common.base_url.clone();
148148

149-
let cx = SinkContext::new_test();
149+
let cx = SinkContext::default();
150150
let (sink, _hc) = config.build(cx.clone()).await.unwrap();
151151

152152
let (batch, mut receiver) = BatchNotifier::new_with_receiver();
@@ -555,7 +555,7 @@ async fn run_insert_tests_with_config(
555555
};
556556
let base_url = common.base_url.clone();
557557

558-
let cx = SinkContext::new_test();
558+
let cx = SinkContext::default();
559559
let (sink, healthcheck) = config
560560
.build(cx.clone())
561561
.await
@@ -639,7 +639,7 @@ async fn run_insert_tests_with_config(
639639
}
640640

641641
async fn run_insert_tests_with_multiple_endpoints(config: &ElasticsearchConfig) {
642-
let cx = SinkContext::new_test();
642+
let cx = SinkContext::default();
643643
let commons = ElasticsearchCommon::parse_many(config, cx.proxy())
644644
.await
645645
.expect("Config error");

src/sinks/gcp/chronicle_unstructured.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ mod integration_tests {
541541
log_type: &str,
542542
auth_path: &str,
543543
) -> crate::Result<(VectorSink, crate::sinks::Healthcheck)> {
544-
let cx = SinkContext::new_test();
544+
let cx = SinkContext::default();
545545
config(log_type, auth_path).build(cx).await
546546
}
547547

0 commit comments

Comments
 (0)