-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove-sequence command #28
Changes from 4 commits
2e71cae
fc87f98
2e74209
d5825b1
e10d082
8cc4d4a
c41d828
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,42 @@ pub fn new_sequence<P: AsRef<Path>>( | |
.map(|_| ()) | ||
} | ||
|
||
pub fn remove_sequence<P: AsRef<Path>>(admin_key_path: P, name: &str) -> Result<(), Error> { | ||
|
||
// Check that the admin has sufficient privileges | ||
try!(utils::validate_admin(&admin_key_path)); | ||
|
||
// Make sure the name is valid (needed since it will be used in a file path) | ||
try!(validate_seq_name(name)); | ||
|
||
// Make the name of the sequence's directory | ||
let mut sequence_dir = String::from("seq_"); | ||
sequence_dir.push_str(&name); | ||
let sequence_dir = sequence_dir; | ||
|
||
// Remove sequence's directory | ||
let sequence_dir_path = Path::new(&sequence_dir); | ||
if sequence_dir_path.exists() && sequence_dir_path.is_dir() { | ||
let _ = fs::remove_dir_all(&sequence_dir_path) | ||
.expect("Error removing sequence directory"); | ||
} | ||
|
||
// Remove sequence from project | ||
let project = try!(utils::read_protonfile(None::<P>)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should move this section before |
||
let new_project = try!(project.remove_sequence(name)); | ||
|
||
// Save project | ||
try!(utils::write_protonfile(&new_project, None::<P>)); | ||
|
||
// Commit changes | ||
let signature = Signature::now("Proton Lights", "[email protected]").unwrap(); | ||
let msg = format!("Removing sequence '{}'", name); | ||
let repo_path: Option<P> = None; | ||
|
||
utils::commit_all(repo_path, &signature, &msg) | ||
.map(|_| ()) | ||
} | ||
|
||
/// Check that the music file is a valid format | ||
/// Full list of supported formats can be found at | ||
/// http://www.rust-sfml.org/doc/rsfml/audio/struct.Music.html | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
extern crate proton_cli; | ||
extern crate tempdir; | ||
extern crate git2; | ||
|
||
mod common; | ||
|
||
use std::path::{Path, PathBuf}; | ||
|
||
use common::setup; | ||
use common::rsa_keys::TestKey; | ||
|
||
|
||
#[test] | ||
fn works_with_valid_key_and_name() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a check here that asdf really was added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The asserts are part of try_make_sequence. Will look into them though |
||
proton_cli::remove_sequence(&root_key_path.as_path(), "asdf") | ||
.expect("Error removing sequence"); | ||
|
||
let project = proton_cli::utils::read_protonfile(None::<&Path>) | ||
.expect("Error reading project from file"); | ||
|
||
let found_sequence = project.find_sequence_by_name("asdf"); | ||
|
||
assert!(found_sequence.is_none()); | ||
|
||
let mut sequence_dir_path = PathBuf::from(root.path()); | ||
sequence_dir_path.push("seq_asdf"); | ||
assert!(!sequence_dir_path.exists()); | ||
|
||
common::assert_repo_no_modified_files(&root.path()); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error removing sequence: Ssl")] | ||
fn fails_with_invalid_admin_key() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
let root_key_bad_path = common::make_key_file(&root.path(), "root_bad.pub", TestKey::RootKeyPub); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
proton_cli::remove_sequence(&root_key_bad_path.as_path(), "asdf") | ||
.expect("Error removing sequence"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error removing sequence: Io")] | ||
fn fails_with_nonexistent_admin_key() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
let root_key_bad_path = PathBuf::from("nonexistent"); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
proton_cli::remove_sequence(&root_key_bad_path.as_path(), "asdf") | ||
.expect("Error removing sequence"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error removing sequence: UnauthorizedAction")] | ||
fn fails_with_unauthorized_admin_key() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
let normal_key_pub_path = common::make_key_file(&root.path(), "normal.pub", TestKey::GoodKeyPub); | ||
let normal_key_priv_path = common::make_key_file(&root.path(), "normal.pem", TestKey::GoodKeyPem); | ||
let _ = proton_cli::new_user( | ||
&root_key_path.as_path(), | ||
&normal_key_pub_path.as_path(), | ||
"normal_user" | ||
).expect("Error creating user"); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
proton_cli::remove_sequence(&normal_key_priv_path.as_path(), "asdf") | ||
.expect("Error removing sequence"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error removing sequence: SequenceNotFound")] | ||
fn fails_with_nonexistent_sequence_name() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
proton_cli::remove_sequence(&root_key_path.as_path(), "a") | ||
.expect("Error removing sequence"); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "Error removing sequence: InvalidSequenceName")] | ||
fn fails_with_bad_sequence_name() { | ||
let root = setup::setup_init_cd(); | ||
let root_key_path = common::make_key_file(&root.path(), "root.pem", TestKey::RootKeyPem); | ||
|
||
setup::try_make_sequence(&root_key_path.as_path(), "asdf", "Dissonance.ogg"); | ||
proton_cli::remove_sequence(&root_key_path.as_path(), "as df") | ||
.expect("Error removing sequence"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "seq_".to_owned() is better since its just more commonly used.