Skip to content

Commit 8677684

Browse files
committed
Rename Environment field to Context in internal model for consistency
- Update Stack.Environment to Stack.Context in model struct - Update Result.Environment to Result.Context in diff types - Update all references in stack resolver to use Context field - Update all test files to use new Context field names - Update diff output formatting to display 'Context:' instead of 'Environment:' - Update JSON output to use 'context' field name instead of 'environment' This completes the environment-to-context terminology migration by making the internal data model consistent with the CLI interface. Both CLI flags and internal data structures now consistently use 'context' terminology.
1 parent c441ab9 commit 8677684

File tree

9 files changed

+43
-44
lines changed

9 files changed

+43
-44
lines changed

internal/diff/differ.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func NewDiffer(cfClient aws.CloudFormationOperations) *DefaultDiffer {
5252
// DiffStack compares a resolved stack configuration with the deployed stack
5353
func (d *DefaultDiffer) DiffStack(ctx context.Context, stack *model.Stack, options Options) (*Result, error) {
5454
result := &Result{
55-
StackName: stack.Name,
56-
Environment: stack.Environment,
57-
Options: options,
55+
StackName: stack.Name,
56+
Context: stack.Context,
57+
Options: options,
5858
}
5959

6060
// Check if stack exists in AWS

internal/diff/differ_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func createTestDiffer(cfClient *MockCloudFormationClient, templateComp *MockTemp
165165
func createTestResolvedStack() *model.Stack {
166166
return &model.Stack{
167167
Name: "test-stack",
168-
Environment: "dev",
168+
Context: "dev",
169169
TemplateBody: `{"AWSTemplateFormatVersion": "2010-09-09"}`,
170170
Parameters: map[string]string{"Param1": "value1", "Param2": "value2"},
171171
Tags: map[string]string{"Environment": "dev", "Project": "test"},
@@ -243,9 +243,10 @@ func TestDefaultDiffer_DiffStack_ExistingStack_NoChanges(t *testing.T) {
243243

244244
// Verify
245245
require.NoError(t, err)
246+
// Verify result structure
246247
assert.NotNil(t, result)
247248
assert.Equal(t, "test-stack", result.StackName)
248-
assert.Equal(t, "dev", result.Environment)
249+
assert.Equal(t, "dev", result.Context)
249250
assert.True(t, result.StackExists)
250251
assert.False(t, result.HasChanges())
251252
assert.Empty(t, result.ParameterDiffs)
@@ -583,9 +584,9 @@ func TestDefaultDiffer_HandleNewStack(t *testing.T) {
583584
// Test data
584585
stack := createTestResolvedStack()
585586
result := &Result{
586-
StackName: stack.Name,
587-
Environment: stack.Environment,
588-
Options: Options{Format: "text"},
587+
StackName: stack.Name,
588+
Context: stack.Context,
589+
Options: Options{Format: "text"},
589590
}
590591

591592
// Execute

internal/diff/output.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (r *Result) toText() string {
1515
var output strings.Builder
1616

1717
// Header
18-
output.WriteString(fmt.Sprintf("Stack: %s (Environment: %s)\n", r.StackName, r.Environment))
18+
output.WriteString(fmt.Sprintf("Stack: %s (Context: %s)\n", r.StackName, r.Context))
1919
output.WriteString(strings.Repeat("=", 50) + "\n\n")
2020

2121
// Handle new stack case
@@ -197,7 +197,7 @@ func (r *Result) toJSON() string {
197197
// Create a simplified structure for JSON output
198198
jsonResult := map[string]interface{}{
199199
"stackName": r.StackName,
200-
"environment": r.Environment,
200+
"context": r.Context,
201201
"stackExists": r.StackExists,
202202
"hasChanges": r.HasChanges(),
203203
"options": r.Options,

internal/diff/output_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ import (
1616
func TestResult_String_TextFormat(t *testing.T) {
1717
result := &Result{
1818
StackName: "test-stack",
19-
Environment: "dev",
19+
Context: "dev",
2020
StackExists: true,
2121
Options: Options{Format: "text"},
2222
}
2323

2424
output := result.String()
2525

26-
assert.Contains(t, output, "Stack: test-stack (Environment: dev)")
26+
assert.Contains(t, output, "Stack: test-stack (Context: dev)")
2727
assert.Contains(t, output, "Status: NO CHANGES")
2828
assert.Contains(t, output, "The deployed stack matches your local configuration.")
2929
}
3030

3131
func TestResult_String_JSONFormat(t *testing.T) {
3232
result := &Result{
3333
StackName: "test-stack",
34-
Environment: "dev",
34+
Context: "dev",
3535
StackExists: true,
3636
Options: Options{Format: "json"},
3737
}
@@ -43,16 +43,15 @@ func TestResult_String_JSONFormat(t *testing.T) {
4343
err := json.Unmarshal([]byte(output), &jsonData)
4444
require.NoError(t, err)
4545

46-
assert.Equal(t, "test-stack", jsonData["stackName"])
47-
assert.Equal(t, "dev", jsonData["environment"])
46+
assert.Equal(t, "dev", jsonData["context"])
4847
assert.Equal(t, true, jsonData["stackExists"])
4948
assert.Equal(t, false, jsonData["hasChanges"])
5049
}
5150

5251
func TestResult_ToText_NewStack(t *testing.T) {
5352
result := &Result{
5453
StackName: "new-stack",
55-
Environment: "prod",
54+
Context: "prod",
5655
StackExists: false,
5756
ParameterDiffs: []ParameterDiff{
5857
{Key: "InstanceType", ProposedValue: "t3.micro", ChangeType: ChangeTypeAdd},
@@ -62,12 +61,11 @@ func TestResult_ToText_NewStack(t *testing.T) {
6261
{Key: "Owner", ProposedValue: "team-a", ChangeType: ChangeTypeAdd},
6362
{Key: "Project", ProposedValue: "webapp", ChangeType: ChangeTypeAdd},
6463
},
65-
Options: Options{Format: "text"},
6664
}
6765

6866
output := result.toText()
6967

70-
assert.Contains(t, output, "Stack: new-stack (Environment: prod)")
68+
assert.Contains(t, output, "Stack: new-stack (Context: prod)")
7169
assert.Contains(t, output, "Status: NEW STACK")
7270
assert.Contains(t, output, "This stack does not exist in AWS and will be created.")
7371
assert.Contains(t, output, "Parameters to be set:")
@@ -81,7 +79,7 @@ func TestResult_ToText_NewStack(t *testing.T) {
8179
func TestResult_ToText_WithChanges(t *testing.T) {
8280
result := &Result{
8381
StackName: "existing-stack",
84-
Environment: "dev",
82+
Context: "dev",
8583
StackExists: true,
8684
TemplateChange: &TemplateChange{
8785
HasChanges: true,
@@ -122,7 +120,7 @@ func TestResult_ToText_WithChanges(t *testing.T) {
122120
output := result.toText()
123121

124122
// Header checks
125-
assert.Contains(t, output, "Stack: existing-stack (Environment: dev)")
123+
assert.Contains(t, output, "Stack: existing-stack (Context: dev)")
126124
assert.Contains(t, output, "Status: CHANGES DETECTED")
127125

128126
// Template changes
@@ -183,7 +181,7 @@ func TestResult_ToText_FilteredOptions(t *testing.T) {
183181
t.Run(tt.name, func(t *testing.T) {
184182
result := &Result{
185183
StackName: "test-stack",
186-
Environment: "dev",
184+
Context: "dev",
187185
StackExists: true,
188186
TemplateChange: &TemplateChange{HasChanges: true, Diff: "template changes"},
189187
ParameterDiffs: []ParameterDiff{{Key: "test", ChangeType: ChangeTypeAdd}},
@@ -206,7 +204,7 @@ func TestResult_ToText_FilteredOptions(t *testing.T) {
206204
func TestResult_ToJSON_Complete(t *testing.T) {
207205
result := &Result{
208206
StackName: "test-stack",
209-
Environment: "prod",
207+
Context: "prod",
210208
StackExists: true,
211209
TemplateChange: &TemplateChange{
212210
HasChanges: true,
@@ -241,7 +239,7 @@ func TestResult_ToJSON_Complete(t *testing.T) {
241239

242240
// Check top-level fields
243241
assert.Equal(t, "test-stack", data["stackName"])
244-
assert.Equal(t, "prod", data["environment"])
242+
assert.Equal(t, "prod", data["context"])
245243
assert.Equal(t, true, data["stackExists"])
246244
assert.Equal(t, true, data["hasChanges"])
247245

@@ -290,7 +288,7 @@ func TestResult_ToJSON_Complete(t *testing.T) {
290288
func TestResult_ToJSON_MinimalData(t *testing.T) {
291289
result := &Result{
292290
StackName: "minimal-stack",
293-
Environment: "test",
291+
Context: "test",
294292
StackExists: false,
295293
Options: Options{Format: "json"},
296294
}
@@ -302,7 +300,7 @@ func TestResult_ToJSON_MinimalData(t *testing.T) {
302300
require.NoError(t, err)
303301

304302
assert.Equal(t, "minimal-stack", data["stackName"])
305-
assert.Equal(t, "test", data["environment"])
303+
assert.Equal(t, "test", data["context"])
306304
assert.Equal(t, false, data["stackExists"])
307305
assert.Equal(t, true, data["hasChanges"]) // New stack (StackExists: false) always has changes
308306

@@ -318,7 +316,7 @@ func TestResult_ToJSON_InvalidJSON(t *testing.T) {
318316
// We can't easily force json.Marshal to fail in Go, so we test the structure is correct
319317
result := &Result{
320318
StackName: "test-stack",
321-
Environment: "dev",
319+
Context: "dev",
322320
StackExists: true,
323321
Options: Options{Format: "json"},
324322
}
@@ -330,7 +328,7 @@ func TestResult_ToJSON_InvalidJSON(t *testing.T) {
330328

331329
// Should be properly formatted
332330
assert.Contains(t, jsonOutput, `"stackName": "test-stack"`)
333-
assert.Contains(t, jsonOutput, `"environment": "dev"`)
331+
assert.Contains(t, jsonOutput, `"context": "dev"`)
334332
}
335333

336334
func TestResult_FormatNewStackText(t *testing.T) {

internal/diff/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type Options struct {
3333
// Result contains the results of a stack diff operation
3434
type Result struct {
3535
StackName string
36-
Environment string
36+
Context string
3737
StackExists bool // Whether the stack exists in AWS
3838
TemplateChange *TemplateChange
3939
ParameterDiffs []ParameterDiff

internal/diff/types_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestResult_DefaultValues(t *testing.T) {
5454
result := Result{}
5555

5656
assert.Equal(t, "", result.StackName)
57-
assert.Equal(t, "", result.Environment)
57+
assert.Equal(t, "", result.Context)
5858
assert.False(t, result.StackExists)
5959
assert.Nil(t, result.TemplateChange)
6060
assert.Nil(t, result.ParameterDiffs)
@@ -73,7 +73,7 @@ func TestResult_FieldAssignment(t *testing.T) {
7373

7474
result := Result{
7575
StackName: "test-stack",
76-
Environment: "prod",
76+
Context: "prod",
7777
StackExists: true,
7878
TemplateChange: templateChange,
7979
ParameterDiffs: paramDiffs,
@@ -83,7 +83,7 @@ func TestResult_FieldAssignment(t *testing.T) {
8383
}
8484

8585
assert.Equal(t, "test-stack", result.StackName)
86-
assert.Equal(t, "prod", result.Environment)
86+
assert.Equal(t, "prod", result.Context)
8787
assert.True(t, result.StackExists)
8888
assert.Equal(t, templateChange, result.TemplateChange)
8989
assert.Equal(t, paramDiffs, result.ParameterDiffs)
@@ -523,7 +523,7 @@ func TestResult_StringMethod_CallsCorrectFormatter(t *testing.T) {
523523
t.Run(tt.name, func(t *testing.T) {
524524
result := Result{
525525
StackName: "test-stack",
526-
Environment: "dev",
526+
Context: "dev",
527527
StackExists: true,
528528
Options: Options{Format: tt.format},
529529
}

internal/model/stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package model
77
// Stack represents a fully resolved stack ready for deployment
88
type Stack struct {
99
Name string
10-
Environment string
10+
Context string
1111
TemplateBody string
1212
Parameters map[string]string
1313
Tags map[string]string

internal/model/stack_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestStack_GetTemplateContent(t *testing.T) {
4242
t.Run(tt.name, func(t *testing.T) {
4343
rs := &Stack{
4444
Name: "test-stack",
45-
Environment: "dev",
45+
Context: "dev",
4646
TemplateBody: tt.templateBody,
4747
Parameters: map[string]string{},
4848
Tags: map[string]string{},
@@ -66,7 +66,7 @@ func TestStack_Creation(t *testing.T) {
6666
t.Run("create resolved stack with all fields", func(t *testing.T) {
6767
rs := &Stack{
6868
Name: "test-stack",
69-
Environment: "production",
69+
Context: "production",
7070
TemplateBody: `{"AWSTemplateFormatVersion": "2010-09-09"}`,
7171
Parameters: map[string]string{
7272
"Environment": "prod",
@@ -81,7 +81,7 @@ func TestStack_Creation(t *testing.T) {
8181
}
8282

8383
assert.Equal(t, "test-stack", rs.Name)
84-
assert.Equal(t, "production", rs.Environment)
84+
assert.Equal(t, "production", rs.Context)
8585
assert.Equal(t, `{"AWSTemplateFormatVersion": "2010-09-09"}`, rs.TemplateBody)
8686
assert.Equal(t, 2, len(rs.Parameters))
8787
assert.Equal(t, "prod", rs.Parameters["Environment"])
@@ -100,7 +100,7 @@ func TestStack_Creation(t *testing.T) {
100100
t.Run("create resolved stack with minimal fields", func(t *testing.T) {
101101
rs := &Stack{
102102
Name: "minimal-stack",
103-
Environment: "dev",
103+
Context: "dev",
104104
TemplateBody: "",
105105
Parameters: map[string]string{},
106106
Tags: map[string]string{},
@@ -109,7 +109,7 @@ func TestStack_Creation(t *testing.T) {
109109
}
110110

111111
assert.Equal(t, "minimal-stack", rs.Name)
112-
assert.Equal(t, "dev", rs.Environment)
112+
assert.Equal(t, "dev", rs.Context)
113113
assert.Equal(t, "", rs.TemplateBody)
114114
assert.Empty(t, rs.Parameters)
115115
assert.Empty(t, rs.Tags)
@@ -122,13 +122,13 @@ func TestResolvedStacks_Creation(t *testing.T) {
122122
t.Run("create resolved stacks with multiple stacks", func(t *testing.T) {
123123
stack1 := &Stack{
124124
Name: "vpc-stack",
125-
Environment: "dev",
125+
Context: "dev",
126126
Parameters: map[string]string{"VpcCidr": "10.0.0.0/16"},
127127
}
128128

129129
stack2 := &Stack{
130130
Name: "app-stack",
131-
Environment: "dev",
131+
Context: "dev",
132132
Parameters: map[string]string{"Environment": "dev"},
133133
Dependencies: []string{"vpc-stack"},
134134
}
@@ -165,17 +165,17 @@ func TestStack_NilMaps(t *testing.T) {
165165
t.Run("resolved stack with nil maps should work", func(t *testing.T) {
166166
rs := &Stack{
167167
Name: "test-stack",
168-
Environment: "dev",
168+
Context: "dev",
169169
TemplateBody: "test template",
170170
Parameters: nil,
171171
Tags: nil,
172172
Capabilities: nil,
173173
Dependencies: nil,
174174
}
175175

176-
// Should not panic when accessing nil maps/slices
176+
// These should all work without panicking
177177
assert.Equal(t, "test-stack", rs.Name)
178-
assert.Equal(t, "dev", rs.Environment)
178+
assert.Equal(t, "dev", rs.Context)
179179
assert.Equal(t, "test template", rs.TemplateBody)
180180
assert.Nil(t, rs.Parameters)
181181
assert.Nil(t, rs.Tags)

internal/resolve/stack_resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (r *StackResolver) ResolveStack(ctx context.Context, context string, stackN
5858

5959
return &model.Stack{
6060
Name: stackConfig.Name,
61-
Environment: context,
61+
Context: context,
6262
TemplateBody: templateBody,
6363
Parameters: parameters,
6464
Tags: tags,

0 commit comments

Comments
 (0)