Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore environment variables to original state after tests #6

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

emily-emily
Copy link
Contributor

@emily-emily emily-emily commented Jun 11, 2024

Problem

The current tests manipulate environment variables and do not restore the original values after execution. This can cause problems for subsequent tests, eg. when the env var overrides something important or is intentionally set to an invalid value for the test.

Solution

This PR introduces the temp_env crate, which restores original environment variable values after the given scope. It uses a mutex to lock the variables so they cannot be concurrently accessed during the tests.

Test cases were also updated to to use a Result return type.

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 tests pass with the updated environment variable code.

@emily-emily emily-emily self-assigned this Jun 11, 2024
Copy link
Contributor

@austin-denoble austin-denoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, and nice considerations around the approach to testing and considering test pollution. I think given what we're trying to test in terms of creating a new Pinecone struct this makes a lot of sense.

For reference, I had to do something similar with environment variables in our Go tests to make sure I was setting something for the test, and then unsetting before continuing: https://github.com/pinecone-io/go-pinecone/blob/257e9f6453ff41ce32bca1eff55687ef96432bab/pinecone/client_test.go#L237

pinecone_sdk/src/pinecone.rs Show resolved Hide resolved
Copy link
Contributor

@ericapywang ericapywang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@emily-emily emily-emily merged commit 5016374 into main Jun 12, 2024
2 checks passed
@emily-emily emily-emily deleted the emily/restore-environment-variables branch June 12, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants