test(push): check that object are locally created when pushed
This commit is contained in:
parent
fa65b6b071
commit
3207391fdb
@ -26,7 +26,6 @@ fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
|||||||
}
|
}
|
||||||
assert!(line.find(str).is_none());
|
assert!(line.find(str).is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
fn collect_status_lines(client: &mut ClientTest) -> Vec<String> {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
use utils::{utils::*, server::ServerTest, client::ClientTest};
|
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -19,6 +19,9 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "foo"));
|
assert!(server.has_file("file1", "foo"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -38,6 +41,10 @@ mod push_tests {
|
|||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "foo"));
|
assert!(server.has_file("file1", "foo"));
|
||||||
|
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
// change content of file1
|
// change content of file1
|
||||||
let _ = client.add_file("file1", "bar");
|
let _ = client.add_file("file1", "bar");
|
||||||
client.run_cmd_ok("add file1");
|
client.run_cmd_ok("add file1");
|
||||||
@ -45,6 +52,10 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("file1", "bar"));
|
assert!(server.has_file("file1", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged, "file1");
|
||||||
|
lines_should_not_contains(not_staged, "file1");
|
||||||
|
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -65,6 +76,11 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("dir/file2", "bar"));
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(staged, "foo");
|
||||||
|
lines_should_not_contains(not_staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(not_staged, "foo");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
@ -85,6 +101,11 @@ mod push_tests {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
assert!(server.has_file("dir/file2", "bar"));
|
assert!(server.has_file("dir/file2", "bar"));
|
||||||
|
let (staged, not_staged) = client.get_status();
|
||||||
|
lines_should_not_contains(staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(staged, "foo");
|
||||||
|
lines_should_not_contains(not_staged.clone(), "file2");
|
||||||
|
lines_should_not_contains(not_staged, "foo");
|
||||||
|
|
||||||
client.clean();
|
client.clean();
|
||||||
server.clean();
|
server.clean();
|
||||||
|
@ -6,3 +6,6 @@ pub mod client;
|
|||||||
|
|
||||||
#[path = "utils/utils.rs"]
|
#[path = "utils/utils.rs"]
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
|
#[path = "utils/status_utils.rs"]
|
||||||
|
pub mod status_utils;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use std::str;
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@ -90,4 +91,46 @@ impl ClientTest {
|
|||||||
file.write_all(content.as_bytes())?;
|
file.write_all(content.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get the files given by the status command in two vector (staged and not staged)
|
||||||
|
pub fn get_status(&mut self) -> (Vec<String>, Vec<String>) {
|
||||||
|
let out = self.run_cmd("status");
|
||||||
|
|
||||||
|
let lines: Vec<String> = str::from_utf8(&out.stdout)
|
||||||
|
.unwrap()
|
||||||
|
.split("\n")
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut staged = vec![];
|
||||||
|
let mut not_staged = vec![];
|
||||||
|
let mut in_staged = true;
|
||||||
|
let mut counter = 0;
|
||||||
|
for line in lines {
|
||||||
|
if line.find("not staged").is_some() {
|
||||||
|
in_staged = false;
|
||||||
|
counter = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip two first line as there are not files
|
||||||
|
if counter < 2 {
|
||||||
|
counter += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if line == String::from("") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if in_staged {
|
||||||
|
staged.push(line);
|
||||||
|
} else {
|
||||||
|
not_staged.push(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (staged, not_staged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
9
tests/utils/status_utils.rs
Normal file
9
tests/utils/status_utils.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
pub fn lines_should_not_contains(lines: Vec<String>, str: &str) {
|
||||||
|
for line in lines {
|
||||||
|
if line.find(str).is_some() {
|
||||||
|
eprintln!("'{}' found in '{}'", str, line);
|
||||||
|
}
|
||||||
|
assert!(line.find(str).is_none());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user