Skip to content

Commit 5b10598

Browse files
tests: write test to making sure that we use local repo everywhere
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 7608c2b commit 5b10598

File tree

5 files changed

+129
-16
lines changed

5 files changed

+129
-16
lines changed

coffee_core/src/nurse/strategy.rs

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ impl Handler for CoffeeRepositoryDirCleanUpStrategy {
9191
coffee: &CoffeeManager,
9292
) -> Result<Option<Defect>, CoffeeError> {
9393
let network = coffee.config.network.clone();
94+
let global_dir = coffee.config.root_path.clone();
95+
let global_dir = format!("{global_dir}/repositories");
96+
if !Path::exists(Path::new(&global_dir)) {
97+
return Ok(None);
98+
}
9499
// Check whether there exists a network-specific repositories folder for each network.
95100
let mut directory_moving = vec![];
96101
let subpath_repo = format!("{}/{network}/repositories", coffee.config.root_path);

coffee_lib/src/plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl PluginLang {
9393
}
9494

9595
/// Plugin struct definition
96-
#[derive(Clone, Serialize, Deserialize, Debug)]
96+
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
9797
pub struct Plugin {
9898
name: String,
9999
/// root path of the plugin

coffee_lib/src/plugin_conf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Coffee configuration serialization file.
22
use serde::{Deserialize, Serialize};
33

4-
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
4+
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Eq)]
55
pub struct Conf {
66
pub plugin: Plugin,
77
pub tipping: Option<Tipping>,
88
}
99

