Skip to content

Commit 7c5d11d

Browse files
milldrosterman
andauthored
chore: Replace myapp with mock Component in Tests (#1213)
* replacing myapp with mock * fix tests * vendoring configuration for mock * vendoring configuration for mock * ignore vendored files * fixed atmos_vendor_pull * fix acceptance tests * fix acceptance tests * fix acceptance tests * fix acceptance tests * fixing tests * fixing tests * fixing tests * fixing tests * fix acceptance tests * fix acceptance tests * revert examples and correct test-cases to support * fixing tests * fixed test * reset examples/quick-start-advanced/Dockerfile --------- Co-authored-by: Erik Osterman (CEO @ Cloud Posse) <[email protected]>
1 parent b4203b6 commit 7c5d11d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+314
-419
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@
3939
**/cache.*.txt
4040

4141
# Ignore components vendored during tests
42-
tests/fixtures/scenarios/vendor/components/**
4342
examples/demo-vendoring/components/**
43+
tests/fixtures/scenarios/vendor-globs/components/**
44+
tests/fixtures/scenarios/vendor/components/**
4445

4546
# Coverage files
4647
coverage.out
47-
coverage.html
48+
coverage.html

internal/exec/vendor_utils_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,16 @@ func TestExecuteVendorPull(t *testing.T) {
129129
"./components/terraform/github/stargazers/main/versions.tf",
130130
"./components/terraform/github/stargazers/main/README.md",
131131
"./components/terraform/test-components/main/main.tf",
132-
"./components/terraform/test-components/main/outputs.tf",
133132
"./components/terraform/test-components/main/README.md",
134-
"./components/terraform/test-components/main/variables.tf",
135-
"./components/terraform/test-components/main/versions.tf",
136133
"./components/terraform/weather/main/main.tf",
137134
"./components/terraform/weather/main/outputs.tf",
138135
"./components/terraform/weather/main/providers.tf",
139136
"./components/terraform/weather/main/variables.tf",
140137
"./components/terraform/weather/main/versions.tf",
141138
"./components/terraform/weather/main/README.md",
142-
"./components/terraform/myapp2/outputs.tf",
143139
"./components/terraform/myapp2/main.tf",
144-
"./components/terraform/myapp2/variables.tf",
145-
"./components/terraform/myapp2/versions.tf",
146140
"./components/terraform/myapp2/README.md",
147-
"./components/terraform/myapp1/outputs.tf",
148141
"./components/terraform/myapp1/main.tf",
149-
"./components/terraform/myapp1/variables.tf",
150-
"./components/terraform/myapp1/versions.tf",
151142
"./components/terraform/myapp1/README.md",
152143
}
153144
success, file := verifyFileExists(t, files)

pkg/stack/stack_processor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ func TestStackProcessorRelativePaths(t *testing.T) {
243243
components := mapConfig1["components"].(map[string]any)
244244
terraformComponents := components["terraform"].(map[string]any)
245245

246-
myappComponent := terraformComponents["myapp"].(map[string]any)
247-
assert.NotNil(t, myappComponent)
246+
mockComponent := terraformComponents["mock"].(map[string]any)
247+
assert.NotNil(t, mockComponent)
248248
}
249249

250250
func TestProcessYAMLConfigFile(t *testing.T) {

pkg/vender/vendor_config_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestVendorConfigScenarios(t *testing.T) {
2828
atmosConfig.Logs.Level = "Trace"
2929

3030
// Setup test component directory
31-
componentPath := filepath.Join(testDir, "components", "terraform", "myapp")
31+
componentPath := filepath.Join(testDir, "components", "terraform", "mock")
3232
err := os.MkdirAll(componentPath, 0o755)
3333
assert.Nil(t, err)
3434

@@ -41,7 +41,7 @@ metadata:
4141
name: test-vendor-config
4242
spec:
4343
sources:
44-
- component: myapp
44+
- component: mock
4545
source: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}}
4646
version: 0.25.0
4747
included_paths:
@@ -60,12 +60,12 @@ spec:
6060
// Verify the component exists in vendor config
6161
var found bool
6262
for _, source := range vendorConfig.Spec.Sources {
63-
if source.Component == "myapp" {
63+
if source.Component == "mock" {
6464
found = true
6565
break
6666
}
6767
}
68-
assert.True(t, found, "Component 'myapp' should be defined in vendor.yaml")
68+
assert.True(t, found, "Component 'mock' should be defined in vendor.yaml")
6969

7070
// Clean up
7171
err = os.Remove(vendorYamlPath)
@@ -78,7 +78,7 @@ spec:
7878
componentYaml := `apiVersion: atmos/v1
7979
kind: ComponentVendorConfig
8080
metadata:
81-
name: myapp-vendor-config
81+
name: mock-vendor-config
8282
spec:
8383
source:
8484
uri: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}}
@@ -89,7 +89,7 @@ spec:
8989
assert.Nil(t, err)
9090

9191
// Test component vendoring
92-
componentConfig, compPath, err := e.ReadAndProcessComponentVendorConfigFile(&atmosConfig, "myapp", "terraform")
92+
componentConfig, compPath, err := e.ReadAndProcessComponentVendorConfigFile(&atmosConfig, "mock", "terraform")
9393
assert.Nil(t, err)
9494
assert.NotNil(t, componentConfig)
9595
assert.Equal(t, componentPath, compPath)
@@ -108,7 +108,7 @@ spec:
108108
assert.False(t, exists)
109109

110110
// Test component vendoring
111-
_, _, err = e.ReadAndProcessComponentVendorConfigFile(&atmosConfig, "myapp", "terraform")
111+
_, _, err = e.ReadAndProcessComponentVendorConfigFile(&atmosConfig, "mock", "terraform")
112112
assert.Error(t, err)
113113
assert.Contains(t, err.Error(), "does not exist")
114114
})
@@ -122,7 +122,7 @@ metadata:
122122
name: test-vendor-config
123123
spec:
124124
sources:
125-
- component: myapp
125+
- component: mock
126126
source: github.com/cloudposse/terraform-null-label.git//exports?ref={{.Version}}
127127
version: 0.25.0
128128
`

tests/cli_terraform_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestCLITerraformClean(t *testing.T) {
3939
}()
4040

4141
// Define the work directory and change to it
42-
workDir := "../examples/quick-start-simple"
42+
workDir := "fixtures/scenarios/basic"
4343
if err := os.Chdir(workDir); err != nil {
4444
t.Fatalf("Failed to change directory to %q: %v", workDir, err)
4545
}
@@ -55,24 +55,23 @@ func TestCLITerraformClean(t *testing.T) {
5555
// Clean everything
5656
runTerraformCleanCommand(t, binaryPath)
5757
// Clean specific component
58-
runTerraformCleanCommand(t, binaryPath, "station")
58+
runTerraformCleanCommand(t, binaryPath, "mycomponent")
5959
// Clean component with stack
60-
runTerraformCleanCommand(t, binaryPath, "station", "-s", "dev")
60+
runTerraformCleanCommand(t, binaryPath, "mycomponent", "-s", "nonprod")
6161

6262
// Run terraform apply for prod environment
6363
runTerraformApply(t, binaryPath, "prod")
64-
verifyStateFilesExist(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"})
64+
verifyStateFilesExist(t, []string{"./components/terraform/mock/terraform.tfstate.d/prod-mycomponent"})
6565
runCLITerraformCleanComponent(t, binaryPath, "prod")
66-
verifyStateFilesDeleted(t, []string{"./components/terraform/weather/terraform.tfstate.d/prod-station"})
66+
verifyStateFilesDeleted(t, []string{"./components/terraform/mock/terraform.tfstate.d/prod-mycomponent"})
6767

68-
// Run terraform apply for dev environment
69-
runTerraformApply(t, binaryPath, "dev")
68+
// Run terraform apply for nonprod environment
69+
runTerraformApply(t, binaryPath, "nonprod")
7070

7171
// Verify if state files exist before cleaning
7272
stateFiles := []string{
73-
"./components/terraform/weather/.terraform",
74-
"./components/terraform/weather/terraform.tfstate.d",
75-
"./components/terraform/weather/.terraform.lock.hcl",
73+
"./components/terraform/mock/.terraform",
74+
"./components/terraform/mock/terraform.tfstate.d",
7675
}
7776
verifyStateFilesExist(t, stateFiles)
7877

@@ -85,7 +84,7 @@ func TestCLITerraformClean(t *testing.T) {
8584

8685
// runTerraformApply runs the terraform apply command for a given environment.
8786
func runTerraformApply(t *testing.T, binaryPath, environment string) {
88-
cmd := exec.Command(binaryPath, "terraform", "apply", "station", "-s", environment)
87+
cmd := exec.Command(binaryPath, "terraform", "apply", "mycomponent", "-s", environment)
8988
envVars := os.Environ()
9089
envVars = append(envVars, "ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE=true")
9190
cmd.Env = envVars
@@ -96,7 +95,7 @@ func runTerraformApply(t *testing.T, binaryPath, environment string) {
9695
err := cmd.Run()
9796
t.Log(stdout.String())
9897
if err != nil {
99-
t.Fatalf("Failed to run terraform apply station -s %s: %v", environment, stderr.String())
98+
t.Fatalf("Failed to run terraform apply mycomponent -s %s: %v", environment, stderr.String())
10099
}
101100
}
102101

@@ -143,7 +142,7 @@ func verifyStateFilesDeleted(t *testing.T, stateFiles []string) {
143142
}
144143

145144
func runCLITerraformCleanComponent(t *testing.T, binaryPath, environment string) {
146-
cmd := exec.Command(binaryPath, "terraform", "clean", "station", "-s", environment, "--force")
145+
cmd := exec.Command(binaryPath, "terraform", "clean", "mycomponent", "-s", environment, "--force")
147146
var stdout, stderr bytes.Buffer
148147
cmd.Stdout = &stdout
149148
cmd.Stderr = &stderr
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Mock Component
2+
3+
This is a mock Terraform component used exclusively for testing purposes. It provides a simple configuration with input variables and corresponding outputs, making it ideal for testing Atmos component functionality and behavior.
4+
5+
## Usage
6+
7+
This component is intended for testing only and should not be used in production environments. It is typically used in conjunction with test fixtures and validation scenarios.
8+
9+
Example stack usage
10+
11+
```yaml
12+
components:
13+
terraform:
14+
mock:
15+
vars:
16+
foo: "default value"
17+
bar: "default value"
18+
baz: "default value"
19+
```
20+
21+
## Requirements
22+
23+
No requirements.
24+
25+
## Providers
26+
27+
No providers.
28+
29+
## Modules
30+
31+
No modules.
32+
33+
## Resources
34+
35+
No resources.
36+
37+
## Inputs
38+
39+
| Name | Description | Type | Default | Required |
40+
|------|-------------|------|---------|:--------:|
41+
| <a name="input_bar"></a> [bar](#input\_bar) | n/a | `string` | `"bar"` | no |
42+
| <a name="input_baz"></a> [baz](#input\_baz) | n/a | `string` | `"baz"` | no |
43+
| <a name="input_foo"></a> [foo](#input\_foo) | n/a | `string` | `"foo"` | no |
44+
45+
## Outputs
46+
47+
| Name | Description |
48+
|------|-------------|
49+
| <a name="output_bar"></a> [bar](#output\_bar) | n/a |
50+
| <a name="output_baz"></a> [baz](#output\_baz) | n/a |
51+
| <a name="output_foo"></a> [foo](#output\_foo) | n/a |

tests/fixtures/components/terraform/myapp/README.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/fixtures/components/terraform/myapp/main.tf

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/fixtures/components/terraform/myapp/outputs.tf

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/fixtures/components/terraform/myapp/variables.tf

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)