-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2e71cae
Added tests for removing sequence
bookdude13 fc87f98
Implemented remove-sequence
bookdude13 2e74209
Added remove-sequence to main
bookdude13 d5825b1
Removed blank lines
bookdude13 e10d082
PR suggestions
bookdude13 8cc4d4a
Added more asserts in try_make_sequence
bookdude13 c41d828
Updated README
bookdude13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ pub fn new_sequence<P: AsRef<Path>>( | |
try!(validate_file_type(&music_file_path)); | ||
|
||
// Make the name of the sequence's directory | ||
let mut sequence_dir = String::from("seq_"); | ||
let mut sequence_dir = "seq_".to_owned(); | ||
sequence_dir.push_str(&name); | ||
let sequence_dir = sequence_dir; | ||
|
||
|
@@ -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 = "seq_".to_owned(); | ||
sequence_dir.push_str(&name); | ||
let sequence_dir = sequence_dir; | ||
|
||
// Remove sequence from project | ||
let project = try!(utils::read_protonfile(None::<P>)); | ||
let new_project = try!(project.remove_sequence(name)); | ||
|
||
// 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"); | ||
} | ||
|
||
// 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
||
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"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add a check here that asdf really was added.
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.
The asserts are part of try_make_sequence. Will look into them though