Skip to content

chore: add environment variable override support for component tests - #4427

Merged
koladilip merged 3 commits into
developfrom
feat/component-tests-env-override-support
Jun 25, 2025
Merged

koladilip merged 3 commits into
developfrom
feat/component-tests-env-override-support

Conversation

@koladilip

@koladilip koladilip commented Jun 24, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

This PR adds environment variable override support for component tests, enabling per-test environment configuration without affecting other tests. The implementation follows component test patterns and integrates seamlessly into the existing test framework.

What is the related Linear task?

Part of INT-3615 - Breaking down large PR #4422 into smaller, manageable pieces.

Please explain the objectives of your changes below

This is the first of several smaller PRs to replace the large PR #4422. The objective is to provide a solid foundation for environment variable testing by:

Core Infrastructure

  • EnvManager Class: Manages environment variable snapshots and overrides with automatic cleanup
  • Component Test Integration: Seamlessly integrated into execution flow
  • Test Isolation: Per-test environment variable isolation with proper cleanup in finally blocks
  • Dynamic Evaluation: Runtime evaluation of environment variables for proper test isolation

Features

  • Automatic Snapshot & Restore: Environment variables are automatically saved and restored after each test
  • Variable Deletion Support: Use to delete environment variables during tests
  • Multiple Overrides: Support for multiple environment variable combinations in a single test
  • Backward Compatible: Existing tests continue to work unchanged

Usage

Add directly to test cases in your files:

{
  id: 'test-with-env-override',
  name: 'my_destination',
  description: 'Test with custom environment configuration',
  envOverrides: {
    API_BASE_URL: 'https://staging.api.com',
    DEBUG_MODE: 'true',
    LEGACY_FEATURE: undefined, // Deletes this env var
  },
  // ... rest of test case
}

Real Working Example

  • Added functional example in
  • Updated destination to support override
  • Demonstrates API endpoint override functionality with passing tests

Documentation

  • Comprehensive documentation added to main README
  • Best practices for dynamic vs static environment variable usage
  • Common environment variables and implementation details

Any changes to existing capabilities/behavior?

No breaking changes. All existing functionality remains unchanged:

  • Existing tests continue to work without modification
  • Component test execution flow enhanced but maintains backward compatibility
  • New property is optional and only used when specified

List any new dependencies added

No new dependencies added. Uses existing Node.js environment variable APIs.

Developer Notes

  • Environment variables are evaluated at runtime using functions instead of module load time for proper test isolation
  • The class provides thread-safe environment variable management
  • All environment variable changes are automatically cleaned up after test execution
  • The implementation follows existing component test patterns and conventions

The feature is immediately usable and demonstrates real-world scenarios for testing different configurations without affecting other tests.

@koladilip
koladilip requested a review from sivashanmukh as a code owner June 24, 2025 06:33
@koladilip
koladilip requested a review from a team June 24, 2025 06:33
@coderabbitai

coderabbitai Bot commented Jun 24, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • The service endpoint can now be configured via an environment variable, allowing for dynamic updates without code changes.

Walkthrough

The changes replace a static constant for the base endpoint URL with a function that retrieves the value at runtime, allowing for dynamic configuration via an environment variable. Related utility functions are updated to use the new function, ensuring endpoint resolution is now environment-dependent rather than hardcoded.

Changes

File(s) Change Summary
src/v0/destinations/rudder_test/config.ts Replaced the exported BASE_ENDPOINT constant with a getBaseEndpoint function for dynamic lookup.
src/v0/destinations/rudder_test/utils.ts Updated import and usage from BASE_ENDPOINT to getBaseEndpoint() in endpoint resolution logic.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment
    participant Config as config.ts
    participant Utils as utils.ts
    participant Destination as Destination

    Destination->>Utils: buildRequestConfig(destination)
    Utils->>Config: getBaseEndpoint()
    Config->>Env: Check RUDDER_TEST_API_ENDPOINT
    alt Env variable set
        Env-->>Config: Return env variable value
    else Env variable not set
        Config-->>Utils: Return default endpoint
    end
    Utils-->>Destination: Return request config with resolved endpoint
Loading

Suggested reviewers

  • sivashanmukh
  • krishna2020

