169 lines
4.7 KiB
Rust
169 lines
4.7 KiB
Rust
mod utils;
|
|
use utils::{utils::*, status_utils::*};
|
|
|
|
#[cfg(test)]
|
|
mod push_tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn simple_push() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
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");
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_update() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
// 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");
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_dir_explicit() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
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");
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_dir_implicit() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
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");
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_all() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
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);
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_file_deletion() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
let _ = client.add_file("file1", "foo");
|
|
|
|
// push file1
|
|
client.run_cmd_ok("add file1");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
assert!(server.has_file("file1", "foo"));
|
|
status_should_be_empty(&mut client);
|
|
|
|
// remove it
|
|
let _ = client.remove_file("file1");
|
|
client.run_cmd_ok("add file1");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
assert!(server.has_not_file("file1"));
|
|
status_should_be_empty(&mut client);
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
|
|
#[test]
|
|
fn push_dir_deletion() {
|
|
let (mut client, mut server) = init_test();
|
|
|
|
// push dir and file2
|
|
let _ = client.add_dir("dir");
|
|
let _ = client.add_file("dir/file2", "bar");
|
|
client.run_cmd_ok("add dir");
|
|
client.run_cmd_ok("push");
|
|
|
|
// tests
|
|
assert!(server.has_file("dir/file2", "bar"));
|
|
|
|
// push deletion
|
|
let _ = client.remove_dir("dir");
|
|
client.run_cmd_ok("add dir");
|
|
client.run_cmd_ok("push");
|
|
assert!(server.has_not_dir("dir"));
|
|
|
|
clean_test(client, &mut server);
|
|
}
|
|
}
|