first binary test not complete
This commit is contained in:
parent
de17ff12be
commit
101dcbb649
@ -1,10 +1,50 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
extern crate clap;
|
||||||
|
use clap::{App, Arg};
|
||||||
|
|
||||||
extern crate adduser;
|
extern crate adduser;
|
||||||
use adduser::api::UserDBWrite;
|
use adduser::api::UserDBWrite;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
let matches = App::new("Create a new linux user")
|
||||||
|
.version("0.1.0")
|
||||||
|
.author("Franz Dietrich <dietrich@teilgedanken.de>")
|
||||||
|
.about("Create a linux user do not use this in production (yet)")
|
||||||
|
.arg(
|
||||||
|
Arg::new("username")
|
||||||
|
.short('n')
|
||||||
|
.long("username")
|
||||||
|
.value_name("USERNAME")
|
||||||
|
.about("the new users name")
|
||||||
|
.takes_value(true)
|
||||||
|
.required(true),
|
||||||
|
) /*
|
||||||
|
.arg(
|
||||||
|
Arg::new("INPUT")
|
||||||
|
.about("Sets the input file to use")
|
||||||
|
.required(true)
|
||||||
|
.index(1),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("v")
|
||||||
|
.short('v')
|
||||||
|
.multiple(true)
|
||||||
|
.about("Sets the level of verbosity"),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
App::new("test")
|
||||||
|
.about("controls testing features")
|
||||||
|
.version("1.3")
|
||||||
|
.author("Someone E. <someone_else@other.com>")
|
||||||
|
.arg(
|
||||||
|
Arg::new("debug")
|
||||||
|
.short('d')
|
||||||
|
.about("print debug information verbosely"),
|
||||||
|
),
|
||||||
|
)*/
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
let mf = adduser::Files {
|
let mf = adduser::Files {
|
||||||
passwd: Some(PathBuf::from("./passwd")),
|
passwd: Some(PathBuf::from("./passwd")),
|
||||||
@ -16,7 +56,7 @@ fn main() {
|
|||||||
|
|
||||||
let _user_res: Result<&adduser::User, adduser::UserLibError> = db.new_user(
|
let _user_res: Result<&adduser::User, adduser::UserLibError> = db.new_user(
|
||||||
adduser::api::CreateUserArgs::builder()
|
adduser::api::CreateUserArgs::builder()
|
||||||
.username("teste")
|
.username(matches.value_of("username").unwrap())
|
||||||
// .delete_home(adduser::api::DeleteHome::Delete)
|
// .delete_home(adduser::api::DeleteHome::Delete)
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
|
@ -40,3 +40,42 @@ fn test_create_user_function() {
|
|||||||
}
|
}
|
||||||
assert!(pf2.lines().last().unwrap().starts_with("test2"));
|
assert!(pf2.lines().last().unwrap().starts_with("test2"));
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_create_user_binary() {
|
||||||
|
use testfiles::Fixture;
|
||||||
|
|
||||||
|
use adduser::api::UserDBWrite;
|
||||||
|
use adduser::api::UserRead;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
|
let p = Fixture::copy("passwd");
|
||||||
|
let s = Fixture::copy("shadow");
|
||||||
|
let g = Fixture::copy("group");
|
||||||
|
|
||||||
|
let pf = fs::read_to_string(&p.path).unwrap();
|
||||||
|
|
||||||
|
let mf = adduser::Files {
|
||||||
|
passwd: Some(p.path.clone()),
|
||||||
|
shadow: Some(s.path),
|
||||||
|
group: Some(g.path),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut db = adduser::UserDBLocal::load_files(mf).unwrap();
|
||||||
|
|
||||||
|
let user_res: Result<&adduser::User, adduser::UserLibError> = db.new_user(
|
||||||
|
adduser::api::CreateUserArgs::builder()
|
||||||
|
.username("test2")
|
||||||
|
// .delete_home(adduser::api::DeleteHome::Delete)
|
||||||
|
.build()
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
let pf2 = fs::read_to_string(&p.path).unwrap();
|
||||||
|
assert_eq!(user_res.unwrap().get_username().unwrap(), "test2");
|
||||||
|
let pflines = pf.lines();
|
||||||
|
let pflines2 = pf2.lines();
|
||||||
|
for (l1, l2) in pflines.zip(pflines2) {
|
||||||
|
dbg!(l1, l2);
|
||||||
|
assert!(l1 == l2);
|
||||||
|
}
|
||||||
|
assert!(pf2.lines().last().unwrap().starts_with("test2"));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user