Skip to content

Commit 05ed9ff

Browse files
authored
Split integration test file (#42)
## Problem Currently all of our integration tests are included in a single file, making it hard to navigate and read. ## Solution This PR splits the integration tests into multiple files: `common.rs` for common helper code (eg. generate index name), and two files for control plane and data plane integration tests. ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [ ] Infrastructure change (CI configs, etc) - [ ] Non-code change (docs, etc) - [ ] None of the above: (explain here) ## Test Plan All existing test cases pass
1 parent d01d51a commit 05ed9ff

File tree

3 files changed

+483
-464
lines changed

3 files changed

+483
-464
lines changed

pinecone_sdk/tests/common.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use pinecone_sdk::pinecone::data::Namespace;
2+
use rand::Rng;
3+
4+
/// Generates a random string of length 10
5+
pub fn generate_random_string() -> String {
6+
use rand::distributions::Alphanumeric;
7+
use rand::{thread_rng, Rng};
8+
9+
let s: String = thread_rng()
10+
.sample_iter(&Alphanumeric)
11+
.take(10)
12+
.map(char::from)
13+
.collect();
14+
15+
s.to_lowercase()
16+
}
17+
18+
/// Generates a random index name
19+
pub fn generate_index_name() -> String {
20+
format!("test-index-{}", generate_random_string())
21+
}
22+
23+
/// Generates a random collection name
24+
pub fn generate_collection_name() -> String {
25+
format!("test-collection-{}", generate_random_string())
26+
}
27+
28+
/// Generates a random namespace name
29+
pub fn generate_namespace_name() -> Namespace {
30+
let name = format!("test-namespace-{}", generate_random_string());
31+
name.into()
32+
}
33+
34+
/// Generates a random vector of length `length`
35+
pub fn generate_vector(length: usize) -> Vec<f32> {
36+
let mut rng = rand::thread_rng();
37+
(0..length).map(|_| rng.gen()).collect()
38+
}
39+
40+
/// Returns the name of the serverless index from the environment variable
41+
pub fn get_serverless_index() -> String {
42+
std::env::var("SERVERLESS_INDEX_NAME").unwrap()
43+
}
44+
45+
/// Returns the name of the pod collection from the environment variable
46+
pub fn get_pod_index() -> String {
47+
std::env::var("POD_INDEX_NAME").unwrap()
48+
}
49+
50+
/// Returns the name of the collection from the environment variable
51+
pub fn get_collection() -> String {
52+
std::env::var("COLLECTION_NAME").unwrap()
53+
}

0 commit comments

Comments
 (0)