Skip to content
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

test: add data #12

Merged
merged 18 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ pub fn parse_ntriples(reader: Box<dyn BufRead>) -> impl Iterator<Item = Triple>

#[cfg(test)]
mod tests {
use super::parse_ntriples;
use std::io::{BufRead, BufReader};

#[test]
// Test the parsing of a triple.
fn parse_ntriples() {
let input = "\n
<http://example.org/resource2> <http://example.org/relatedTo> <http://example.org/resource3>\n
<http://example.org/resource2> <http://example.org/relatedTo> <http://example.org/resource3>\n
";
fn simple_parsing() {
let input: &[u8] = "http://example.org/resource2> <http://example.org/relatedTo> <http://example.org/resource3> .\n".as_bytes();
let buffer_input: Box<dyn BufRead> = Box::new(BufReader::new(input));
parse_ntriples(buffer_input).for_each(|t| {
assert_eq!(t.subject, "A"); // to replace with http://example.org/resource2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! but shouldnt it be http://example.com... in the assert? You wanted it to fail for me to test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the parse.nt function is turning any triple into "A", "B" and "C" ;)
That's why the test fails when using what's commented right now
https://github.com/sdsc-ordes/rdf-protect/blob/b00e799ed997d335739226e73430403a89d9d0ef/src/model.rs#L58-L62

assert_eq!(t.predicate, "B"); // to replace with http://example.org/relatedTo
assert_eq!(t.object, "C"); // to replace with http://example.org/resource3
});
}
}
6 changes: 3 additions & 3 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use bitflags::bitflags;

#[derive(Debug)]
pub struct Triple {
subject: String,
predicate: String,
object: String,
pub subject: String,
pub predicate: String,
pub object: String,
}

// should use bitflags, e.g. S = 0b100, P = 0b010 -> SP = S + P
Expand Down
1 change: 0 additions & 1 deletion src/pass_first.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@


16 changes: 16 additions & 0 deletions src/pass_second.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ pub fn encrypt(log: &Logger, input: &Path, output: &Path, type_map_file: &Path)
info!(log, "{:?}", triple.hash_parts(TriplePart::SUBJECT));
}
}
#[cfg(test)]
mod tests {
use super::encrypt;
use crate::{log, log::Logger};
use std::path::Path;

#[test]
// Test the parsing of a triple.
fn simple_encryption() {
let input_path = Path::new("tests/data/test.nt");
let output_path = Path::new("tests/data/");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the output path should be a file or - to specify stdout, should be documented probably on the function, sorry didnt wrote that yet.

let type_map_path = Path::new("tests/data/type_map.nt");
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved
let logger = log::create_logger(true);
encrypt(&logger, &input_path, &output_path, &type_map_path);
}
}
15 changes: 15 additions & 0 deletions tests/data/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# hash URIs of people and online accounts
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved
replace-uris-of-nodes-with-type:
"http://xmlns.com/foaf/0.1/Person" # All nodes which are rdf:type Person
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved
"http://xmlns.com/foaf/OnlineAccount" # "" OnlineAccount
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved

# hash name only for instances of person and online account
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved
replace-values-of-predicate-object:
"http://xmlns.com/foaf/OnlineAccount":
"http://schema.org/name"
"http://xmlns.com/foaf/0.1/Person":
"http://schema.org/name"

# hash accesscode values for all nodes
supermaxiste marked this conversation as resolved.
Show resolved Hide resolved
replace-values-of-predicate:
"http://schema.org/accessCode"
15 changes: 15 additions & 0 deletions tests/data/test.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<http://example.org/Alice> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/0.1/Person> .
gabyx marked this conversation as resolved.
Show resolved Hide resolved
<http://example.org/Alice> <http://xmlns.com/foaf/0.1/holdsAccount> <http://example.org/Alice-Bank-Account> .
<http://example.org/Alice-Bank-Account> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/OnlineAccount> .
<http://example.org/Alice-Bank-Account> <http://schema.org/name> "my_account32" .
<http://example.org/Alice-Bank-Account> <http://schema.org/accessCode> "secret-123" .
<http://example.org/Alice> <http://schema.org/name> "Alice" .
<http://example.org/Bob> <http://xmlns.com/foaf/0.1/knows> <http://example.org/Alice> .
<http://example.org/Bob> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/0.1/Person>
<http://example.org/Bob> <http://xmlns.com/foaf/0.1/holdsAccount> <http://example.org/Bob-Bank-Account> .
<http://example.org/Bob-Bank-Account> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/OnlineAccount> .
<http://example.org/Bob-Bank-Account> <http://schema.org/name> "my_account12" .
<http://example.org/Bob-Bank-Account> <http://schema.org/accessCode> "secret-456" .
<http://example.org/Bob> <http://schema.org/name> "Bob" .
<http://example.org/Bank> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/0.1/Organization> .
<http://example.org/Bank> <http://schema.org/name> "Bank" .
4 changes: 4 additions & 0 deletions tests/data/type_map.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<http://example.org/Alice> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/0.1/Person> .
<http://example.org/Alice-Bank-Account> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/OnlineAccount> .
<http://example.org/Bob> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/0.1/Person> .
<http://example.org/Bob-Bank-Account> <http://www.w3.org/2000/01/rdf-schema#type> <http://xmlns.com/foaf/OnlineAccount> .