Skip to content

Commit

Permalink
tests: write test to making sure that we use local repo everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Apr 15, 2024
1 parent 83d65f4 commit 4528011
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 16 deletions.
5 changes: 5 additions & 0 deletions coffee_core/src/nurse/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ impl Handler for CoffeeRepositoryDirCleanUpStrategy {
coffee: &CoffeeManager,
) -> Result<Option<Defect>, CoffeeError> {
let network = coffee.config.network.clone();
let global_dir = coffee.config.root_path.clone();
let global_dir = format!("{global_dir}/repositories");
if !Path::exists(Path::new(&global_dir)) {
return Ok(None);
}
// Check whether there exists a network-specific repositories folder for each network.
let mut directory_moving = vec![];
let subpath_repo = format!("{}/{network}/repositories", coffee.config.root_path);
Expand Down
2 changes: 1 addition & 1 deletion coffee_lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl PluginLang {
}

/// Plugin struct definition
#[derive(Clone, Serialize, Deserialize, Debug)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct Plugin {
name: String,
/// root path of the plugin
Expand Down
8 changes: 4 additions & 4 deletions coffee_lib/src/plugin_conf.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Coffee configuration serialization file.
use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Eq)]
pub struct Conf {
pub plugin: Plugin,
pub tipping: Option<Tipping>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Eq)]
pub struct Plugin {
pub name: String,
pub version: String,
Expand All @@ -19,12 +19,12 @@ pub struct Plugin {
pub important: Option<bool>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Deprecaterd {
pub reason: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Tipping {
pub bolt12: String,
}
4 changes: 2 additions & 2 deletions coffee_lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ pub mod response {
pub plugins: Vec<Plugin>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct CoffeeRemote {
pub remotes: Option<Vec<CoffeeListRemote>>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct CoffeeListRemote {
pub local_name: String,
pub url: String,
Expand Down
126 changes: 117 additions & 9 deletions tests/src/coffee_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ pub async fn init_coffee_test_cmd() -> anyhow::Result<()> {
let root_path = manager.root_path().to_owned();
manager
.coffee()
.add_remote("folgore", "https://github.com/coffee-tools/folgore.git")
.add_remote(
"folgore",
"https://github.com/coffee-tools/folgore.git",
false,
)
.await
.unwrap();

Expand Down Expand Up @@ -107,7 +111,11 @@ pub async fn init_coffee_test_add_remote() {

manager
.coffee()
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
.add_remote(
"lightningd",
"https://github.com/lightningd/plugins.git",
false,
)
.await
.unwrap();
manager
Expand Down Expand Up @@ -141,7 +149,7 @@ pub async fn test_add_remove_plugins() {
let repo_url = "https://github.com/lightningd/plugins.git";
manager
.coffee()
.add_remote(repo_name, repo_url)
.add_remote(repo_name, repo_url, false)
.await
.unwrap();

Expand Down Expand Up @@ -260,7 +268,7 @@ pub async fn test_errors_and_show() {
let repo_url = "https://github.com/lightningd/plugins.git";
manager
.coffee()
.add_remote(repo_name, repo_url)
.add_remote(repo_name, repo_url, false)
.await
.unwrap();

Expand Down Expand Up @@ -346,7 +354,11 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {
// Add lightningd remote repository
manager
.coffee()
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
.add_remote(
"lightningd",
"https://github.com/lightningd/plugins.git",
false,
)
.await
.unwrap();
// Install summary plugin
Expand Down Expand Up @@ -386,7 +398,11 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {

let result = manager
.coffee()
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
.add_remote(
"lightningd",
"https://github.com/lightningd/plugins.git",
false,
)
.await;
assert!(result.is_err(), "{:?}", result);
// Install summary plugin
Expand Down Expand Up @@ -423,7 +439,7 @@ pub async fn test_double_slash() {
let repo_url = "https://github.com/lightningd/plugins.git";
manager
.coffee()
.add_remote(repo_name, repo_url)
.add_remote(repo_name, repo_url, false)
.await
.unwrap();

Expand Down Expand Up @@ -486,7 +502,11 @@ pub async fn test_plugin_installation_path() {
// Add lightningd remote repository
manager
.coffee()
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
.add_remote(
"lightningd",
"https://github.com/lightningd/plugins.git",
false,
)
.await
.unwrap();

Expand Down Expand Up @@ -604,7 +624,11 @@ pub async fn test_nurse_repository_missing_on_disk() {
// Add folgore remote repository
manager
.coffee()
.add_remote("folgore", "https://github.com/coffee-tools/folgore.git")
.add_remote(
"folgore",
"https://github.com/coffee-tools/folgore.git",
false,
)
.await
.unwrap();

Expand Down Expand Up @@ -700,3 +724,87 @@ pub async fn test_nurse_repository_missing_on_disk() {

cln.stop().await.unwrap();
}

/// Materializing the following test case
/// https://github.com/coffee-tools/coffee/pull/239#issuecomment-2052606147
#[tokio::test]
#[ntest::timeout(560000)]
pub async fn test_migrated_repository_to_local_one() {
init();
// We need to run before the testnet and the regtest
// because we work on the same database
//
// WHEN UNIX socket?
let dir = Arc::new(tempfile::tempdir().unwrap());

let testnet_conf = CoffeeTestingArgs {
conf: None,
data_dir: dir.path().to_str().unwrap().to_owned(),
network: "testnet".to_owned(),
};

let mut coffee_testnet_m = CoffeeTesting::tmp_with_args(&testnet_conf, dir.clone())
.await
.unwrap();
let coffee_testnet = coffee_testnet_m.coffee();
coffee_testnet
.add_remote(
"lightningd",
"https://github.com/lightningd/plugins.git",
false,
)
.await
.unwrap();

let test_remotes = coffee_testnet.list_remotes().await.unwrap();
std::mem::drop(coffee_testnet_m);

let regtest_conf = CoffeeTestingArgs {
conf: None,
data_dir: dir.path().to_str().unwrap().to_owned(),
network: "regtest".to_owned(),
};

let mut coffee_regtest_m = CoffeeTesting::tmp_with_args(&regtest_conf, dir.clone())
.await
.unwrap();
let coffee_regtest = coffee_regtest_m.coffee();

coffee_regtest
.add_remote(
"folgore",
"https://github.com/coffee-tools/folgore.git",
false,
)
.await
.unwrap();

coffee_regtest
.install("folgore", false, false)
.await
.unwrap();

let reg_plugins = coffee_regtest.list().await.unwrap();
let reg_remotes = coffee_regtest.list_remotes().await.unwrap();

std::mem::drop(coffee_regtest_m);
// just lightnind
assert_eq!(test_remotes.remotes.unwrap().len(), 1);
// just folgore
assert_eq!(reg_remotes.remotes.clone().unwrap().len(), 1);

let mut coffee_testnet_m = CoffeeTesting::tmp_with_args(&testnet_conf, dir.clone())
.await
.unwrap();
let coffee_testnet = coffee_testnet_m.coffee();
let test_plugins = coffee_testnet.list().await.unwrap();
let test_remotes = coffee_testnet.list_remotes().await.unwrap();
std::mem::drop(coffee_testnet_m);

// in the regtest plugins we will just a single plugin, and in testnet none
assert_eq!(test_plugins.plugins.len() + 1, reg_plugins.plugins.len());
assert_eq!(
test_remotes.remotes.unwrap().len(),
reg_remotes.remotes.unwrap().len()
);
}

0 comments on commit 4528011

Please sign in to comment.