Skip to content

Commit

Permalink
Split integration test file (#42)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
emily-emily authored Jul 26, 2024
1 parent d01d51a commit 05ed9ff
Show file tree
Hide file tree
Showing 3 changed files with 483 additions and 464 deletions.
53 changes: 53 additions & 0 deletions pinecone_sdk/tests/common.rs
Original file line number Diff line number Diff line change
@@ -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<f32> {
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()
}
Loading

0 comments on commit 05ed9ff

Please sign in to comment.