upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils')
-rw-r--r--test_utils/src/git.rs26
-rw-r--r--test_utils/src/lib.rs2
2 files changed, 26 insertions, 2 deletions
diff --git a/test_utils/src/git.rs b/test_utils/src/git.rs
index db50165..7aa7e84 100644
--- a/test_utils/src/git.rs
+++ b/test_utils/src/git.rs
@@ -5,6 +5,10 @@ use std::{env::current_dir, fs, path::PathBuf};
5 5
6use anyhow::{Context, Result}; 6use anyhow::{Context, Result};
7use git2::{Oid, RepositoryInitOptions, Signature, Time}; 7use git2::{Oid, RepositoryInitOptions, Signature, Time};
8use nostr::nips::nip01::Coordinate;
9use nostr_sdk::{Kind, ToBech32};
10
11use crate::{generate_repo_ref_event, REPOSITORY_KIND};
8 12
9pub struct GitTestRepo { 13pub struct GitTestRepo {
10 pub dir: PathBuf, 14 pub dir: PathBuf,
@@ -13,7 +17,24 @@ pub struct GitTestRepo {
13 17
14impl Default for GitTestRepo { 18impl Default for GitTestRepo {
15 fn default() -> Self { 19 fn default() -> Self {
16 Self::new("main").unwrap() 20 let repo_event = generate_repo_ref_event();
21 let coordinate = Coordinate {
22 kind: Kind::Custom(REPOSITORY_KIND),
23 public_key: repo_event.author(),
24 identifier: repo_event.identifier().unwrap().to_string(),
25 relays: vec![
26 "ws://localhost:8055".to_string(),
27 "ws://localhost:8056".to_string(),
28 ],
29 };
30
31 let repo = Self::new("main").unwrap();
32 let _ = repo
33 .git_repo
34 .config()
35 .unwrap()
36 .set_str("nostr.repo", &coordinate.to_bech32().unwrap());
37 repo
17 } 38 }
18} 39}
19impl GitTestRepo { 40impl GitTestRepo {
@@ -33,6 +54,9 @@ impl GitTestRepo {
33 git_repo, 54 git_repo,
34 }) 55 })
35 } 56 }
57 pub fn without_repo_in_git_config() -> Self {
58 Self::new("main").unwrap()
59 }
36 60
37 pub fn initial_commit(&self) -> Result<Oid> { 61 pub fn initial_commit(&self) -> Result<Oid> {
38 let oid = self.git_repo.index()?.write_tree()?; 62 let oid = self.git_repo.index()?.write_tree()?;
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index 2825eaa..a3ffd70 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -191,7 +191,7 @@ pub fn generate_repo_ref_event() -> nostr::Event {
191 191
192/// enough to fool event_is_patch_set_root 192/// enough to fool event_is_patch_set_root
193pub fn get_pretend_proposal_root_event() -> nostr::Event { 193pub fn get_pretend_proposal_root_event() -> nostr::Event {
194 serde_json::from_str(r#"{"id":"8cb75aa4cda10a3a0f3242dc49d36159d30b3185bf63414cf6ce17f5c14a73b1","pubkey":"f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768","created_at":1714984571,"kind":1617,"tags":[["t","root"]],"content":"","sig":"6c197314b8c4c61da696dff888198333004d1ecc5d7bae2c554857f2f2b0d3ecc09369a5d8ba089c1bf89e3c6f5be40ade873fd698438ef8b303ffc6df35eb3f"}"#).unwrap() 194 serde_json::from_str(r#"{"id":"431e58eb8e1b4e20292d1d5bbe81d5cfb042e1bc165de32eddfdd52245a4cce4","pubkey":"f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768","created_at":1721404213,"kind":1617,"tags":[["a","30617:ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random"],["a","30617:f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768:9ee507fc4357d7ee16a5d8901bedcd103f23c17d-consider-it-random"],["r","9ee507fc4357d7ee16a5d8901bedcd103f23c17d"],["t","cover-letter"],["alt","git patch cover letter: exampletitle"],["t","root"],["e","8cb75aa4cda10a3a0f3242dc49d36159d30b3185bf63414cf6ce17f5c14a73b1","","mention"],["branch-name","feature"],["p","ba882566eff14f3baa976103998c452d27fe95b65a796a6a9f92628bced76fe5"],["p","f53e4bcd7a9cdef049cf6467d638a1321958acd3b71eb09823fd6fadb023d768"]],"content":"From fe973a840fba2a8ab37dd505c154854a69a6505c Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] exampletitle\n\nexampledescription","sig":"37d5b2338bf9fd9d598e6494ae88af9a8dbd52330cfe9d025ee55e35e2f3f55e931ba039d9f7fed8e6fc40206e47619a24f730f8eddc2a07ccfb3988a5005170"}"#).unwrap()
195} 195}
196 196
197/// wrapper for a cli testing tool - currently wraps rexpect and dialoguer 197/// wrapper for a cli testing tool - currently wraps rexpect and dialoguer