Skip to content

Commit

Permalink
Expose properties() step in an anonymouse traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
criminosis committed Jul 16, 2024
1 parent 09d562c commit 97b677c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ impl AnonymousTraversalSource {
self.traversal.clone().property(key, value)
}

pub fn properties<L>(&self, labels: L) -> TraversalBuilder
where
L: Into<Labels>,
{
self.traversal.clone().properties(labels)
}

pub fn v<T>(&self, ids: T) -> TraversalBuilder
where
T: Into<GIDs>,
Expand Down
55 changes: 55 additions & 0 deletions gremlin-client/tests/integration_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,61 @@ fn test_side_effect() {
);
}

#[test]
fn test_anonymous_traversal_properties_drop() {
let client = graph();
let test_vertex_label = "test_anonymous_traversal_properties_drop";
let pre_drop_prop_key = "pre_drop_prop_key";
let expected_prop_value = "prop_val";

drop_vertices(&client, &test_vertex_label).unwrap();

let g = traversal().with_remote(client);

let element_map = g
.add_v(test_vertex_label)
.side_effect(__.property(
gremlin_client::structure::Either2::A(pre_drop_prop_key),
expected_prop_value,
))
.element_map(())
.next()
.expect("Should get response")
.expect("Should have returned an element map");

//Make sure the property was assigned
assert_map_property(&element_map, pre_drop_prop_key, expected_prop_value);

let created_vertex_id = element_map.get("id").expect("Should have id property");
let GValue::Int64(id) = created_vertex_id else {
panic!("Not expected id type");
};

let post_drop_prop_key = "post_drop_prop_key";
//Operate on the same vertex via id
let post_drop_map = g
.v(*id)
//Drop all properties first
.side_effect(__.properties(()).drop())
//Then add a different property
.side_effect(__.property(
gremlin_client::structure::Either2::A(pre_drop_prop_key),
expected_prop_value,
))
.element_map(())
.next()
.expect("Should get response")
.expect("Should have returned an element map");

assert_map_property(&post_drop_map, pre_drop_prop_key, expected_prop_value);

//Now make sure the pre drop property key is no longer present
assert!(
post_drop_map.get(post_drop_prop_key).is_none(),
"Pre drop key should have been dropped"
);
}

#[test]
fn test_by_columns() {
let client = graph();
Expand Down

0 comments on commit 97b677c

Please sign in to comment.