10-
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
10+
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, Eq)]
1111
pub struct Plugin {
1212
pub name: String,
1313
pub version: String,
@@ -19,12 +19,12 @@ pub struct Plugin {
1919
pub important: Option<bool>,
2020
}
2121

22-
#[derive(Debug, PartialEq, Serialize, Deserialize)]
22+
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
2323
pub struct Deprecaterd {
2424
pub reason: String,
2525
}
2626

27-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
27+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
2828
pub struct Tipping {
2929
pub bolt12: String,
3030
}

coffee_lib/src/types/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ pub mod response {
8585
pub plugins: Vec<Plugin>,
8686
}
8787

88-
#[derive(Clone, Debug, Serialize, Deserialize)]
88+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
8989
pub struct CoffeeRemote {
9090
pub remotes: Option<Vec<CoffeeListRemote>>,
9191
}
9292

93-
#[derive(Clone, Debug, Serialize, Deserialize)]
93+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
9494
pub struct CoffeeListRemote {
9595
pub local_name: String,
9696
pub url: String,

tests/src/coffee_integration_tests.rs

+117-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ pub async fn init_coffee_test_cmd() -> anyhow::Result<()> {
4040
let root_path = manager.root_path().to_owned();
4141
manager
4242
.coffee()
43-
.add_remote("folgore", "https://github.com/coffee-tools/folgore.git")
43+
.add_remote(
44+
"folgore",
45+
"https://github.com/coffee-tools/folgore.git",
46+
false,
47+
)
4448
.await
4549
.unwrap();
4650

@@ -107,7 +111,11 @@ pub async fn init_coffee_test_add_remote() {
107111

108112
manager
109113
.coffee()
110-
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
114+
.add_remote(
115+
"lightningd",
116+
"https://github.com/lightningd/plugins.git",
117+
false,
118+
)
111119
.await
112120
.unwrap();
113121
manager
@@ -141,7 +149,7 @@ pub async fn test_add_remove_plugins() {
141149
let repo_url = "https://github.com/lightningd/plugins.git";
142150
manager
143151
.coffee()
144-
.add_remote(repo_name, repo_url)
152+
.add_remote(repo_name, repo_url, false)
145153
.await
146154
.unwrap();
147155

@@ -260,7 +268,7 @@ pub async fn test_errors_and_show() {
260268
let repo_url = "https://github.com/lightningd/plugins.git";
261269
manager
262270
.coffee()
263-
.add_remote(repo_name, repo_url)
271+
.add_remote(repo_name, repo_url, false)
264272
.await
265273
.unwrap();
266274

@@ -346,7 +354,11 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {
346354
// Add lightningd remote repository
347355
manager
348356
.coffee()
349-
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
357+
.add_remote(
358+
"lightningd",
359+
"https://github.com/lightningd/plugins.git",
360+
false,
361+
)
350362
.await
351363
.unwrap();
352364
// Install summary plugin
@@ -386,7 +398,11 @@ pub async fn install_plugin_in_two_networks() -> anyhow::Result<()> {
386398

387399
let result = manager
388400
.coffee()
389-
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
401+
.add_remote(
402+
"lightningd",
403+
"https://github.com/lightningd/plugins.git",
404+
false,
405+
)
390406
.await;
391407
assert!(result.is_err(), "{:?}", result);
392408
// Install summary plugin
@@ -423,7 +439,7 @@ pub async fn test_double_slash() {
423439
let repo_url = "https://github.com/lightningd/plugins.git";
424440
manager
425441
.coffee()
426-
.add_remote(repo_name, repo_url)
442+
.add_remote(repo_name, repo_url, false)
427443
.await
428444
.unwrap();
429445

@@ -486,7 +502,11 @@ pub async fn test_plugin_installation_path() {
486502
// Add lightningd remote repository
487503
manager
488504
.coffee()
489-
.add_remote("lightningd", "https://github.com/lightningd/plugins.git")
505+
.add_remote(
506+
"lightningd",
507+
"https://github.com/lightningd/plugins.git",
508+
false,
509+
)
490510
.await
491511
.unwrap();
492512

@@ -604,7 +624,11 @@ pub async fn test_nurse_repository_missing_on_disk() {
604624
// Add folgore remote repository
605625
manager
606626
.coffee()
607-
.add_remote("folgore", "https://github.com/coffee-tools/folgore.git")
627+
.add_remote(
628+
"folgore",
629+
"https://github.com/coffee-tools/folgore.git",
630+
false,
631+
)
608632
.await
609633
.unwrap();
610634

@@ -700,3 +724,87 @@ pub async fn test_nurse_repository_missing_on_disk() {
700724

701725
cln.stop().await.unwrap();
702726
}
727+
728+
/// Materializing the following test case
729+
/// https://github.com/coffee-tools/coffee/pull/239#issuecomment-2052606147
730+
#[tokio::test]
731+
#[ntest::timeout(560000)]
732+
pub async fn test_migrated_repository_to_local_one() {
733+
init();
734+
// We need to run before the testnet and the regtest
735+
// because we work on the same database
736+
//
737+
// WHEN UNIX socket?
738+
let dir = Arc::new(tempfile::tempdir().unwrap());
739+
740+
let testnet_conf = CoffeeTestingArgs {
741+
conf: None,
742+
data_dir: dir.path().to_str().unwrap().to_owned(),
743+
network: "testnet".to_owned(),
744+
};
745+
746+
let mut coffee_testnet_m = CoffeeTesting::tmp_with_args(&testnet_conf, dir.clone())
747+
.await
748+
.unwrap();
749+
let coffee_testnet = coffee_testnet_m.coffee();
750+
coffee_testnet
751+
.add_remote(
752+
"lightningd",
753+
"https://github.com/lightningd/plugins.git",
754+
false,
755+
)
756+
.await
757+
.unwrap();
758+
759+
let test_remotes = coffee_testnet.list_remotes().await.unwrap();
760+
std::mem::drop(coffee_testnet_m);
761+
762+
let regtest_conf = CoffeeTestingArgs {
763+
conf: None,
764+
data_dir: dir.path().to_str().unwrap().to_owned(),
765+
network: "regtest".to_owned(),
766+
};
767+
768+
let mut coffee_regtest_m = CoffeeTesting::tmp_with_args(&regtest_conf, dir.clone())
769+
.await
770+
.unwrap();
771+
let coffee_regtest = coffee_regtest_m.coffee();
772+
773+
coffee_regtest
774+
.add_remote(
775+
"folgore",
776+
"https://github.com/coffee-tools/folgore.git",
777+
false,
778+
)
779+
.await
780+
.unwrap();
781+
782+
coffee_regtest
783+
.install("folgore", false, false)
784+
.await
785+
.unwrap();
786+
787+
let reg_plugins = coffee_regtest.list().await.unwrap();
788+
let reg_remotes = coffee_regtest.list_remotes().await.unwrap();
789+
790+
std::mem::drop(coffee_regtest_m);
791+
// just lightnind
792+
assert_eq!(test_remotes.remotes.unwrap().len(), 1);
793+
// just folgore
794+
assert_eq!(reg_remotes.remotes.clone().unwrap().len(), 1);
795+
796+
let mut coffee_testnet_m = CoffeeTesting::tmp_with_args(&testnet_conf, dir.clone())
797+
.await
798+
.unwrap();
799+
let coffee_testnet = coffee_testnet_m.coffee();
800+
let test_plugins = coffee_testnet.list().await.unwrap();
801+
let test_remotes = coffee_testnet.list_remotes().await.unwrap();
802+
std::mem::drop(coffee_testnet_m);
803+
804+
// in the regtest plugins we will just a single plugin, and in testnet none
805+
assert_eq!(test_plugins.plugins.len() + 1, reg_plugins.plugins.len());
806+
assert_eq!(
807+
test_remotes.remotes.unwrap().len(),
808+
reg_remotes.remotes.unwrap().len()
809+
);
810+
}

0 commit comments

Comments
 (0)