cli/test: Clean up testing environment
This is a small cleanup to path generation during testing. 1. Separate `rad_home` and `unix_home` to avoid confusion. 2. Remove now unnecessary `trait HasHome`. 3. Move setting `$USER` to the environment. 4. Make paths shorter overall, to fix macOS tests.
This commit is contained in:
parent
3780f908a2
commit
7d6d2e51d8
|
|
@ -8,23 +8,23 @@ $ touch file.bin
|
||||||
$ rad self --did
|
$ rad self --did
|
||||||
did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
|
did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
|
||||||
$ pwd
|
$ pwd
|
||||||
[..]/home/bob/.radicle
|
[..]/bob/.radicle
|
||||||
$ mkdir src
|
$ mkdir src
|
||||||
$ cd src
|
$ cd src
|
||||||
$ pwd
|
$ pwd
|
||||||
[..]/home/bob/.radicle/src
|
[..]/bob/.radicle/src
|
||||||
```
|
```
|
||||||
|
|
||||||
``` ~alice
|
``` ~alice
|
||||||
$ rad self --did
|
$ rad self --did
|
||||||
did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||||
$ pwd
|
$ pwd
|
||||||
[..]/home/alice/.radicle
|
[..]/alice/.radicle
|
||||||
```
|
```
|
||||||
|
|
||||||
``` ~bob
|
``` ~bob
|
||||||
$ pwd
|
$ pwd
|
||||||
[..]/home/bob/.radicle/src
|
[..]/bob/.radicle/src
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from the network, found 2 potential s
|
||||||
✓ Creating checkout in ./heartwood..
|
✓ Creating checkout in ./heartwood..
|
||||||
✓ Remote alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi added
|
✓ Remote alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi added
|
||||||
✓ Remote-tracking branch alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master created for z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
✓ Remote-tracking branch alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master created for z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||||
✓ Repository successfully cloned under [..]/bob/heartwood/
|
✓ Repository successfully cloned under [..]/bob/work/heartwood/
|
||||||
╭────────────────────────────────────╮
|
╭────────────────────────────────────╮
|
||||||
│ heartwood │
|
│ heartwood │
|
||||||
│ Radicle Heartwood Protocol & Stack │
|
│ Radicle Heartwood Protocol & Stack │
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,11 @@ Node not running
|
||||||
SSH not running
|
SSH not running
|
||||||
├╴Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
|
├╴Key (hash) SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
|
||||||
└╴Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
|
└╴Key (full) ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
|
||||||
Home [..]/home/alice/.radicle
|
Home [..]/alice/.radicle
|
||||||
├╴Config [..]/home/alice/.radicle/config.json
|
├╴Config [..]/alice/.radicle/config.json
|
||||||
├╴Storage [..]/home/alice/.radicle/storage
|
├╴Storage [..]/alice/.radicle/storage
|
||||||
├╴Keys [..]/home/alice/.radicle/keys
|
├╴Keys [..]/alice/.radicle/keys
|
||||||
└╴Node [..]/home/alice/.radicle/node
|
└╴Node [..]/alice/.radicle/node
|
||||||
```
|
```
|
||||||
|
|
||||||
If you need to display only your DID, Node ID, or SSH Public Key, you can use
|
If you need to display only your DID, Node ID, or SSH Public Key, you can use
|
||||||
|
|
@ -41,5 +41,5 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad self --home
|
$ rad self --home
|
||||||
[..]/home/alice/.radicle
|
[..]/alice/.radicle
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -82,37 +82,37 @@ impl Default for Environment {
|
||||||
|
|
||||||
impl Environment {
|
impl Environment {
|
||||||
/// Create a new test environment.
|
/// Create a new test environment.
|
||||||
fn named(name: &'static str) -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
tempdir: tempfile::TempDir::with_prefix("radicle-".to_owned() + name).unwrap(),
|
tempdir: tempfile::TempDir::new().unwrap(),
|
||||||
users: 0,
|
users: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new test environment.
|
/// Return the path of the temporary directory at which
|
||||||
pub fn new() -> Self {
|
/// this testing environment is rooted.
|
||||||
Self::named("")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the temp directory path.
|
|
||||||
pub fn tempdir(&self) -> PathBuf {
|
pub fn tempdir(&self) -> PathBuf {
|
||||||
self.tempdir.path().into()
|
self.tempdir.path().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Path to the working directory designated for given alias.
|
/// Return the home directory of the user with the given alias.
|
||||||
pub fn work(&self, has_alias: &impl HasAlias) -> PathBuf {
|
/// This is in analogy to a Unix home directory.
|
||||||
self.tempdir().join("work").join(has_alias.alias().as_ref())
|
pub fn unix_home(&self, has_alias: &impl HasAlias) -> PathBuf {
|
||||||
|
self.tempdir().join(has_alias.alias().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// We don't have `RAD_HOME` or `HOME` to rely on to compute a home as usual.
|
/// Return the Radicle path of the user with the given alias.
|
||||||
pub fn home(&self, alias: &Alias) -> Home {
|
/// This is in analogy to `$RAD_HOME` and always a subdirectory of
|
||||||
Home::new(
|
/// the user's home directory (see [`Environment::unix_home`]).
|
||||||
self.tempdir()
|
pub fn rad_home(&self, has_alias: &impl HasAlias) -> Home {
|
||||||
.join("home")
|
Home::new(self.unix_home(has_alias).join(".radicle")).unwrap()
|
||||||
.join(alias.to_string())
|
}
|
||||||
.join(".radicle"),
|
|
||||||
)
|
/// Path to the working directory of the user with the given alias.
|
||||||
.unwrap()
|
/// Tests that need to act on multiple repositories should crate
|
||||||
|
/// subdirecories within this directory.
|
||||||
|
pub fn work(&self, has_alias: &impl HasAlias) -> PathBuf {
|
||||||
|
self.unix_home(has_alias).join("work")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new default configuration.
|
/// Create a new default configuration.
|
||||||
|
|
@ -135,7 +135,7 @@ impl Environment {
|
||||||
/// is provided.
|
/// is provided.
|
||||||
pub fn profile_with(&mut self, config: profile::Config) -> Profile {
|
pub fn profile_with(&mut self, config: profile::Config) -> Profile {
|
||||||
let alias = config.alias().clone();
|
let alias = config.alias().clone();
|
||||||
let home = self.home(&alias);
|
let home = self.rad_home(&alias);
|
||||||
let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32]));
|
let keypair = KeyPair::from_seed(Seed::from([!(self.users as u8); 32]));
|
||||||
let policies_db = home.node().join(POLICIES_DB_FILE);
|
let policies_db = home.node().join(POLICIES_DB_FILE);
|
||||||
let cobs_db = home.cobs().join(COBS_DB_FILE);
|
let cobs_db = home.cobs().join(COBS_DB_FILE);
|
||||||
|
|
@ -224,7 +224,12 @@ impl Environment {
|
||||||
self.node_with(config::seed(alias))
|
self.node_with(config::seed(alias))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method for placing repository fixture.
|
/// Convenience method for placing repository fixture into the
|
||||||
|
/// directory returned by [`Environment::work`] for the user.
|
||||||
|
/// Use this only in tests that act on *a single repository* only.
|
||||||
|
/// For tests that need to act on multiple repositories,
|
||||||
|
/// create the repositories as subdirectories of the working
|
||||||
|
/// directory returned by [`Environment::work`].
|
||||||
pub fn repository(
|
pub fn repository(
|
||||||
&self,
|
&self,
|
||||||
has_alias: &impl HasAlias,
|
has_alias: &impl HasAlias,
|
||||||
|
|
@ -236,24 +241,17 @@ impl Environment {
|
||||||
pub fn test(
|
pub fn test(
|
||||||
&self,
|
&self,
|
||||||
test_file: &'static str,
|
test_file: &'static str,
|
||||||
subject: &(impl HasAlias + HasHome),
|
subject: &impl HasAlias,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
formula(
|
formula(
|
||||||
self.work(subject).as_ref(),
|
self.work(subject).as_ref(),
|
||||||
PathBuf::from("examples").join(test_file.to_owned() + ".md"),
|
PathBuf::from("examples").join(test_file.to_owned() + ".md"),
|
||||||
)?
|
)?
|
||||||
.env(
|
.env("USER", subject.alias().as_ref())
|
||||||
"RAD_HOME",
|
.env("RAD_HOME", self.rad_home(subject).path().to_string_lossy())
|
||||||
subject.home().path().to_path_buf().to_string_lossy(),
|
|
||||||
)
|
|
||||||
.env(
|
.env(
|
||||||
"JJ_CONFIG",
|
"JJ_CONFIG",
|
||||||
subject
|
self.unix_home(subject)
|
||||||
.home()
|
|
||||||
.path()
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.to_path_buf()
|
|
||||||
.join(".jjconfig.toml")
|
.join(".jjconfig.toml")
|
||||||
.to_string_lossy(),
|
.to_string_lossy(),
|
||||||
)
|
)
|
||||||
|
|
@ -262,10 +260,11 @@ impl Environment {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience method for executing multiple test formulas with standard configuration.
|
||||||
pub fn tests(
|
pub fn tests(
|
||||||
&self,
|
&self,
|
||||||
test_files: impl IntoIterator<Item = &'static str>,
|
test_files: impl IntoIterator<Item = &'static str>,
|
||||||
subject: &(impl HasAlias + HasHome),
|
subject: &impl HasAlias,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
for test_file in test_files {
|
for test_file in test_files {
|
||||||
self.test(test_file, subject)?;
|
self.test(test_file, subject)?;
|
||||||
|
|
@ -288,6 +287,12 @@ pub trait HasAlias {
|
||||||
fn alias(&self) -> &Alias;
|
fn alias(&self) -> &Alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasAlias for Alias {
|
||||||
|
fn alias(&self) -> &Alias {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl HasAlias for Node<MemorySigner> {
|
impl HasAlias for Node<MemorySigner> {
|
||||||
fn alias(&self) -> &Alias {
|
fn alias(&self) -> &Alias {
|
||||||
&self.config.alias
|
&self.config.alias
|
||||||
|
|
@ -305,25 +310,3 @@ impl<G> HasAlias for NodeHandle<G> {
|
||||||
&self.alias
|
&self.alias
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait HasHome {
|
|
||||||
fn home(&self) -> &Home;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasHome for Profile {
|
|
||||||
fn home(&self) -> &Home {
|
|
||||||
&self.home
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasHome for Node<MemorySigner> {
|
|
||||||
fn home(&self) -> &Home {
|
|
||||||
&self.home
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HasHome for NodeHandle<MemorySigner> {
|
|
||||||
fn home(&self) -> &Home {
|
|
||||||
&self.home
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ pub(crate) fn formula(
|
||||||
.env("EDITOR", "true")
|
.env("EDITOR", "true")
|
||||||
.env("TZ", "UTC")
|
.env("TZ", "UTC")
|
||||||
.env("LANG", "C")
|
.env("LANG", "C")
|
||||||
.env("USER", "alice")
|
|
||||||
.env(env::RAD_PASSPHRASE, "radicle")
|
.env(env::RAD_PASSPHRASE, "radicle")
|
||||||
.env(env::RAD_KEYGEN_SEED, RAD_SEED)
|
.env(env::RAD_KEYGEN_SEED, RAD_SEED)
|
||||||
.env(env::RAD_RNG_SEED, "0")
|
.env(env::RAD_RNG_SEED, "0")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue