Skip to content

Conversation

@goruha
Copy link
Contributor

@goruha goruha commented Apr 3, 2025

What

  • Add basic component test
  • Add disabled component test
  • Test component drifting
  • Add any additional use case tests

Why

  • Test basic component features
  • Verify that the component does not create any resources when input enabled: false set
  • Verify that the component does not drift on a second run with the same inputs
  • Add test for any additional than basic use cases for the component

References

Summary by CodeRabbit

  • New Features

    • Introduced new configuration files that enhance CLI settings and infrastructure deployments, including account mapping, cluster setup, component settings, and vendor dependency management.
  • Chores

    • Upgraded the eks module to a newer version and streamlined internal variable handling for improved efficiency.
  • Tests

    • Expanded test coverage with a comprehensive component test suite and updated test configurations.
    • Removed an obsolete test runner script.

@goruha goruha requested review from a team as code owners April 3, 2025 21:44
@goruha goruha linked an issue Apr 3, 2025 that may be closed by this pull request
4 tasks
@coderabbitai
Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request updates Terraform configurations and expands testing and configuration files. In the Terraform provider configuration, the intermediate local variable for the role ARN has been removed, and its logic is now applied directly. The eks module version has been upgraded. Additionally, multiple new YAML configuration files have been added in test fixtures for CLI, VPC, EKS cluster, use cases, organization defaults, and vendor settings. A new Go module file for tests has been introduced while a test script file has been removed.

Changes

