chore: improve git workflow testing

This commit is contained in:
Aravinth Manivannan 2022-03-29 18:02:32 +05:30
parent 3c40a32fba
commit c76b351198
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 55 additions and 6 deletions

19
Cargo.lock generated
View file

@ -801,6 +801,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "mktemp"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "975de676448231fcde04b9149d2543077e166b78fc29eae5aa219e7928410da2"
dependencies = [
"uuid",
]
[[package]]
name = "nom"
version = "5.1.2"
@ -896,6 +905,7 @@ dependencies = [
"git2",
"lazy_static",
"log",
"mktemp",
"num_cpus",
"pretty_env_logger",
"serde 1.0.136",
@ -1374,6 +1384,15 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom",
]
[[package]]
name = "vcpkg"
version = "0.2.15"

View file

@ -34,3 +34,6 @@ url = "2.2"
derive_more = "0.99"
num_cpus = "1.13"
[dev-dependencies]
mktemp = "0.4.1"

View file

@ -27,7 +27,7 @@ pub struct Page {
}
impl Page {
pub fn create_repo(&self) -> Repository {
fn create_repo(&self) -> Repository {
let repo = Repository::open(&self.path);
if let Ok(repo) = repo {
@ -36,9 +36,7 @@ impl Page {
info!("Cloning repository {} at {}", self.repo, self.path);
Repository::clone(&self.repo, &self.path).unwrap()
};
// let branch = repo.find_branch(&self.branch, BranchType::Local).unwrap();
//repo.branches(BranchType::Local).unwrap().find(|b| b.unwrap().na
let repo = Repository::open(&self.path).unwrap();
{
self._fetch_upstream(&repo, &self.branch);
@ -53,11 +51,8 @@ impl Page {
repo.checkout_tree(&tree, Some(&mut checkout_options))
.unwrap();
// repo.set_head(&format!("refs/heads/{}", &self.branch))
// .unwrap();
repo.set_head(branch.get().name().unwrap()).unwrap();
// }
}
repo
}
@ -75,3 +70,35 @@ impl Page {
self._fetch_upstream(&repo, branch);
}
}
#[cfg(test)]
mod tests {
use super::*;
use mktemp::Temp;
#[actix_rt::test]
async fn pages_works() {
let tmp_dir = Temp::new_dir().unwrap();
assert!(tmp_dir.exists(), "tmp directory successully created");
let page = Page {
secret: String::default(),
repo: "https://github.com/mcaptcha/website".to_owned(),
path: tmp_dir.to_str().unwrap().to_string(),
branch: "gh-pages".to_string(),
};
assert!(
Repository::open(tmp_dir.as_path()).is_err(),
"repository doesn't exist yet"
);
let repo = page.create_repo();
assert!(!repo.is_bare(), "repository isn't bare");
page.create_repo();
assert!(
Repository::open(tmp_dir.as_path()).is_ok(),
"repository exists yet"
);
}
}