Skip to content

Commit 5e84f88

Browse files
refactor(tap-agent): use insta for snapshot testing messages (#658)
1 parent 633aaa8 commit 5e84f88

File tree

28 files changed

+318
-186
lines changed

28 files changed

+318
-186
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
image: rust:1.81-bookworm
111111
env:
112112
DATABASE_URL: postgres://postgres@postgres:5432
113+
CI: true
113114
steps:
114115
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
115116
- name: Cache dependencies

Cargo.lock

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ rev = "9fd4beb"
9595
[patch.crates-io.tap_graph]
9696
git = "https://github.com/semiotic-ai/timeline-aggregation-protocol"
9797
rev = "9fd4beb"
98+
99+
# Insta benefits from being compiled in release mode, even as dev dependency
100+
# see https://insta.rs/docs/quickstart
101+
[profile.dev.package]
102+
insta.opt-level = 3
103+
similar.opt-level = 3

crates/tap-agent/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ test-assets = { path = "../test-assets" }
6767
test-log.workspace = true
6868
rstest = "0.24.0"
6969
stdext = "0.3.3"
70+
insta = "1.42.2"

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,7 @@ pub mod tests {
15271527
))
15281528
.unwrap();
15291529
let message = msg_receiver.recv().await.expect("Channel failed");
1530-
assert_eq!(
1531-
message,
1532-
SenderAccountMessage::UpdateAllocationIds(allocation_ids)
1533-
);
1530+
insta::assert_debug_snapshot!(message);
15341531

15351532
// verify if create sender account
15361533
let sender_allocation_id = format!("{}:{}:{}", prefix.clone(), SENDER.1, ALLOCATION_ID_0);
@@ -1541,17 +1538,7 @@ pub mod tests {
15411538
.cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new()))
15421539
.unwrap();
15431540
let message = msg_receiver.recv().await.expect("Channel failed");
1544-
assert_eq!(
1545-
message,
1546-
SenderAccountMessage::UpdateReceiptFees(
1547-
ALLOCATION_ID_0,
1548-
ReceiptFees::UpdateValue(UnaggregatedReceipts {
1549-
value: 0,
1550-
last_id: 0,
1551-
counter: 0,
1552-
})
1553-
)
1554-
);
1541+
insta::assert_debug_snapshot!(message);
15551542

15561543
let actor_ref = ActorRef::<SenderAllocationMessage>::where_is(sender_allocation_id.clone());
15571544
assert!(actor_ref.is_some());
@@ -1582,10 +1569,7 @@ pub mod tests {
15821569
.cast(SenderAccountMessage::UpdateAllocationIds(HashSet::new()))
15831570
.unwrap();
15841571
let msg = msg_receiver.recv().await.expect("Channel failed");
1585-
assert_eq!(
1586-
msg,
1587-
SenderAccountMessage::UpdateAllocationIds(HashSet::new())
1588-
);
1572+
insta::assert_debug_snapshot!(msg);
15891573

15901574
let actor_ref = ActorRef::<SenderAllocationMessage>::where_is(sender_allocation_id.clone());
15911575
assert!(actor_ref.is_none());

crates/tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,7 @@ mod tests {
948948
use crate::{
949949
agent::{
950950
sender_account::SenderAccountMessage,
951-
sender_accounts_manager::{
952-
handle_notification, AllocationId, NewReceiptNotification, SenderType,
953-
},
951+
sender_accounts_manager::{handle_notification, NewReceiptNotification, SenderType},
954952
},
955953
test::{
956954
actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor},
@@ -1316,10 +1314,8 @@ mod tests {
13161314
.await
13171315
.unwrap();
13181316

1319-
assert_eq!(
1320-
rx.recv().await.unwrap(),
1321-
SenderAccountMessage::NewAllocationId(AllocationId::Legacy(ALLOCATION_ID_0))
1322-
);
1317+
let new_alloc_msg = rx.recv().await.unwrap();
1318+
insta::assert_debug_snapshot!(new_alloc_msg);
13231319
sender_account.stop_and_wait(None, None).await.unwrap();
13241320
join_handle.await.unwrap();
13251321
}

0 commit comments

Comments
 (0)