File(s) Change Summary
src/provider-helm.tf, src/remote-state.tf Simplified Terraform config: Removed intermediate kube_exec_auth_role_arn variable in provider-helm and upgraded eks module version from "1.5.0" to "1.8.0".
test/.gitignore New file added with patterns to ignore state directories, cache files, and test artifacts.
test/component_test.go New test suite ComponentSuite added with methods for basic and enabled flag tests, plus setup and run functions.
test/fixtures/.../*.yaml New YAML configuration files added for CLI settings (atmos.yaml), account maps, EKS cluster, reloader use cases (basic and disabled), VPC, org defaults/tests, and vendor configuration.
test/go.mod New Go module file with specified Go version, toolchain, dependencies, and a replace directive.
test/run.sh Removed test script that previously echoed a test message.

Sequence Diagram(s)

sequenceDiagram
    participant TF as Terraform Config
    participant Var as kube_exec_auth_role_arn
    participant IAM as module.iam_roles.terraform_role_arn
    TF->>Var: Check for role ARN
    alt Role ARN is provided
        Var-->>TF: Return value
    else Role ARN is not provided
        TF->>IAM: Fallback to IAM role ARN
        IAM-->>TF: Return IAM role ARN
    end
Loading
sequenceDiagram
    participant Runner as TestRunSuite
    participant Suite as ComponentSuite
    participant Helper as helper.Run
    Runner->>Suite: Initialize ComponentSuite
    Suite->>Suite: Run SetupSuite() (configure test env)
    Runner->>Suite: Execute TestBasic() & TestEnabledFlag()
    Suite->>Helper: Run test suite with dependencies ("vpc", "eks/cluster")
    Helper-->>Runner: Return test results
Loading

Poem

I'm a rabbit with a spring in my code-filled hop,
Skipping through Terraform changes that never stop.
I nibble on YAML files, crisp and bright,
And bounce through tests in the soft daylight.
With each pull request, my ears perk anew,
Hopping happy with every change that's true!

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@goruha goruha changed the title Added tests Add component tests Apr 3, 2025
@mergify
Copy link

mergify bot commented Apr 3, 2025

Important

Description is necessary and should not be empty.

Kindly provide details with what was changed, why it was changed.

@mergify
Copy link

mergify bot commented Apr 3, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require terratest

Wonderful, this rule succeeded.

This rule require terratest status

  • check-success = test/terratest

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (11)
test/fixtures/stacks/catalog/usecase/basic.yaml (1)

1-15: EKS Reloader Basic Configuration YAML
This configuration for the "eks/reloader/basic" component is well-structured, specifying essential metadata and variable settings for deploying the reloader. However, YAMLlint has flagged that there is no newline at the end of this file (line 15). Please add a newline at the end for compliance with YAML best practices.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 15-15: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/stacks/catalog/usecase/disabled.yaml (1)

1-15: YAML Structure and Trailing Newline

The configuration is structured clearly to disable the EKS reloader, and the mapping for metadata and variables is self-explanatory. Please add a newline at the end of the file (after line 15) to satisfy YAML linting rules.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 15-15: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/vendor.yaml (1)

1-43: Comprehensive Vendor Configuration

The AtmosVendorConfig manifests are well-defined. All sources, targets, and included/excluded path patterns are clearly specified. As a minor nitpick, please verify that the version strings and source paths (which appear as GitHub repository references) follow your project's standard conventions and include a trailing newline if needed.

test/fixtures/stacks/catalog/account-map.yaml (1)

1-47: Account-Map YAML Clarity

The account-map configuration is clear and well-organized. The metadata, variables, and the static remote state backend structure are appropriately defined. The commented-out section provides useful context for internal use and legacy configuration. Please ensure a trailing newline at the end of the file for uniformity.

test/fixtures/stacks/orgs/default/test/_defaults.yaml (1)

1-67: Robust Default Configuration

This defaults file delivers a comprehensive setup for Terraform backend configuration and variable management. The templated expressions using getenv and the structured definitions of label orders and descriptor formats are well done. Once again, ensure that the file terminates with a newline to align with YAML best practices.

src/provider-helm.tf (1)

136-138: Streamlined exec_role Assignment

Directly embedding the coalesce function within the exec_role list improves clarity by eliminating an unnecessary intermediate local variable. Confirm that all consumers of the provider have been updated to work with this inline expression.

test/component_test.go (1)

21-21: Remove the unused constant awsRegion.

The variable awsRegion is declared but never used in your test code. Consider removing it to improve code cleanliness.

-	const awsRegion = "us-east-2"
🧰 Tools
🪛 golangci-lint (1.64.8)

21-21: const awsRegion is unused

(unused)

test/go.mod (1)

17-17: Uncomment or remove the replace directive.

The replace directive for aws-nuke is commented out. Either uncomment it if it's needed or remove it entirely to maintain a clean configuration file.

-// replace github.com/rebuy-de/aws-nuke/v2/mocks => github.com/ekristen/aws-nuke/v3/ v3.29.0
+replace github.com/rebuy-de/aws-nuke/v2/mocks => github.com/ekristen/aws-nuke/v3/ v3.29.0

or

-// replace github.com/rebuy-de/aws-nuke/v2/mocks => github.com/ekristen/aws-nuke/v3/ v3.29.0
test/fixtures/stacks/catalog/eks-cluster.yaml (2)

94-94: Add a newline at the end of the file.

The file is missing a newline character at the end. This is a common best practice and is flagged by linters.

 aws-efs-csi-driver:
   addon_version: "v2.0.8-eksbuild.1"
+
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 94-94: no new line character at the end of file

(new-line-at-end-of-file)


82-94: Consider adding descriptions for EKS add-ons.

The EKS add-ons section lists version numbers without any comments explaining their purpose or why specific versions were chosen. Adding brief comments about each add-on would improve code documentation.

 addons:
   vpc-cni:
+    # Amazon VPC CNI plugin for pod networking
     addon_version: "v1.18.3-eksbuild.3"
   kube-proxy:
+    # Maintains network rules on nodes
     addon_version: "v1.30.3-eksbuild.5"
   coredns:
+    # DNS service for Kubernetes
     addon_version: "v1.11.3-eksbuild.1"
     configuration_values: '{"autoScaling":{"enabled":true,"minReplicas":3}}'
   aws-ebs-csi-driver:
+    # EBS CSI driver for persistent volumes
     addon_version: "v1.34.0-eksbuild.1"
     configuration_values: '{"sidecars":{"snapshotter":{"forceEnable":false}}}'
   aws-efs-csi-driver:
+    # EFS CSI driver for persistent volumes
     addon_version: "v2.0.8-eksbuild.1"
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 94-94: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/atmos.yaml (1)

18-18: Consider setting a base_path for better standardization.

The base_path is currently set to an empty string. Setting a consistent base path could help standardize paths across different environments and make the configuration more portable.

-base_path: ""
+base_path: "test/fixtures"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba00f3d and cf89060.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • src/provider-helm.tf (1 hunks)
  • src/remote-state.tf (1 hunks)
  • test/.gitignore (1 hunks)
  • test/component_test.go (1 hunks)
  • test/fixtures/atmos.yaml (1 hunks)
  • test/fixtures/stacks/catalog/account-map.yaml (1 hunks)
  • test/fixtures/stacks/catalog/eks-cluster.yaml (1 hunks)
  • test/fixtures/stacks/catalog/usecase/basic.yaml (1 hunks)
  • test/fixtures/stacks/catalog/usecase/disabled.yaml (1 hunks)
  • test/fixtures/stacks/catalog/vpc.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/_defaults.yaml (1 hunks)
  • test/fixtures/stacks/orgs/default/test/tests.yaml (1 hunks)
  • test/fixtures/vendor.yaml (1 hunks)
  • test/go.mod (1 hunks)
  • test/run.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • test/run.sh
🧰 Additional context used
🪛 YAMLlint (1.35.1)
test/fixtures/stacks/catalog/usecase/basic.yaml

[error] 15-15: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/stacks/catalog/usecase/disabled.yaml

[error] 15-15: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/stacks/catalog/eks-cluster.yaml

[error] 94-94: no new line character at the end of file

(new-line-at-end-of-file)

🪛 golangci-lint (1.64.8)
test/component_test.go

21-21: const awsRegion is unused

(unused)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (15)
src/remote-state.tf (1)

3-3: Module Version Upgrade to 1.8.0
The module version in the remote-state configuration has been updated from "1.5.0" to "1.8.0". Please verify that this upgrade is compatible with the rest of your Terraform configuration and that any potential breaking changes or new features have been accounted for.

test/.gitignore (1)

1-5: New .gitignore for Test Directory
The .gitignore file in the test directory now correctly excludes directories and files such as state/, .cache, test/test-suite.json, .atmos, and test_suite.yaml. This will help prevent cluttering the repository with temporary or test-related artifacts.

test/fixtures/stacks/orgs/default/test/tests.yaml (1)

1-7: Test Imports Configuration
This YAML file lists the necessary import paths for test configurations, including defaults and catalog components (vpc, eks-cluster, basic, and disabled use cases). Ensure that each specified path exists and that the imported configurations are properly maintained.

test/fixtures/stacks/catalog/vpc.yaml (1)

1-20: VPC Configuration YAML
The new VPC configuration is clear and comprehensive; it defines metadata and variables such as availability zones, NAT gateway settings, and CIDR blocks. One point to verify: the comment on line 13 states that "Private subnets do not need internet access," which should be consistent with the enabled NAT gateway (line 14). Please double-check that this comment correctly describes the intended configuration.

src/provider-helm.tf (3)

164-173: Dynamic Exec Block in Helm Provider

The dynamic block that configures the exec parameters for the Helm provider is well implemented—it conditionally includes the exec configuration only when kube_exec_auth_enabled is true and certificate data is available. This approach enhances flexibility.


190-198: Consistent Dynamic Exec Block in Kubernetes Provider

Similarly, the dynamic block for the Kubernetes provider mirrors the Helm provider configuration, ensuring consistency across providers. This uniform structure aids maintainability and reduces confusion.


75-80:

❓ Verification inconclusive

Deprecation Notice for kube_exec_auth_role_arn Variable

While the new inline coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn) logic in the exec_role assignment simplifies the code, the public variable kube_exec_auth_role_arn is still declared. If this variable is no longer needed externally, please consider deprecating or removing it and updating the module’s documentation accordingly.


#!/bin/bash
# Verify usage of the variable 'kube_exec_auth_role_arn' across the repository.
# This command will search for all occurrences of the variable name to see if external dependencies exist.
rg "kube_exec_auth_role_arn" -n .

Deprecation Suggestion for kube_exec_auth_role_arn Variable

The new inline logic using coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn) in the exec_role assignment helps simplify the configuration, yet the public variable kube_exec_auth_role_arn remains declared in src/provider-helm.tf (lines 75–80).
Before removing or deprecating this variable, please verify whether any external dependencies rely on it. If it is indeed unused externally or redundant due to the inline logic, consider deprecating or removing the variable and updating the module’s documentation accordingly.

test/component_test.go (4)

18-52: Your implementation of TestBasic looks good.

The test properly validates critical metadata of the "eks/reloader/basic" component including app version, chart name, timestamps, and namespace. The test also includes cleanup with defer s.DestroyAtmosComponent and performs a drift test to ensure the deployed component matches the expected state.

🧰 Tools
🪛 golangci-lint (1.64.8)

21-21: const awsRegion is unused

(unused)


54-58: Good implementation of TestEnabledFlag.

The test properly verifies the enabled flag for the "eks/reloader/disabled" component using the helper method VerifyEnabledFlag.


60-64: Well-structured SetupSuite method.

The SetupSuite method correctly initializes the test configuration and sets the component destination directory path.


66-71: TestRunSuite properly sets up test dependencies.

The function correctly creates a new ComponentSuite instance and adds necessary dependencies for "vpc" and "eks/cluster" before running the suite.

test/fixtures/stacks/catalog/eks-cluster.yaml (2)

52-58: Consider enabling Fargate profiles for Karpenter.

The Fargate profiles configuration is commented out but might be necessary for Karpenter functionality. If this is intentional, consider adding a comment explaining why it's disabled or if it should be enabled in certain scenarios.

Is Karpenter functionality important for your test cases? If so, you may need to uncomment and properly configure the Fargate profiles section.


1-94: Well-structured EKS cluster configuration.

The configuration file provides a comprehensive setup for an EKS cluster with appropriate settings for node groups, access control, add-ons, and security. The organization of sections with explanatory comments makes the configuration clear and maintainable.

🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 94-94: no new line character at the end of file

(new-line-at-end-of-file)

test/fixtures/atmos.yaml (2)

58-60: Consider more flexible log configuration.

The log file is set to "/dev/stdout" which works on Linux/Unix systems but might not be compatible with Windows environments. Consider adding a comment about platform compatibility or providing conditional configuration.

If your tests need to run on Windows, you might want to use a more platform-independent logging approach.


1-78: Well-documented configuration file with comprehensive settings.

The Atmos configuration file includes detailed comments explaining each setting and alternative ways to specify values (env vars, command-line args). This is excellent practice for maintainability and onboarding new developers.

@goruha
Copy link
Contributor Author

goruha commented Apr 3, 2025

/terratest

@goruha goruha merged commit 89a6b4f into main Apr 4, 2025
19 checks passed
@goruha goruha deleted the add-tests branch April 4, 2025 06:32
@github-actions
Copy link

github-actions bot commented Apr 4, 2025

These changes were released in v1.536.1.

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.

Add component tests

2 participants