Skip to content

chore: add tests #16

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

Merged
merged 2 commits into from
Apr 2, 2025
Merged

chore: add tests #16

merged 2 commits into from
Apr 2, 2025

Conversation

RoseSecurity
Copy link
Contributor

@RoseSecurity RoseSecurity commented Mar 31, 2025

what

  • Add basic component test
  • Add disabled component test
  • Test component drifting

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

references

Summary by CodeRabbit

  • Tests
    • Added a new test suite that validates component deployments, parameter provisioning, and proper handling of enabled/disabled state flags.
  • Configuration
    • Introduced a comprehensive CLI configuration supporting customizable settings for directories, logging, component behavior, and workflows.
    • Added new YAML configurations for managing Terraform account mappings and SSM parameter components.
    • Implemented vendor configuration to streamline external component sourcing.
  • Chores
    • Updated dependency management and removed an obsolete test script to improve maintenance.

@RoseSecurity RoseSecurity requested review from a team as code owners March 31, 2025 16:54
@RoseSecurity
Copy link
Contributor Author

/terratest

Copy link

coderabbitai bot commented Mar 31, 2025

Walkthrough

This pull request introduces a new test suite in test/component_test.go with methods to verify component deployments and enabled flags. Several YAML configuration files are added to define CLI settings, Terraform component details, account mappings, and vendor configuration. Additionally, a new Go module file is included to manage dependencies, and an obsolete Bash script (test/run.sh) has been removed.

Changes

File(s) Change Summary
test/component_test.go New ComponentSuite added with test methods TestBasic, TestEnabledFlag, and the test runner function TestRunSuite.
test/fixtures/atmos.yaml New CLI configuration file defining the loading hierarchy and base paths for components, stacks, and workflows.
test/fixtures/stacks/catalog/* New YAML files: account-map.yaml for Terraform account mappings and usecase/basic.yaml, usecase/disabled.yaml for SSM parameter components.
test/fixtures/stacks/orgs/default/test/* New YAML configuration files: _defaults.yaml for Terraform backend defaults and tests.yaml that imports various configurations.
test/fixtures/vendor.yaml New Atmos vendor configuration specifying source repository, version, target directory, and file inclusion paths.
test/go.mod New Go module file declared with Go version 1.23.0 and dependencies including test helpers, terratest, and AWS SDK libraries.
test/run.sh Removed the Bash script that previously printed a simple test message.

Sequence Diagram(s)

sequenceDiagram
    participant TF as Testing Framework
    participant TR as TestRunSuite
    participant HS as helper.Run
    participant CS as ComponentSuite
    participant AWS as AWS Environment

    TF->>TR: Initiate test execution
    TR->>HS: Run ComponentSuite tests
    HS->>CS: Instantiate ComponentSuite
    CS->>AWS: Deploy 'ssm-parameter/basic' during TestBasic
    AWS-->>CS: Return parameter details and status
    CS->>CS: Verify outputs and drift
    CS->>AWS: Check enabled flag in TestEnabledFlag
    AWS-->>CS: Return enabled flag status
    CS->>HS: Complete test execution
Loading

Poem

Oh, what a hop, a code delight,
I’m a bunny celebrating tests so bright,
YAMLs and modules come into view,
Each new config makes my whiskers brew,
With every leap, our code sings true—
Hoppy trails and bugs adieu!
🐇🎉

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

Copy link

mergify bot commented Mar 31, 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: 3

🧹 Nitpick comments (7)
test/go.mod (2)

15-15: Uncomment or remove the replace directive

The replace directive for aws-nuke is commented out, which leaves it in an ambiguous state.

-// 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

Alternatively, if the directive is not needed, consider removing it entirely.


17-17: Use consistent dependency organization pattern

The github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 dependency is placed separately between two require blocks instead of being included with other direct dependencies.

-require github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.43.12
-
-require (
+require (
+	github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.43.12

Also applies to: 19-133

test/component_test.go (3)

25-26: Add timeout or context to GetParameter call

The GetParameter function doesn't specify a timeout or context, which could cause tests to hang indefinitely if there are AWS connectivity issues.

-	createdParam := aws.GetParameter(s.T(), awsRegion, "/dev/testing")
+	// Add timeout or context to prevent test from hanging
+	createdParam := aws.GetParameter(s.T(), awsRegion, "/dev/testing")

Consider using the Terratest context package to add timeouts to AWS calls.


31-31: Document DriftTest's purpose

Add a comment explaining what DriftTest is checking for and why it's important to include in the test.

-	s.DriftTest(component, stack, nil)
+	// Verify that applying the component again with the same inputs doesn't result in any changes,
+	// confirming idempotence and consistent state
+	s.DriftTest(component, stack, nil)

34-38: Expand TestEnabledFlag to validate resources are not created

The TestEnabledFlag test only calls VerifyEnabledFlag but doesn't explicitly verify that no resources were created when the component is disabled.

func (s *ComponentSuite) TestEnabledFlag() {
	const component = "ssm-parameter/disabled"
	const stack = "default-test"
	s.VerifyEnabledFlag(component, stack, nil)
+
+	// Verify that no SSM parameters were created when component is disabled
+	const awsRegion = "us-east-2"
+	exists := aws.ParameterExistsE(s.T(), awsRegion, "/dev/testing")
+	assert.False(s.T(), exists, "Parameter should not exist when component is disabled")
}
test/fixtures/stacks/orgs/default/test/_defaults.yaml (1)

8-9: Use consistent state path variable

The state path uses COMPONENT_HELPER_STATE_DIR environment variable with a hardcoded default fallback path, which could lead to state files being created in unexpected locations.

-      path: '{{ getenv "COMPONENT_HELPER_STATE_DIR" | default "../../../state" }}/{{ .component }}/terraform.tfstate'
-      workspace_dir: '{{ getenv "COMPONENT_HELPER_STATE_DIR" | default "../../../state" }}/{{ .component }}/'
+      path: '{{ getenv "COMPONENT_HELPER_STATE_DIR" | default "/tmp/terraform-test-state" }}/{{ .component }}/terraform.tfstate'
+      workspace_dir: '{{ getenv "COMPONENT_HELPER_STATE_DIR" | default "/tmp/terraform-test-state" }}/{{ .component }}/'

A temporary directory would be more appropriate to ensure tests don't interfere with each other when run in parallel.

test/fixtures/atmos.yaml (1)

58-60: Consider enabling Debug logs for tests

Setting the log level to "Info" for tests might not provide enough details when troubleshooting test failures.

logs:
  file: "/dev/stdout"
  # Supported log levels: Trace, Debug, Info, Warning, Off
-  level: Info
+  level: Debug
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3cd9933 and dceb35e.

⛔ Files ignored due to path filters (1)
  • test/go.sum is excluded by !**/*.sum
📒 Files selected for processing (10)
  • 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/usecase/basic.yaml (1 hunks)
  • test/fixtures/stacks/catalog/usecase/disabled.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
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
🔇 Additional comments (8)
test/fixtures/stacks/orgs/default/test/tests.yaml (1)

1-4: YAML Imports Defined Correctly.
The file correctly imports the default test settings and the two SSM parameter component use cases, ensuring that the test suite has access to the required configurations.

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

1-14: Disabled SSM Parameter Configuration is Well-Structured.
This new YAML file properly configures the disabled SSM parameter component. The enabled: false flag and parameter details (including value, description, overwrite, and type) are clearly defined.

test/fixtures/vendor.yaml (1)

1-19: Vendor Configuration File Looks Solid.
The Atmos vendor configuration is clearly specified with the correct API version, kind, metadata, and source details. Please verify that the version "1.520.0" is current and intentional.

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

1-14: Basic SSM Parameter Component is Configured Properly.
This YAML file sets up the basic SSM parameter component with enabled: true and provides all the necessary parameter definitions. The structure is clear and consistent with the other component configurations.

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

1-47: Account-Map Configuration is Detailed and Clear.
The account-map YAML file includes a comprehensive setup for Terraform with proper metadata and variable definitions. The static remote state backend configuration for testing is well separated from the commented-out production settings.
Ensure that the commented-out sections do not cause confusion in a production context and that the static configuration meets all test requirements.

test/go.mod (1)

3-3:

❓ Verification inconclusive

Verify Go version compatibility

The module specifies Go version 1.23.0, which might be a future version not yet released (latest official release is 1.22.x as of March 2024).


🌐 Web query:

What is the latest version of Go programming language?

💡 Result:

The latest stable version of the Go programming language is 1.24.1, released on March 4, 2025[2][3]. This minor revision includes security fixes for the net/http package and bug fixes across various components like the compiler, go command, and runtime[2][5].

Key points about Go releases:

  • Major releases follow a biannual cycle (e.g., Go 1.23 in August 2024, Go 1.24 in February 2025)[2][4]
  • Each major version receives security updates and bug fixes until two subsequent versions are released[2][3]
  • The language maintains strict backward compatibility under its Go 1 promise[3][4]

Notable features in recent updates include:

  • Enhanced security in core packages (crypto/x509, net/http)[2]
  • New compilation targets including experimental RISC-V support[4]
  • Improved toolchain with expanded go vet checks and tracing capabilities[4]

While Exercism's Go track currently uses 1.21.1 for its test runner, full support for 1.24.x features requires updating local installations[1]. Users can download the latest version from the official Go website[5].


Go emphasizes stability through its versioning policy (go1.[major].[patch] format) and long-term support cycle[3][4]. The language continues to prioritize backwards compatibility while gradually introducing performance optimizations and security improvements[2][3].

Citations:


Review Go Version Compatibility: Please verify the module’s intended version

  • The file test/go.mod currently specifies go 1.23.0, which, as of March 2025, is a released version.
  • Note that the latest stable Go release is 1.24.1 (released on March 4, 2025), which includes additional security fixes and improvements.
  • Please confirm that using Go 1.23.0 is intentional. If you aim to leverage the latest features and enhancements, consider updating the Go version in the module.
test/component_test.go (1)

40-43: LGTM: Test entrypoint is properly implemented

The TestRunSuite function correctly sets up and runs the test suite.

test/fixtures/atmos.yaml (1)

42-46:

✅ Verification successful

Review stack inclusion/exclusion patterns

The current configuration includes all paths under "orgs/**/*" but excludes "_defaults.yaml" files. Ensure this matches the intended directory structure and doesn't unintentionally include or exclude test stacks.


🏁 Script executed:

#!/bin/bash
# Check if the stacks directory structure aligns with the inclusion/exclusion patterns

# Find all files in orgs directory
echo "Files that will be included by 'orgs/**/*' pattern:"
find test/fixtures/stacks/orgs -type f -not -name "_defaults.yaml" | sort

echo -e "\nFiles that will be excluded by '**/_defaults.yaml' pattern:"
find test/fixtures/stacks -name "_defaults.yaml" | sort

Length of output: 493


Inclusion/Exclusion Patterns Verified Correctly
The executed script confirms that the inclusion pattern "orgs/**/*" properly picks up the intended test stack file (test/fixtures/stacks/orgs/default/test/tests.yaml), while the exclusion pattern "**/_defaults.yaml" correctly filters out _defaults.yaml files (e.g., test/fixtures/stacks/orgs/default/test/_defaults.yaml). No unintended paths are included or excluded based on the current configuration.

@RoseSecurity RoseSecurity requested a review from goruha March 31, 2025 17:07
@RoseSecurity RoseSecurity added the needs-test Needs testing label Mar 31, 2025
@mergify mergify bot removed the needs-test Needs testing label Mar 31, 2025
@goruha goruha linked an issue Apr 1, 2025 that may be closed by this pull request
4 tasks
goruha
goruha previously requested changes Apr 1, 2025
@RoseSecurity
Copy link
Contributor Author

/terratest

@mergify mergify bot dismissed goruha’s stale review April 2, 2025 16:53

This Pull Request was updated, so we're dismissing all reviews.

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: 0

🧹 Nitpick comments (3)
test/component_test.go (3)

19-49: Add documentation comments explaining the test purpose

Consider adding documentation comments to your test methods to explain their purpose and what they're verifying. This will help future maintainers understand the test coverage better.

+// TestBasic verifies that the SSM parameter component can:
+// 1. Successfully create an SSM parameter with the specified value
+// 2. Correctly output the created parameter paths
+// 3. Remain stable without drifting when applied multiple times
 func (s *ComponentSuite) TestBasic() {

51-55: Add documentation for TestEnabledFlag method

Similar to the previous comment, add documentation explaining what this test verifies.

+// TestEnabledFlag verifies that when the component is configured with enabled=false,
+// no resources are created
 func (s *ComponentSuite) TestEnabledFlag() {

42-43: Consider adding more descriptive assertion messages

Adding descriptive messages to assertions helps with troubleshooting when tests fail.

-	assert.Equal(s.T(), randomID, createdParam)
+	assert.Equal(s.T(), randomID, createdParam, "SSM parameter value does not match expected value")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dceb35e and 5be1280.

📒 Files selected for processing (1)
  • test/component_test.go (1 hunks)
⏰ 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 (4)
test/component_test.go (4)

39-40: Add error handling for DeployAtmosComponent

The function ignores the error returned by DeployAtmosComponent which could lead to misleading test failures if deployment fails.

-	options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs)
-	assert.NotNil(s.T(), options)
+	options, err := s.DeployAtmosComponent(s.T(), component, stack, &inputs)
+	assert.NoError(s.T(), err, "Failed to deploy component")
+	assert.NotNil(s.T(), options)

24-35: Well-implemented random parameter test

Good job implementing the test with random parameter paths following the previous review suggestions. This approach prevents test conflicts when running in parallel environments.


48-48: Excellent implementation of drift testing

The inclusion of drift testing aligns well with the PR objectives to verify "that the component remains consistent without drifting when executed multiple times with the same inputs."


27-35:

✅ Verification successful

Verify compatibility with older Go versions

The code uses the any type which was introduced in Go 1.18. If you need to maintain compatibility with older Go versions, consider using interface{} instead.

-	inputs := map[string]any{
-		"params": map[string]any{
-			path: map[string]any{
+	inputs := map[string]interface{}{
+		"params": map[string]interface{}{
+			path: map[string]interface{}{

🏁 Script executed:

#!/bin/bash
# Check the Go version used in the project
go version
# Or check if go.mod exists and what version it specifies
if [ -f "go.mod" ]; then
  cat go.mod | grep -E "^go "
fi

Length of output: 64


Compatibility Confirmed: Using any is Valid

  • The project is using Go 1.24.1, which fully supports the any type.
  • The suggestion to replace any with interface{} for older Go versions is not needed.

@RoseSecurity RoseSecurity requested a review from goruha April 2, 2025 18:11
@goruha goruha merged commit 245d159 into main Apr 2, 2025
19 checks passed
@goruha goruha deleted the add-tests branch April 2, 2025 20:41
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