Skip to content

Commit

Permalink
test(git): add statuses test
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Oct 24, 2020
1 parent 6ff44d4 commit bd69f41
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/git/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use std::fmt;

pub(crate) struct Statuses(pub Vec<Status>);

#[derive(Eq, PartialEq)]
pub(crate) enum Status {
Untracked(Changes),
UnCommitted(Changes),
}

#[derive(Eq, PartialEq)]
pub(crate) enum Changes {
New(String),
Renamed(String),
Expand Down Expand Up @@ -101,3 +103,38 @@ impl fmt::Debug for Statuses {
write!(f, "{}", &self)
}
}

#[cfg(test)]
mod test {
use crate::git::status::{Changes, Statuses};
use anyhow::Result;
use git2::Repository;
use git2::StatusOptions;
use std::fs;
use temp_testdir::TempDir;

#[test]
fn should_get_statuses_from_git_statuses() -> Result<()> {
let temp_testdir = TempDir::default();
let path = temp_testdir.join("test_repo");
let repo = Repository::init(&path)?;
fs::write(path.join("file"), "content")?;

let mut options = StatusOptions::new();
options.include_untracked(true);
options.exclude_submodules(true);
options.include_unmodified(false);

let git_statuses = repo
.statuses(Some(&mut options))
.map_err(|err| anyhow!(err))?;

let statuses = Statuses::from(git_statuses);

assert!(statuses
.0
.contains(&super::Status::Untracked(Changes::New("file".into()))));
assert_eq!(statuses.0.len(), 1);
Ok(())
}
}

0 comments on commit bd69f41

Please sign in to comment.