144 lines
4.1 KiB
Rust
144 lines
4.1 KiB
Rust
|
|
mod utils;
|
|
use utils::{utils::*, status_utils::*, server::ServerTest, client::ClientTest};
|
|
|
|
|
|
#[cfg(test)]
|
|
mod push_tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn simple_push() {
|
|
let id = get_random_test_id();
|
|
let mut server = ServerTest::new(id.clone());
|
|
server.init();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_file("file1", "foo");
|
|
client.run_cmd_ok("add file1");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
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();
|
|
server.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn push_update() {
|
|
let id = get_random_test_id();
|
|
let mut server = ServerTest::new(id.clone());
|
|
server.init();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
// init content of file1
|
|
let _ = client.add_file("file1", "foo");
|
|
client.run_cmd_ok("add file1");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
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
|
|
let _ = client.add_file("file1", "bar");
|
|
client.run_cmd_ok("add file1");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
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();
|
|
server.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn push_dir_explicit() {
|
|
let id = get_random_test_id();
|
|
let mut server = ServerTest::new(id.clone());
|
|
server.init();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_dir("dir");
|
|
let _ = client.add_file("dir/file2", "bar");
|
|
|
|
// push dir and file2
|
|
client.run_cmd_ok("add dir");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
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();
|
|
server.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn push_dir_implicit() {
|
|
let id = get_random_test_id();
|
|
let mut server = ServerTest::new(id.clone());
|
|
server.init();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_dir("dir");
|
|
let _ = client.add_file("dir/file2", "bar");
|
|
|
|
// push dir and file2
|
|
client.run_cmd_ok("add dir/file2");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
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();
|
|
server.clean();
|
|
}
|
|
|
|
#[test]
|
|
fn push_all() {
|
|
let id = get_random_test_id();
|
|
let mut server = ServerTest::new(id.clone());
|
|
server.init();
|
|
let mut client = ClientTest::new(id).init();
|
|
|
|
let _ = client.add_file("file1", "foo");
|
|
let _ = client.add_dir("dir");
|
|
let _ = client.add_file("dir/file2", "bar");
|
|
|
|
// push dir and file2
|
|
client.run_cmd_ok("add *");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
assert!(server.has_file("file1", "foo"));
|
|
assert!(server.has_file("dir/file2", "bar"));
|
|
let (staged, not_staged) = client.get_status();
|
|
assert!(staged.len() == 0);
|
|
assert!(not_staged.len() == 0);
|
|
|
|
client.clean();
|
|
server.clean();
|
|
}
|
|
}
|