From a1bbe791b0aafce9634857d8151a12568f9f4767 Mon Sep 17 00:00:00 2001 From: Allan Clements Date: Wed, 13 Nov 2024 11:28:19 -0600 Subject: [PATCH] Created parameterized integration_client_async --- .../tests/integration_client_async.rs | 72 +++++--- .../tests/integration_client_async_v2.rs | 174 ------------------ 2 files changed, 42 insertions(+), 204 deletions(-) delete mode 100644 gremlin-client/tests/integration_client_async_v2.rs diff --git a/gremlin-client/tests/integration_client_async.rs b/gremlin-client/tests/integration_client_async.rs index c936cc68..90dedf46 100644 --- a/gremlin-client/tests/integration_client_async.rs +++ b/gremlin-client/tests/integration_client_async.rs @@ -5,24 +5,24 @@ mod common; mod aio { use gremlin_client::{aio::GremlinClient, ConnectionOptions, GremlinError, TlsOptions}; - use gremlin_client::{Edge, GValue, Map, Vertex}; + use gremlin_client::{Edge, GValue, IoProtocol, Map, Vertex}; + + use rstest::*; + use rstest_reuse::{self, *}; - use super::common::aio::{connect, create_edge, create_vertex, drop_vertices}; + use crate::common; + + use super::common::aio::{connect, create_edge, create_vertex, drop_vertices, connect_serializer}; #[cfg(feature = "async-std-runtime")] use async_std::prelude::*; #[cfg(feature = "tokio-runtime")] use tokio_stream::StreamExt; + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_client_connection_ok() { - connect().await; - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_ok_credentials() { + async fn test_ok_credentials(protocol: IoProtocol) { let client = GremlinClient::connect( ConnectionOptions::builder() .host("localhost") @@ -32,6 +32,8 @@ mod aio { .tls_options(TlsOptions { accept_invalid_certs: true, }) + .serializer(protocol.clone()) + .deserializer(protocol) .build(), ) .await @@ -41,10 +43,11 @@ mod aio { assert!(result.is_ok(), "{:?}", result); } + #[apply(common::serializers)] #[cfg(feature = "async-std-runtime")] #[cfg_attr(feature = "async-std-runtime", async_std::test)] - async fn test_empty_query() { - let graph = connect().await; + async fn test_empty_query(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; assert_eq!( 0, @@ -57,10 +60,11 @@ mod aio { ) } + #[apply(common::serializers)] #[cfg(feature = "async-std-runtime")] #[cfg_attr(feature = "async-std-runtime", async_std::test)] - async fn test_session_empty_query() { - let mut graph = connect().await; + async fn test_session_empty_query(protocol: IoProtocol) { + let mut graph = connect_serializer(protocol).await; let mut sessioned_graph = graph .create_session("test-session".to_string()) .await @@ -82,10 +86,11 @@ mod aio { .expect("It should close the session."); } + #[apply(common::serializers)] #[cfg(feature = "async-std-runtime")] #[cfg_attr(feature = "async-std-runtime", async_std::test)] - async fn test_keep_alive_query() { - let graph = connect().await; + async fn test_keep_alive_query(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; assert_eq!( 0, @@ -110,10 +115,11 @@ mod aio { ) } + #[apply(common::serializers)] #[cfg(feature = "async-std-runtime")] #[cfg_attr(feature = "async-std-runtime", async_std::test)] - async fn test_partial_content() { - let graph = connect().await; + async fn test_partial_content(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; drop_vertices(&graph, "Partial") .await @@ -137,10 +143,11 @@ mod aio { ); } + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_wrong_query() { - let error = connect() + async fn test_wrong_query(protocol: IoProtocol) { + let error = connect_serializer(protocol) .await .execute("g.V", &[]) .await @@ -155,10 +162,11 @@ mod aio { } } + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_wrong_alias() { - let error = connect() + async fn test_wrong_alias(protocol: IoProtocol) { + let error = connect_serializer(protocol) .await .alias("foo") .execute("g.V()", &[]) @@ -174,11 +182,11 @@ mod aio { } } + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - - async fn test_vertex_query() { - let graph = connect().await; + async fn test_vertex_query(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; let vertices = graph .execute( "g.V().hasLabel('person').has('name',name)", @@ -194,10 +202,12 @@ mod aio { assert_eq!("person", vertices[0].label()); } + + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_edge_query() { - let graph = connect().await; + async fn test_edge_query(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; let edges = graph .execute("g.E().hasLabel('knows').limit(1)", &[]) .await @@ -211,10 +221,11 @@ mod aio { assert_eq!("knows", edges[0].label()); } + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_vertex_creation() { - let graph = connect().await; + async fn test_vertex_creation(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; let mark = create_vertex(&graph, "mark").await; assert_eq!("person", mark.label()); @@ -237,10 +248,11 @@ mod aio { ); } + #[apply(common::serializers)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_edge_creation() { - let graph = connect().await; + async fn test_edge_creation(protocol: IoProtocol) { + let graph = connect_serializer(protocol).await; let mark = create_vertex(&graph, "mark").await; let frank = create_vertex(&graph, "frank").await; diff --git a/gremlin-client/tests/integration_client_async_v2.rs b/gremlin-client/tests/integration_client_async_v2.rs deleted file mode 100644 index f98d9249..00000000 --- a/gremlin-client/tests/integration_client_async_v2.rs +++ /dev/null @@ -1,174 +0,0 @@ -#[allow(dead_code)] -mod common; - -#[cfg(feature = "async_gremlin")] -mod aio { - - use gremlin_client::GremlinError; - use gremlin_client::{Edge, GValue, IoProtocol, Map, Vertex}; - - use super::common::aio::{connect_serializer, create_edge, create_vertex}; - #[cfg(feature = "async-std-runtime")] - use async_std::prelude::*; - - #[cfg(feature = "tokio-runtime")] - use tokio_stream::StreamExt; - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_client_connection_ok_v2() { - connect_serializer(IoProtocol::GraphSONV2).await; - } - - #[cfg(feature = "async-std-runtime")] - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - async fn test_empty_query_v2() { - let graph = connect_serializer(IoProtocol::GraphSONV2).await; - - assert_eq!( - 0, - graph - .execute("g.V().hasLabel('NotFound')", &[]) - .await - .expect("It should execute a traversal") - .count() - .await - ) - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_wrong_query_v2() { - let error = connect_serializer(IoProtocol::GraphSONV2) - .await - .execute("g.V", &[]) - .await - .expect_err("it should return an error"); - - match error { - GremlinError::Request((code, message)) => { - assert_eq!(597, code); - assert_eq!("No such property: V for class: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource",message) - } - _ => panic!("wrong error type"), - } - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_wrong_alias_v2() { - let error = connect_serializer(IoProtocol::GraphSONV2) - .await - .alias("foo") - .execute("g.V()", &[]) - .await - .expect_err("it should return an error"); - - match error { - GremlinError::Request((code, message)) => { - assert_eq!(499, code); - assert_eq!("Could not alias [g] to [foo] as [foo] not in the Graph or TraversalSource global bindings",message) - } - _ => panic!("wrong error type"), - } - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - - async fn test_vertex_query_v2() { - let graph = connect_serializer(IoProtocol::GraphSONV2).await; - - println!("About to execute query."); - let vertices = graph - .execute( - "g.V().hasLabel('person').has('name',name)", - &[("name", &"marko")], - ) - .await - .expect("it should execute a query") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .await - .expect("It should be ok"); - - assert_eq!("person", vertices[0].label()); - } - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_edge_query_v2() { - let graph = connect_serializer(IoProtocol::GraphSONV2).await; - let edges = graph - .execute("g.E().hasLabel('knows').limit(1)", &[]) - .await - .expect("it should execute a query") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .await - .expect("It should be ok"); - - assert_eq!("knows", edges[0].label()); - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_vertex_creation_v2() { - let graph = connect_serializer(IoProtocol::GraphSONV2).await; - let mark = create_vertex(&graph, "mark").await; - - assert_eq!("person", mark.label()); - - let value_map = graph - .execute("g.V(identity).valueMap()", &[("identity", mark.id())]) - .await - .expect("should fetch valueMap with properties") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .await - .expect("It should be ok"); - - assert_eq!(1, value_map.len()); - - assert_eq!( - Some(&GValue::List(vec![String::from("mark").into()].into())), - value_map[0].get("name") - ); - } - - #[cfg_attr(feature = "async-std-runtime", async_std::test)] - #[cfg_attr(feature = "tokio-runtime", tokio::test)] - async fn test_edge_creation_v2() { - let graph = connect_serializer(IoProtocol::GraphSONV2).await; - let mark = create_vertex(&graph, "mark").await; - let frank = create_vertex(&graph, "frank").await; - - let edge = create_edge(&graph, &mark, &frank, "knows").await; - - assert_eq!("knows", edge.label()); - - assert_eq!(&mark, edge.out_v()); - assert_eq!(&frank, edge.in_v()); - - let edges = graph - .execute("g.V(identity).outE()", &[("identity", mark.id())]) - .await - .expect("should fetch edge") - .filter_map(Result::ok) - .map(|f| f.take::()) - .collect::, _>>() - .await - .expect("It should be ok"); - - assert_eq!(1, edges.len()); - - let edge = &edges[0]; - - assert_eq!("knows", edge.label()); - - assert_eq!(&mark, edge.out_v()); - assert_eq!(&frank, edge.in_v()); - } -}