tangled
alpha
login
or
join now
seoul.systems
/
microcosm-rs
forked from
microcosm.blue/microcosm-rs
0
fork
atom
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
0
fork
atom
overview
issues
pulls
pipelines
Add tests for new get_many_to_many query handler
seoul.systems
1 month ago
f3144f8d
45e798b8
+212
1 changed file
expand all
collapse all
unified
split
constellation
src
storage
mod.rs
+212
constellation/src/storage/mod.rs
reviewed
···
1683
1683
}
1684
1684
);
1685
1685
});
1686
1686
+
1687
1687
+
test_each_storage!(get_m2m_empty, |storage| {
1688
1688
+
assert_eq!(
1689
1689
+
storage.get_many_to_many(
1690
1690
+
"a.com",
1691
1691
+
"a.b.c",
1692
1692
+
".d.e",
1693
1693
+
".f.g",
1694
1694
+
10,
1695
1695
+
None,
1696
1696
+
&HashSet::new(),
1697
1697
+
&HashSet::new(),
1698
1698
+
)?,
1699
1699
+
PagedOrderedCollection {
1700
1700
+
items: vec![],
1701
1701
+
next: None,
1702
1702
+
}
1703
1703
+
);
1704
1704
+
});
1705
1705
+
1706
1706
+
test_each_storage!(get_m2m_single, |storage| {
1707
1707
+
storage.push(
1708
1708
+
&ActionableEvent::CreateLinks {
1709
1709
+
record_id: RecordId {
1710
1710
+
did: "did:plc:asdf".into(),
1711
1711
+
collection: "app.t.c".into(),
1712
1712
+
rkey: "asdf".into(),
1713
1713
+
},
1714
1714
+
links: vec![
1715
1715
+
CollectedLink {
1716
1716
+
target: Link::Uri("a.com".into()),
1717
1717
+
path: ".abc.uri".into(),
1718
1718
+
},
1719
1719
+
CollectedLink {
1720
1720
+
target: Link::Uri("b.com".into()),
1721
1721
+
path: ".def.uri".into(),
1722
1722
+
},
1723
1723
+
CollectedLink {
1724
1724
+
target: Link::Uri("b.com".into()),
1725
1725
+
path: ".ghi.uri".into(),
1726
1726
+
},
1727
1727
+
],
1728
1728
+
},
1729
1729
+
0,
1730
1730
+
)?;
1731
1731
+
assert_eq!(
1732
1732
+
storage.get_many_to_many(
1733
1733
+
"a.com",
1734
1734
+
"app.t.c",
1735
1735
+
".abc.uri",
1736
1736
+
".def.uri",
1737
1737
+
10,
1738
1738
+
None,
1739
1739
+
&HashSet::new(),
1740
1740
+
&HashSet::new(),
1741
1741
+
)?,
1742
1742
+
PagedOrderedCollection {
1743
1743
+
items: vec![(
1744
1744
+
"b.com".to_string(),
1745
1745
+
vec![RecordId {
1746
1746
+
did: "did:plc:asdf".into(),
1747
1747
+
collection: "app.t.c".into(),
1748
1748
+
rkey: "asdf".into(),
1749
1749
+
}]
1750
1750
+
)],
1751
1751
+
next: None,
1752
1752
+
}
1753
1753
+
);
1754
1754
+
});
1755
1755
+
1756
1756
+
test_each_storage!(get_m2m_filters, |storage| {
1757
1757
+
storage.push(
1758
1758
+
&ActionableEvent::CreateLinks {
1759
1759
+
record_id: RecordId {
1760
1760
+
did: "did:plc:asdf".into(),
1761
1761
+
collection: "app.t.c".into(),
1762
1762
+
rkey: "asdf".into(),
1763
1763
+
},
1764
1764
+
links: vec![
1765
1765
+
CollectedLink {
1766
1766
+
target: Link::Uri("a.com".into()),
1767
1767
+
path: ".abc.uri".into(),
1768
1768
+
},
1769
1769
+
CollectedLink {
1770
1770
+
target: Link::Uri("b.com".into()),
1771
1771
+
path: ".def.uri".into(),
1772
1772
+
},
1773
1773
+
],
1774
1774
+
},
1775
1775
+
0,
1776
1776
+
)?;
1777
1777
+
storage.push(
1778
1778
+
&ActionableEvent::CreateLinks {
1779
1779
+
record_id: RecordId {
1780
1780
+
did: "did:plc:asdf".into(),
1781
1781
+
collection: "app.t.c".into(),
1782
1782
+
rkey: "asdf2".into(),
1783
1783
+
},
1784
1784
+
links: vec![
1785
1785
+
CollectedLink {
1786
1786
+
target: Link::Uri("a.com".into()),
1787
1787
+
path: ".abc.uri".into(),
1788
1788
+
},
1789
1789
+
CollectedLink {
1790
1790
+
target: Link::Uri("b.com".into()),
1791
1791
+
path: ".def.uri".into(),
1792
1792
+
},
1793
1793
+
],
1794
1794
+
},
1795
1795
+
1,
1796
1796
+
)?;
1797
1797
+
storage.push(
1798
1798
+
&ActionableEvent::CreateLinks {
1799
1799
+
record_id: RecordId {
1800
1800
+
did: "did:plc:fdsa".into(),
1801
1801
+
collection: "app.t.c".into(),
1802
1802
+
rkey: "fdsa".into(),
1803
1803
+
},
1804
1804
+
links: vec![
1805
1805
+
CollectedLink {
1806
1806
+
target: Link::Uri("a.com".into()),
1807
1807
+
path: ".abc.uri".into(),
1808
1808
+
},
1809
1809
+
CollectedLink {
1810
1810
+
target: Link::Uri("c.com".into()),
1811
1811
+
path: ".def.uri".into(),
1812
1812
+
},
1813
1813
+
],
1814
1814
+
},
1815
1815
+
2,
1816
1816
+
)?;
1817
1817
+
storage.push(
1818
1818
+
&ActionableEvent::CreateLinks {
1819
1819
+
record_id: RecordId {
1820
1820
+
did: "did:plc:fdsa".into(),
1821
1821
+
collection: "app.t.c".into(),
1822
1822
+
rkey: "fdsa2".into(),
1823
1823
+
},
1824
1824
+
links: vec![
1825
1825
+
CollectedLink {
1826
1826
+
target: Link::Uri("a.com".into()),
1827
1827
+
path: ".abc.uri".into(),
1828
1828
+
},
1829
1829
+
CollectedLink {
1830
1830
+
target: Link::Uri("c.com".into()),
1831
1831
+
path: ".def.uri".into(),
1832
1832
+
},
1833
1833
+
],
1834
1834
+
},
1835
1835
+
3,
1836
1836
+
)?;
1837
1837
+
1838
1838
+
// Test without filters - should get all records grouped by secondary target
1839
1839
+
let result = storage.get_many_to_many(
1840
1840
+
"a.com",
1841
1841
+
"app.t.c",
1842
1842
+
".abc.uri",
1843
1843
+
".def.uri",
1844
1844
+
10,
1845
1845
+
None,
1846
1846
+
&HashSet::new(),
1847
1847
+
&HashSet::new(),
1848
1848
+
)?;
1849
1849
+
assert_eq!(result.items.len(), 2);
1850
1850
+
assert_eq!(result.next, None);
1851
1851
+
// Find b.com group
1852
1852
+
let (b_target, b_records) = result.items.iter().find(|(target, _)| target == "b.com").unwrap();
1853
1853
+
assert_eq!(b_target, "b.com");
1854
1854
+
assert_eq!(b_records.len(), 2);
1855
1855
+
assert!(b_records.iter().any(|r| r.did.0 == "did:plc:asdf" && r.rkey == "asdf"));
1856
1856
+
assert!(b_records.iter().any(|r| r.did.0 == "did:plc:asdf" && r.rkey == "asdf2"));
1857
1857
+
// Find c.com group
1858
1858
+
let (c_target, c_records) = result.items.iter().find(|(target, _)| target == "c.com").unwrap();
1859
1859
+
assert_eq!(c_target, "c.com");
1860
1860
+
assert_eq!(c_records.len(), 2);
1861
1861
+
assert!(c_records.iter().any(|r| r.did.0 == "did:plc:fdsa" && r.rkey == "fdsa"));
1862
1862
+
assert!(c_records.iter().any(|r| r.did.0 == "did:plc:fdsa" && r.rkey == "fdsa2"));
1863
1863
+
1864
1864
+
// Test with DID filter - should only get records from did:plc:fdsa
1865
1865
+
let result = storage.get_many_to_many(
1866
1866
+
"a.com",
1867
1867
+
"app.t.c",
1868
1868
+
".abc.uri",
1869
1869
+
".def.uri",
1870
1870
+
10,
1871
1871
+
None,
1872
1872
+
&HashSet::from_iter([Did("did:plc:fdsa".to_string())]),
1873
1873
+
&HashSet::new(),
1874
1874
+
)?;
1875
1875
+
assert_eq!(result.items.len(), 1);
1876
1876
+
let (target, records) = &result.items[0];
1877
1877
+
assert_eq!(target, "c.com");
1878
1878
+
assert_eq!(records.len(), 2);
1879
1879
+
assert!(records.iter().all(|r| r.did.0 == "did:plc:fdsa"));
1880
1880
+
1881
1881
+
// Test with target filter - should only get records linking to b.com
1882
1882
+
let result = storage.get_many_to_many(
1883
1883
+
"a.com",
1884
1884
+
"app.t.c",
1885
1885
+
".abc.uri",
1886
1886
+
".def.uri",
1887
1887
+
10,
1888
1888
+
None,
1889
1889
+
&HashSet::new(),
1890
1890
+
&HashSet::from_iter(["b.com".to_string()]),
1891
1891
+
)?;
1892
1892
+
assert_eq!(result.items.len(), 1);
1893
1893
+
let (target, records) = &result.items[0];
1894
1894
+
assert_eq!(target, "b.com");
1895
1895
+
assert_eq!(records.len(), 2);
1896
1896
+
assert!(records.iter().all(|r| r.did.0 == "did:plc:asdf"));
1897
1897
+
});
1686
1898
}