Skip to content

Commit bbd29ad

Browse files
authored
fix: add mocked resources (#102)
## 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 - https://github.com/masterpointio/terraform-spacelift-automation/actions/runs/19815562739/job/56765940741?pr=100 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Enhanced test infrastructure with mock data providers for improved test simulation and validation capabilities. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3ac5ced commit bbd29ad

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/resource-id-resolver.tftest.hcl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,66 @@
11
# This test file validates the resource_id_resolver logic in main.tf which handles
22
# name-to-ID resolution for Spacelift resources and when to use global vs stack-level values,
33
# including Spaces, Worker Pools, and AWS Integrations, etc.
4+
5+
mock_provider "spacelift" {
6+
mock_data "spacelift_spaces" {
7+
defaults = {
8+
spaces = [
9+
{
10+
space_id = "mp-aws-automation-01JK7A21DW1YH3Q64JHS3RYNP9"
11+
name = "mp-aws-automation"
12+
parent_space_id = "root"
13+
description = "Test space"
14+
labels = []
15+
inherit_entities = true
16+
}
17+
]
18+
}
19+
}
20+
21+
mock_data "spacelift_worker_pools" {
22+
defaults = {
23+
worker_pools = [
24+
{
25+
worker_pool_id = "01K3VABYB4FBXNV24KN4A4EKC8"
26+
name = "mp-ue1-automation-spft-priv-workers"
27+
description = "Test worker pool"
28+
labels = []
29+
config = ""
30+
space_id = "root"
31+
drift_detection_run_limit = 0
32+
}
33+
]
34+
}
35+
}
36+
37+
mock_data "spacelift_aws_integrations" {
38+
defaults = {
39+
integrations = [
40+
{
41+
integration_id = "01JEC7ZACVKHTSVY4NF8QNZVVB"
42+
name = "mp-automation-755965222190"
43+
role_arn = "arn:aws:iam::755965222190:role/spacelift"
44+
external_id = "test"
45+
duration_seconds = 3600
46+
generate_credentials_in_worker = false
47+
space_id = "root"
48+
labels = []
49+
region = "us-east-1"
50+
}
51+
]
52+
}
53+
}
54+
}
55+
56+
mock_provider "jsonschema" {
57+
mock_data "jsonschema_validator" {
58+
defaults = {
59+
validated = "{}"
60+
}
61+
}
62+
}
63+
464
variables {
565
root_modules_path = "./tests/fixtures/multi-instance"
666
common_config_file = "common.yaml"

0 commit comments

Comments
 (0)