diff --git a/pinecone_sdk/tests/common.rs b/pinecone_sdk/tests/common.rs new file mode 100644 index 0000000..c4d320c --- /dev/null +++ b/pinecone_sdk/tests/common.rs @@ -0,0 +1,53 @@ +use pinecone_sdk::pinecone::data::Namespace; +use rand::Rng; + +/// Generates a random string of length 10 +pub fn generate_random_string() -> String { + use rand::distributions::Alphanumeric; + use rand::{thread_rng, Rng}; + + let s: String = thread_rng() + .sample_iter(&Alphanumeric) + .take(10) + .map(char::from) + .collect(); + + s.to_lowercase() +} + +/// Generates a random index name +pub fn generate_index_name() -> String { + format!("test-index-{}", generate_random_string()) +} + +/// Generates a random collection name +pub fn generate_collection_name() -> String { + format!("test-collection-{}", generate_random_string()) +} + +/// Generates a random namespace name +pub fn generate_namespace_name() -> Namespace { + let name = format!("test-namespace-{}", generate_random_string()); + name.into() +} + +/// Generates a random vector of length `length` +pub fn generate_vector(length: usize) -> Vec { + let mut rng = rand::thread_rng(); + (0..length).map(|_| rng.gen()).collect() +} + +/// Returns the name of the serverless index from the environment variable +pub fn get_serverless_index() -> String { + std::env::var("SERVERLESS_INDEX_NAME").unwrap() +} + +/// Returns the name of the pod collection from the environment variable +pub fn get_pod_index() -> String { + std::env::var("POD_INDEX_NAME").unwrap() +} + +/// Returns the name of the collection from the environment variable +pub fn get_collection() -> String { + std::env::var("COLLECTION_NAME").unwrap() +} diff --git a/pinecone_sdk/tests/integration_test_control.rs b/pinecone_sdk/tests/integration_test_control.rs new file mode 100644 index 0000000..1a2847c --- /dev/null +++ b/pinecone_sdk/tests/integration_test_control.rs @@ -0,0 +1,427 @@ +use common::{ + generate_collection_name, generate_index_name, get_collection, get_pod_index, + get_serverless_index, +}; +use openapi::models::index_model::Metric as OpenApiMetric; +use openapi::models::serverless_spec::Cloud as OpenApiCloud; +use pinecone_sdk::pinecone::control::{Cloud, Metric, WaitPolicy}; +use pinecone_sdk::pinecone::PineconeClient; +use pinecone_sdk::utils::errors::PineconeError; +use std::collections::HashMap; +use std::time::Duration; + +mod common; + +#[tokio::test] +async fn test_describe_index() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .describe_index(&get_serverless_index()) + .await + .expect("Failed to describe index"); + + Ok(()) +} + +#[tokio::test] +async fn test_describe_index_fail() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .describe_index("invalid-index") + .await + .expect_err("Expected to fail describing index"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_list_indexes() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let index1_name = &generate_index_name(); + let index2_name = &generate_index_name(); + + let _ = pinecone + .create_serverless_index( + index1_name, + 2, + Metric::Cosine, + Cloud::Aws, + "us-west-2", + WaitPolicy::NoWait, + ) + .await + .expect("Failed to create index"); + + let _ = pinecone + .create_serverless_index( + index2_name, + 2, + Metric::Dotproduct, + Cloud::Aws, + "us-west-2", + WaitPolicy::NoWait, + ) + .await + .expect("Failed to create index"); + + let index_list = pinecone + .list_indexes() + .await + .expect("Failed to list indexes"); + let indexes = index_list.indexes.unwrap(); + + let index1 = indexes + .iter() + .find(|index| index.name == index1_name.to_string()) + .unwrap(); + + assert_eq!(index1.name, index1_name.to_string()); + assert_eq!(index1.dimension, 2); + assert_eq!(index1.metric, OpenApiMetric::Cosine); + let spec1 = index1.spec.serverless.as_ref().unwrap(); + assert_eq!(spec1.cloud, OpenApiCloud::Aws); + assert_eq!(spec1.region, "us-west-2"); + + let index2 = indexes + .iter() + .find(|index| index.name == index2_name.to_string()) + .unwrap(); + + assert_eq!(index2.name, index2_name.to_string()); + assert_eq!(index2.dimension, 2); + assert_eq!(index2.metric, OpenApiMetric::Dotproduct); + let spec2 = index2.spec.serverless.as_ref().unwrap(); + assert_eq!(spec2.cloud, OpenApiCloud::Aws); + assert_eq!(spec2.region, "us-west-2"); + + let _ = pinecone + .delete_index(index1_name) + .await + .expect("Failed to delete index"); + + let _ = pinecone + .delete_index(index2_name) + .await + .expect("Failed to delete index"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_delete_index() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let name = &generate_index_name(); + + let response = pinecone + .create_serverless_index( + name, + 2, + Metric::Euclidean, + Cloud::Aws, + "us-west-2", + WaitPolicy::NoWait, + ) + .await + .expect("Failed to create index"); + + assert_eq!(response.name, name.to_string()); + assert_eq!(response.dimension, 2); + assert_eq!(response.metric, OpenApiMetric::Euclidean); + + let spec = response.spec.serverless.unwrap(); + assert_eq!(spec.cloud, OpenApiCloud::Aws); + assert_eq!(spec.region, "us-west-2"); + + let _ = pinecone + .delete_index(name) + .await + .expect("Failed to delete index"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_pod_index() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let name = &generate_index_name(); + + let response = pinecone + .create_pod_index( + name, + 2, + Metric::Euclidean, + "us-west1-gcp", + "p1.x1", + 1, + Some(1), + Some(1), + None, + None, + WaitPolicy::NoWait, + ) + .await + .expect("Failed to create index"); + + assert_eq!(response.name, name.to_string()); + assert_eq!(response.dimension, 2); + assert_eq!(response.metric, OpenApiMetric::Euclidean); + + let spec = response.spec.pod.unwrap(); + assert_eq!(spec.environment, "us-west1-gcp"); + assert_eq!(spec.replicas, Some(1)); + assert_eq!(spec.shards, Some(1)); + assert_eq!(spec.pod_type, "p1.x1"); + assert_eq!(spec.pods, 1); + assert_eq!(spec.source_collection, None); + + let _ = pinecone + .delete_index(name) + .await + .expect("Failed to delete index"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_pod_index_collection() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let name = &generate_index_name(); + + let response = pinecone + .create_pod_index( + name, + 12, + Metric::Euclidean, + "us-east-1-aws", + "p1.x1", + 1, + Some(1), + Some(1), + None, + Some("valid-collection"), + WaitPolicy::NoWait, + ) + .await + .expect("Failed to create index"); + + assert_eq!(response.name, name.to_string()); + assert_eq!(response.dimension, 12); + assert_eq!(response.metric, OpenApiMetric::Euclidean); + + let spec = response.spec.pod.unwrap(); + assert_eq!(spec.environment, "us-east-1-aws"); + assert_eq!(spec.replicas, Some(1)); + assert_eq!(spec.shards, Some(1)); + assert_eq!(spec.pod_type, "p1.x1"); + assert_eq!(spec.pods, 1); + assert_eq!(spec.source_collection, Some("valid-collection".to_string())); + + let _ = pinecone + .delete_index(name) + .await + .expect("Failed to delete index"); + + Ok(()) +} + +#[tokio::test] +async fn test_delete_index_err() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .delete_index("invalid-index") + .await + .expect_err("Expected to fail deleting invalid index"); + + Ok(()) +} + +#[tokio::test] +async fn test_configure_index() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .configure_index(&get_pod_index(), 1, "s1.x1") + .await + .expect("Failed to configure index"); + + Ok(()) +} + +#[tokio::test] +async fn test_configure_serverless_index_err() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .configure_index(&get_serverless_index(), 1, "p1.x1") + .await + .expect_err("Expected to fail configuring serverless index"); + + Ok(()) +} + +#[tokio::test] +async fn test_configure_invalid_index_err() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .configure_index("invalid-index", 2, "p1.x1") + .await + .expect_err("Expected to fail configuring invalid index"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_delete_collection() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let collection_name = generate_collection_name(); + + let index_name = &get_pod_index(); + loop { + if match pinecone.describe_index(index_name).await { + Ok(index) => index.status.ready, + Err(_) => false, + } { + break; + } + tokio::time::sleep(Duration::from_millis(1000)).await; + } + + let response = pinecone + .create_collection(&collection_name, index_name) + .await + .expect("Failed to create collection"); + + assert_eq!(response.name, collection_name.to_string()); + + let _ = pinecone + .delete_collection(&collection_name) + .await + .expect("Failed to delete collection"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_collection_serverless_err() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let collection_name = generate_collection_name(); + + let _ = pinecone + .create_collection(&collection_name, &get_serverless_index()) + .await + .expect_err("Expected to fail creating collection from serverless"); + + Ok(()) +} + +#[tokio::test] +async fn test_create_collection_invalid_err() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let collection_name = generate_collection_name(); + + let _ = pinecone + .create_collection(&collection_name, "invalid-index") + .await + .expect_err("Expected to fail creating collection from invalid index"); + + Ok(()) +} + +#[tokio::test] +async fn test_describe_collection() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let collection_name = &get_collection(); + + let _ = pinecone + .describe_collection(&collection_name) + .await + .expect("Failed to describe collection"); + + Ok(()) +} + +#[tokio::test] +async fn test_describe_collection_fail() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .describe_collection("invalid-collection") + .await + .expect_err("Expected to fail describing collection"); + + Ok(()) +} + +#[tokio::test] +async fn test_list_collections() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .list_collections() + .await + .expect("Failed to list collections"); + + Ok(()) +} + +#[tokio::test] +async fn test_list_collections_invalid_api_version() -> Result<(), PineconeError> { + let headers: HashMap = [( + pinecone_sdk::pinecone::PINECONE_API_VERSION_KEY.to_string(), + "invalid".to_string(), + )] + .iter() + .cloned() + .collect(); + + let pinecone = PineconeClient::new(None, None, Some(headers), None) + .expect("Failed to create Pinecone instance"); + + let _ = pinecone + .list_collections() + .await + .expect_err("Expected to fail listing collections due to invalid api version"); + + Ok(()) +} + +#[tokio::test] +async fn test_delete_collection_invalid_collection() -> Result<(), PineconeError> { + let pinecone = + PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); + + let _ = pinecone + .delete_collection("invalid-collection") + .await + .expect_err("Expected to fail deleting collection"); + + Ok(()) +} diff --git a/pinecone_sdk/tests/integration_test.rs b/pinecone_sdk/tests/integration_test_data.rs similarity index 54% rename from pinecone_sdk/tests/integration_test.rs rename to pinecone_sdk/tests/integration_test_data.rs index 5445783..334c926 100644 --- a/pinecone_sdk/tests/integration_test.rs +++ b/pinecone_sdk/tests/integration_test_data.rs @@ -1,472 +1,11 @@ -use openapi::models::index_model::Metric as OpenApiMetric; -use openapi::models::serverless_spec::Cloud as OpenApiCloud; -use pinecone_sdk::pinecone::control::{Cloud, Metric, WaitPolicy}; +use common::{generate_namespace_name, generate_vector, get_pod_index, get_serverless_index}; use pinecone_sdk::pinecone::data::{Kind, Metadata, Namespace, SparseValues, Value, Vector}; use pinecone_sdk::pinecone::PineconeClient; use pinecone_sdk::utils::errors::PineconeError; -use rand::Rng; -use std::collections::{BTreeMap, HashMap}; -use std::time::Duration; +use std::collections::BTreeMap; use std::vec; -// helpers to generate random test/collection names -fn generate_random_string() -> String { - use rand::distributions::Alphanumeric; - use rand::{thread_rng, Rng}; - - let s: String = thread_rng() - .sample_iter(&Alphanumeric) - .take(10) - .map(char::from) - .collect(); - - s.to_lowercase() -} - -fn generate_index_name() -> String { - format!("test-index-{}", generate_random_string()) -} - -fn generate_collection_name() -> String { - format!("test-collection-{}", generate_random_string()) -} - -fn generate_namespace_name() -> Namespace { - let name = format!("test-namespace-{}", generate_random_string()); - name.into() -} - -fn generate_vector(length: usize) -> Vec { - let mut rng = rand::thread_rng(); - (0..length).map(|_| rng.gen()).collect() -} - -// helper functions to get index names from environment variables -fn get_serverless_index() -> String { - std::env::var("SERVERLESS_INDEX_NAME").unwrap() -} - -fn get_pod_index() -> String { - std::env::var("POD_INDEX_NAME").unwrap() -} - -fn get_collection() -> String { - std::env::var("COLLECTION_NAME").unwrap() -} - -#[tokio::test] -async fn test_describe_index() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .describe_index(&get_serverless_index()) - .await - .expect("Failed to describe index"); - - Ok(()) -} - -#[tokio::test] -async fn test_describe_index_fail() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .describe_index("invalid-index") - .await - .expect_err("Expected to fail describing index"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_list_indexes() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let index1_name = &generate_index_name(); - let index2_name = &generate_index_name(); - - let _ = pinecone - .create_serverless_index( - index1_name, - 2, - Metric::Cosine, - Cloud::Aws, - "us-west-2", - WaitPolicy::NoWait, - ) - .await - .expect("Failed to create index"); - - let _ = pinecone - .create_serverless_index( - index2_name, - 2, - Metric::Dotproduct, - Cloud::Aws, - "us-west-2", - WaitPolicy::NoWait, - ) - .await - .expect("Failed to create index"); - - let index_list = pinecone - .list_indexes() - .await - .expect("Failed to list indexes"); - let indexes = index_list.indexes.unwrap(); - - let index1 = indexes - .iter() - .find(|index| index.name == index1_name.to_string()) - .unwrap(); - - assert_eq!(index1.name, index1_name.to_string()); - assert_eq!(index1.dimension, 2); - assert_eq!(index1.metric, OpenApiMetric::Cosine); - let spec1 = index1.spec.serverless.as_ref().unwrap(); - assert_eq!(spec1.cloud, OpenApiCloud::Aws); - assert_eq!(spec1.region, "us-west-2"); - - let index2 = indexes - .iter() - .find(|index| index.name == index2_name.to_string()) - .unwrap(); - - assert_eq!(index2.name, index2_name.to_string()); - assert_eq!(index2.dimension, 2); - assert_eq!(index2.metric, OpenApiMetric::Dotproduct); - let spec2 = index2.spec.serverless.as_ref().unwrap(); - assert_eq!(spec2.cloud, OpenApiCloud::Aws); - assert_eq!(spec2.region, "us-west-2"); - - let _ = pinecone - .delete_index(index1_name) - .await - .expect("Failed to delete index"); - - let _ = pinecone - .delete_index(index2_name) - .await - .expect("Failed to delete index"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_delete_index() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let name = &generate_index_name(); - - let response = pinecone - .create_serverless_index( - name, - 2, - Metric::Euclidean, - Cloud::Aws, - "us-west-2", - WaitPolicy::NoWait, - ) - .await - .expect("Failed to create index"); - - assert_eq!(response.name, name.to_string()); - assert_eq!(response.dimension, 2); - assert_eq!(response.metric, OpenApiMetric::Euclidean); - - let spec = response.spec.serverless.unwrap(); - assert_eq!(spec.cloud, OpenApiCloud::Aws); - assert_eq!(spec.region, "us-west-2"); - - let _ = pinecone - .delete_index(name) - .await - .expect("Failed to delete index"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_pod_index() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let name = &generate_index_name(); - - let response = pinecone - .create_pod_index( - name, - 2, - Metric::Euclidean, - "us-west1-gcp", - "p1.x1", - 1, - Some(1), - Some(1), - None, - None, - WaitPolicy::NoWait, - ) - .await - .expect("Failed to create index"); - - assert_eq!(response.name, name.to_string()); - assert_eq!(response.dimension, 2); - assert_eq!(response.metric, OpenApiMetric::Euclidean); - - let spec = response.spec.pod.unwrap(); - assert_eq!(spec.environment, "us-west1-gcp"); - assert_eq!(spec.replicas, Some(1)); - assert_eq!(spec.shards, Some(1)); - assert_eq!(spec.pod_type, "p1.x1"); - assert_eq!(spec.pods, 1); - assert_eq!(spec.source_collection, None); - - let _ = pinecone - .delete_index(name) - .await - .expect("Failed to delete index"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_pod_index_collection() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let name = &generate_index_name(); - - let response = pinecone - .create_pod_index( - name, - 12, - Metric::Euclidean, - "us-east-1-aws", - "p1.x1", - 1, - Some(1), - Some(1), - None, - Some("valid-collection"), - WaitPolicy::NoWait, - ) - .await - .expect("Failed to create index"); - - assert_eq!(response.name, name.to_string()); - assert_eq!(response.dimension, 12); - assert_eq!(response.metric, OpenApiMetric::Euclidean); - - let spec = response.spec.pod.unwrap(); - assert_eq!(spec.environment, "us-east-1-aws"); - assert_eq!(spec.replicas, Some(1)); - assert_eq!(spec.shards, Some(1)); - assert_eq!(spec.pod_type, "p1.x1"); - assert_eq!(spec.pods, 1); - assert_eq!(spec.source_collection, Some("valid-collection".to_string())); - - let _ = pinecone - .delete_index(name) - .await - .expect("Failed to delete index"); - - Ok(()) -} - -#[tokio::test] -async fn test_delete_index_err() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .delete_index("invalid-index") - .await - .expect_err("Expected to fail deleting invalid index"); - - Ok(()) -} - -#[tokio::test] -async fn test_configure_index() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .configure_index(&get_pod_index(), 1, "s1.x1") - .await - .expect("Failed to configure index"); - - Ok(()) -} - -#[tokio::test] -async fn test_configure_serverless_index_err() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .configure_index(&get_serverless_index(), 1, "p1.x1") - .await - .expect_err("Expected to fail configuring serverless index"); - - Ok(()) -} - -#[tokio::test] -async fn test_configure_invalid_index_err() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .configure_index("invalid-index", 2, "p1.x1") - .await - .expect_err("Expected to fail configuring invalid index"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_delete_collection() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let collection_name = generate_collection_name(); - - let index_name = &get_pod_index(); - loop { - if match pinecone.describe_index(index_name).await { - Ok(index) => index.status.ready, - Err(_) => false, - } { - break; - } - tokio::time::sleep(Duration::from_millis(1000)).await; - } - - let response = pinecone - .create_collection(&collection_name, index_name) - .await - .expect("Failed to create collection"); - - assert_eq!(response.name, collection_name.to_string()); - - let _ = pinecone - .delete_collection(&collection_name) - .await - .expect("Failed to delete collection"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_collection_serverless_err() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let collection_name = generate_collection_name(); - - let _ = pinecone - .create_collection(&collection_name, &get_serverless_index()) - .await - .expect_err("Expected to fail creating collection from serverless"); - - Ok(()) -} - -#[tokio::test] -async fn test_create_collection_invalid_err() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let collection_name = generate_collection_name(); - - let _ = pinecone - .create_collection(&collection_name, "invalid-index") - .await - .expect_err("Expected to fail creating collection from invalid index"); - - Ok(()) -} - -#[tokio::test] -async fn test_describe_collection() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let collection_name = &get_collection(); - - let _ = pinecone - .describe_collection(&collection_name) - .await - .expect("Failed to describe collection"); - - Ok(()) -} - -#[tokio::test] -async fn test_describe_collection_fail() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .describe_collection("invalid-collection") - .await - .expect_err("Expected to fail describing collection"); - - Ok(()) -} - -#[tokio::test] -async fn test_list_collections() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .list_collections() - .await - .expect("Failed to list collections"); - - Ok(()) -} - -#[tokio::test] -async fn test_delete_collection_invalid_collection() -> Result<(), PineconeError> { - let pinecone = - PineconeClient::new(None, None, None, None).expect("Failed to create Pinecone instance"); - - let _ = pinecone - .delete_collection("invalid-collection") - .await - .expect_err("Expected to fail deleting collection"); - - Ok(()) -} - -#[tokio::test] -async fn test_list_collections_invalid_api_version() -> Result<(), PineconeError> { - let headers: HashMap = [( - pinecone_sdk::pinecone::PINECONE_API_VERSION_KEY.to_string(), - "invalid".to_string(), - )] - .iter() - .cloned() - .collect(); - - let pinecone = PineconeClient::new(None, None, Some(headers), None) - .expect("Failed to create Pinecone instance"); - - let _ = pinecone - .list_collections() - .await - .expect_err("Expected to fail listing collections due to invalid api version"); - - Ok(()) -} +mod common; #[tokio::test] async fn test_index() -> Result<(), PineconeError> {