Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
0

Configure Feed

Select the types of activity you want to include in your feed.

tolerable test things

+68 -40
+68 -40
ufos/src/storage_fjall.rs
··· 1128 1128 use jetstream::exports::Cid; 1129 1129 use serde_json::value::RawValue; 1130 1130 1131 - #[test] 1132 - fn test_hello() -> anyhow::Result<()> { 1133 - // let db_path = tempfile::tempdir()?; 1134 - let (_read, mut write, _) = FjallStorage::init( 1135 - tempfile::tempdir()?, 1131 + fn fjall_db() -> (FjallReader, FjallWriter) { 1132 + let (read, write, _) = FjallStorage::init( 1133 + tempfile::tempdir().unwrap(), 1136 1134 "offline test (no real jetstream endpoint)".to_string(), 1137 1135 false, 1138 1136 FjallConfig { temp: true }, 1139 - )?; 1137 + ) 1138 + .unwrap(); 1139 + (read, write) 1140 + } 1140 1141 1141 - write.insert_batch(EventBatch { 1142 - ..Default::default() 1143 - })?; 1142 + #[derive(Debug, Default)] 1143 + struct TestBatch { 1144 + pub batch: EventBatch, 1145 + } 1144 1146 1147 + impl TestBatch { 1148 + pub fn create( 1149 + &mut self, 1150 + did: &str, 1151 + collection: &str, 1152 + rkey: &str, 1153 + record: &str, 1154 + rev: Option<&str>, 1155 + cid: Option<Cid>, 1156 + ) -> Nsid { 1157 + let did = Did::new(did.to_string()).unwrap(); 1158 + let collection = Nsid::new(collection.to_string()).unwrap(); 1159 + let record = RawValue::from_string(record.to_string()).unwrap(); 1160 + let cid = cid.unwrap_or( 1161 + "bafyreidofvwoqvd2cnzbun6dkzgfucxh57tirf3ohhde7lsvh4fu3jehgy" 1162 + .parse() 1163 + .unwrap(), 1164 + ); 1165 + 1166 + let event = CommitEvent { 1167 + collection, 1168 + rkey: RecordKey::new(rkey.to_string()).unwrap(), 1169 + rev: rev.unwrap_or("asdf").to_string(), 1170 + operation: CommitOp::Create, 1171 + record: Some(record), 1172 + cid: Some(cid), 1173 + }; 1174 + 1175 + let (commit, collection) = 1176 + UFOsCommit::from_commit_info(event, did.clone(), Cursor::from_raw_u64(100)) 1177 + .unwrap(); 1178 + 1179 + self.batch 1180 + .commits_by_nsid 1181 + .entry(collection.clone()) 1182 + .or_default() 1183 + .truncating_insert(commit, 1); 1184 + 1185 + collection 1186 + } 1187 + } 1188 + 1189 + #[test] 1190 + fn test_hello() -> anyhow::Result<()> { 1191 + let (_, mut write) = fjall_db(); 1192 + write.insert_batch(EventBatch::default())?; 1145 1193 Ok(()) 1146 1194 } 1147 1195 1148 1196 #[test] 1149 1197 fn test_insert_one() -> anyhow::Result<()> { 1150 - let (read, mut write, _) = FjallStorage::init( 1151 - tempfile::tempdir()?, 1152 - "offline test (no real jetstream endpoint)".to_string(), 1153 - false, 1154 - FjallConfig { temp: true }, 1155 - )?; 1156 - 1157 - let did = Did::new("did:plc:inze6wrmsm7pjl7yta3oig77".to_string()).unwrap(); 1158 - let cid: Cid = "bafyreidofvwoqvd2cnzbun6dkzgfucxh57tirf3ohhde7lsvh4fu3jehgy" 1159 - .parse() 1160 - .unwrap(); 1161 - let event = CommitEvent { 1162 - collection: Nsid::new("a.b.c".to_string()).unwrap(), 1163 - rkey: RecordKey::new("asdf".to_string()).unwrap(), 1164 - rev: "asdf".to_string(), 1165 - operation: CommitOp::Create, 1166 - record: Some(*Box::new(RawValue::from_string("{}".to_string()).unwrap())), 1167 - cid: Some(cid), 1168 - }; 1169 - let (commit, collection) = 1170 - UFOsCommit::from_commit_info(event, did.clone(), Cursor::from_raw_u64(100))?; 1198 + let (read, mut write) = fjall_db(); 1171 1199 1172 - let mut commits = CollectionCommits::default(); 1173 - commits.truncating_insert(commit, 1); 1174 - 1175 - let mut commits_by_nsid = HashMap::new(); 1176 - commits_by_nsid.insert(collection.clone(), commits); 1177 - 1178 - write.insert_batch(EventBatch { 1179 - commits_by_nsid, 1180 - ..Default::default() 1181 - })?; 1200 + let mut batch = TestBatch::default(); 1201 + let collection = batch.create( 1202 + "did:plc:inze6wrmsm7pjl7yta3oig77", 1203 + "a.b.c", 1204 + "asdf", 1205 + "{}", 1206 + Some("rev-z"), 1207 + None, 1208 + ); 1209 + write.insert_batch(batch.batch)?; 1182 1210 1183 1211 let total = read.get_total_by_collection(&collection)?; 1184 1212 assert_eq!(total, 1);