Suggestions for improvement:
Consider adding unit tests to verify that the endpoint resolution behaves correctly under different environment configurations. Additionally, document the new environment variable in the relevant configuration or deployment guides to ensure discoverability for other developers.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Jun 24, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.14%. Comparing base (ab20435) to head (7af469f).
Report is 48 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4427      +/-   ##
===========================================
- Coverage    91.14%   91.14%   -0.01%     
===========================================
  Files          638      638              
  Lines        33478    33475       -3     
  Branches      7902     7903       +1     
===========================================
- Hits         30513    30510       -3     
  Misses        2696     2696              
  Partials       269      269              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Add comprehensive documentation for envOverrides usage in component tests
- Include examples for API endpoint override, debug mode, and feature flags
- Provide best practices for dynamic vs static environment variable usage
- Document common environment variables and implementation details
- Guide developers on proper usage to ensure test compatibility
@koladilip
koladilip force-pushed the feat/component-tests-env-override-support branch from 05c78cf to b083195 Compare June 24, 2025 06:47
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

…mework

- Move envUtils.ts to test/integrations/ directory alongside testUtils.ts
- Integrate EnvManager into component.test.ts execution flow
- Add environment variable handling with proper cleanup in finally blocks
- Update rudder_test destination to support dynamic RUDDER_TEST_API_ENDPOINT override
- Use runtime function evaluation instead of module load time for proper test isolation
- Add working example test case in rudder_test processor data.ts
- Update main README with comprehensive environment variable override documentation
- Follow component test patterns by using data.ts files only

Environment variable overrides now work seamlessly in component tests with:
- Automatic snapshot and restore of environment variables
- Per-test isolation with proper cleanup
- Real working example demonstrates API endpoint override functionality
- Dynamic evaluation ensures environment changes take effect during test execution
@koladilip
koladilip requested a review from a team as a code owner June 24, 2025 07:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/v0/destinations/rudder_test/utils.ts (1)

29-30: Function call implementation looks good with minor performance consideration.

The implementation correctly calls getBaseEndpoint() to enable runtime environment variable configuration. Note that this reads the environment variable on every function call, which is acceptable for the testing use case and aligns with the requirement for per-test environment variable overrides.

Consider caching the environment variable value if buildRequestConfig becomes a performance bottleneck in high-volume scenarios, though this is likely unnecessary for the current testing use case.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa7e9d9 and 603d06f.

⛔ Files ignored due to path filters (6)
  • README.md is excluded by !**/*.md
  • test/integrations/component.test.ts is excluded by !**/test/**
  • test/integrations/destinations/rudder_test/processor/data.ts is excluded by !**/test/**
  • test/integrations/envUtils.ts is excluded by !**/test/**
  • test/integrations/testTypes.ts is excluded by !**/test/**
  • test/integrations/utils/envUtils.README.md is excluded by !**/*.md, !**/test/**
📒 Files selected for processing (2)
  • src/v0/destinations/rudder_test/config.ts (1 hunks)
  • src/v0/destinations/rudder_test/utils.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/v0/destinations/rudder_test/config.ts (1)

1-4: LGTM! Clean implementation of runtime environment variable override.

The conversion from a static constant to a runtime function perfectly aligns with the PR objective of enabling environment variable overrides for component tests. The implementation is clean, well-documented, and maintains backward compatibility with the fallback URL.

src/v0/destinations/rudder_test/utils.ts (1)

2-2: Correct import update for the new function-based approach.

The import change properly reflects the transition from a static constant to a dynamic function.

The documentation has been integrated into the main README.md file,
so the separate documentation file is no longer needed.
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

koladilip added a commit that referenced this pull request Jun 24, 2025
- Remove test/integrations/__tests__/exampleUsage.test.ts (not required)
- Remove test/integrations/utils/ directory to avoid conflicts with PR #4427
- Update README to reference correct envUtils.ts path from PR #4427
- Ensure this PR focuses only on integration test framework utilities
@koladilip koladilip changed the title feat: add environment variable override support for component tests chore: add environment variable override support for component tests Jun 25, 2025
@koladilip
koladilip enabled auto-merge (squash) June 25, 2025 04:19
@koladilip
koladilip requested a review from utsabc June 25, 2025 04:19
@koladilip
koladilip merged commit 8f87ba0 into develop Jun 25, 2025
@koladilip
koladilip deleted the feat/component-tests-env-override-support branch June 25, 2025 04:33
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