Skip to content

fix: add mocked resources#102

Merged
gberenice merged 1 commit intomainfrom
fix/failing-tests
Dec 8, 2025
Merged

fix: add mocked resources#102
gberenice merged 1 commit intomainfrom
fix/failing-tests

Conversation

@gberenice
Copy link
Member

@gberenice gberenice commented Dec 8, 2025

what

  • Added mock providers for Spacelift data sources in resource-id-resolver.tftest.hcl to make tests deterministic and not dependent on external API calls.

why

  • The tests were failing because they relied on real Spacelift API responses for name-to-ID resolution. This caused failures when AWS integrations or other resources were renamed/deleted in the Spacelift account.

references

Summary by CodeRabbit

  • Tests
    • Enhanced test infrastructure with mock data providers for improved test simulation and validation capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.

@gberenice gberenice requested a review from a team as a code owner December 8, 2025 15:52
@gberenice gberenice requested a review from dudymas December 8, 2025 15:52
oycyc
oycyc previously approved these changes Dec 8, 2025
Copy link
Contributor

@oycyc oycyc left a comment

Choose a reason for hiding this comment

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

Ah nice. Thanks!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

This pull request extends test infrastructure in tests/resource-id-resolver.tftest.hcl by adding mock provider configurations for Spacelift and JSONSchema. Mock data for spaces, worker_pools, and aws_integrations are introduced for the Spacelift provider, while a default validated value is configured for the JSONSchema validator. The variables block is expanded with six new configuration entries (github_enterprise, repository, all_root_modules_enabled, aws_integration_enabled, before_init, and labels) to support additional test scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Mock provider configurations follow consistent, repetitive patterns that are straightforward to validate
  • Variable additions are straightforward configuration entries without complex logic
  • Changes are isolated to a single test file with no cross-file dependencies to verify
  • Primary focus should be ensuring mock data accurately reflects the actual provider schemas and that new variables align with the test scenarios they're intended to drive

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: add mocked resources' is directly related to the main change—adding mock providers and mock data to the test file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/failing-tests

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ac5ced and c94ef90.

📒 Files selected for processing (1)
  • tests/resource-id-resolver.tftest.hcl (1 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: gberenice
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/main.tf:224-230
Timestamp: 2024-10-29T17:52:31.823Z
Learning: In the `masterpointio/terraform-spacelift-automation` repository, the `context.tf` file is a mixin file that we don't own. Do not make suggestions or comments on `context.tf` in future reviews.
Learnt from: Gowiem
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/main.tf:221-227
Timestamp: 2024-10-29T00:06:05.693Z
Learning: In the Terraform module `modules/spacelift-automation/main.tf`, when `var.aws_integration_id` is a required variable, avoid suggesting to make the `spacelift_aws_integration_attachment` resource conditional based on whether `aws_integration_id` is provided.
Learnt from: oycyc
Repo: masterpointio/terraform-aws-ssm-agent PR: 28
File: tests/cpu-compatibility.tftest.hcl:1-11
Timestamp: 2024-10-23T14:10:26.952Z
Learning: In `tests/cpu-compatibility.tftest.hcl`, the variables block contains mock values intended for testing purposes.
📚 Learning: 2024-10-23T14:10:26.952Z
Learnt from: oycyc
Repo: masterpointio/terraform-aws-ssm-agent PR: 28
File: tests/cpu-compatibility.tftest.hcl:1-11
Timestamp: 2024-10-23T14:10:26.952Z
Learning: In `tests/cpu-compatibility.tftest.hcl`, the variables block contains mock values intended for testing purposes.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2025-09-09T13:21:15.616Z
Learnt from: oycyc
Repo: masterpointio/terraform-spacelift-automation PR: 92
File: data.tf:1-4
Timestamp: 2025-09-09T13:21:15.616Z
Learning: The spacelift_aws_integrations data source exists and is available in the Spacelift Terraform provider for looking up AWS integrations, contrary to previous incorrect analysis.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-30T17:01:23.897Z
Learnt from: Gowiem
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: main.tf:231-257
Timestamp: 2024-10-30T17:01:23.897Z
Learning: In `main.tf`, grouping related attributes in the `spacelift_stack` resource using locals may overcomplicate things and remove important logic elsewhere; prefer to keep attributes as is.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-23T14:10:29.597Z
Learnt from: oycyc
Repo: masterpointio/terraform-aws-ssm-agent PR: 28
File: tests/main.tftest.hcl:27-28
Timestamp: 2024-10-23T14:10:29.597Z
Learning: In Terraform test files (e.g., `tests/main.tftest.hcl`), module outputs can be accessed without assigning an explicit name to the module.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-29T00:05:59.989Z
Learnt from: Gowiem
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/main.tf:215-218
Timestamp: 2024-10-29T00:05:59.989Z
Learning: In the `modules/spacelift-automation/main.tf` file, it's valid to directly reference resource collections created with `for_each` in the `depends_on` attribute. For example, in the `spacelift_stack_destructor` resource, referencing `spacelift_drift_detection.this` and `spacelift_aws_integration_attachment.this` directly is acceptable and should not be flagged.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-29T00:06:05.693Z
Learnt from: Gowiem
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/main.tf:221-227
Timestamp: 2024-10-29T00:06:05.693Z
Learning: In the Terraform module `modules/spacelift-automation/main.tf`, when `var.aws_integration_id` is a required variable, avoid suggesting to make the `spacelift_aws_integration_attachment` resource conditional based on whether `aws_integration_id` is provided.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-29T17:52:31.823Z
Learnt from: gberenice
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/main.tf:224-230
Timestamp: 2024-10-29T17:52:31.823Z
Learning: In the `masterpointio/terraform-spacelift-automation` repository, the `context.tf` file is a mixin file that we don't own. Do not make suggestions or comments on `context.tf` in future reviews.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-10-28T12:47:36.579Z
Learnt from: gberenice
Repo: masterpointio/terraform-spacelift-automation PR: 3
File: modules/spacelift-automation/variables.tf:54-64
Timestamp: 2024-10-28T12:47:36.579Z
Learning: In the `spacelift-automation` module, the variable `aws_integration_attachment_write` has a default value of `true`, which matches the default value in the provider.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-12-11T17:35:43.671Z
Learnt from: gberenice
Repo: masterpointio/client-tf-templates PR: 1
File: root-module/main.tf:25-31
Timestamp: 2024-12-11T17:35:43.671Z
Learning: In the `client-tf-templates` repository, the module `masterpointio/random/pet` used in `root-module/main.tf` is a dummy example and may not exist in the Terraform Registry. This is intentional and should not be flagged as an error in future reviews.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-11-18T12:59:36.156Z
Learnt from: gberenice
Repo: masterpointio/terraform-spacelift-aws-integrations PR: 2
File: main.tf:2-8
Timestamp: 2024-11-18T12:59:36.156Z
Learning: In this Terraform configuration, `module.this` is defined in `context.tf`.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
📚 Learning: 2024-11-18T13:00:36.189Z
Learnt from: gberenice
Repo: masterpointio/terraform-spacelift-aws-integrations PR: 2
File: versions.tf:5-8
Timestamp: 2024-11-18T13:00:36.189Z
Learning: If a Terraform module does not include any AWS resources, there's no need to declare the AWS provider.

Applied to files:

  • tests/resource-id-resolver.tftest.hcl
🔇 Additional comments (3)
tests/resource-id-resolver.tftest.hcl (3)

55-61: Verify jsonschema mock data is appropriate.

The jsonschema validator mock returns a hardcoded "{}" as the validated value. Confirm this is the expected format and provides sufficient coverage for the schema validation logic in your tests.


5-78: Excellent test infrastructure setup.

The mock providers are well-structured and the test variables are comprehensively configured. The mock data IDs correctly align with the test assertions throughout the file (e.g., space ID on line 10 matches the assertion on line 87, worker pool ID on line 25 matches line 161, and AWS integration ID on line 40 matches line 189). This consistency ensures the mocked data will satisfy the resource_id_resolver tests and make them deterministic.


5-53: The mock_data field names are correct as written.

The field names in the mock_provider blocks (spaces, worker_pools, integrations) accurately match the actual Spacelift Terraform provider data source response structure, as confirmed by their usage in main.tf where the same fields are accessed in the resource_id_resolver map construction. The mock data structure is properly aligned with the test assertions.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gberenice gberenice merged commit bbd29ad into main Dec 8, 2025
6 checks passed
@gberenice gberenice deleted the fix/failing-tests branch December 8, 2025 17:03
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.

2 participants