2021-03-10 18:14:48 +03:00
|
|
|
// Copyright 2021 The Grin Developers
|
2018-08-03 05:16:16 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use grin_util as util;
|
2018-08-03 05:16:16 +03:00
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use self::util::file;
|
2018-08-03 05:16:16 +03:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::{self, Write};
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn copy_dir() {
|
|
|
|
let root = Path::new("./target/tmp2");
|
|
|
|
fs::create_dir_all(root.join("./original/sub")).unwrap();
|
|
|
|
fs::create_dir_all(root.join("./original/sub2")).unwrap();
|
2018-09-26 23:38:44 +03:00
|
|
|
write_files("original".to_string(), &root).unwrap();
|
2018-08-03 05:16:16 +03:00
|
|
|
let original_path = Path::new("./target/tmp2/original");
|
|
|
|
let copy_path = Path::new("./target/tmp2/copy");
|
|
|
|
file::copy_dir_to(original_path, copy_path).unwrap();
|
2019-07-12 12:50:27 +03:00
|
|
|
let original_files = file::list_files(&Path::new("./target/tmp2/original"));
|
|
|
|
let copied_files = file::list_files(&Path::new("./target/tmp2/copy"));
|
|
|
|
assert_eq!(original_files, copied_files);
|
2018-08-03 05:16:16 +03:00
|
|
|
fs::remove_dir_all(root).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_files(dir_name: String, root: &Path) -> io::Result<()> {
|
|
|
|
let mut file = File::create(root.join(dir_name.clone() + "/foo.txt"))?;
|
|
|
|
file.write_all(b"Hello, world!")?;
|
|
|
|
let mut file = File::create(root.join(dir_name.clone() + "/bar.txt"))?;
|
|
|
|
file.write_all(b"Goodbye, world!")?;
|
2020-02-05 19:02:07 +03:00
|
|
|
let mut file = File::create(root.join(dir_name + "/sub/lorem"))?;
|
2018-08-03 05:16:16 +03:00
|
|
|
file.write_all(b"Lorem ipsum dolor sit amet, consectetur adipiscing elit")?;
|
|
|
|
Ok(())
|
2018-09-26 23:38:44 +03:00
|
|
|
}
|