Skip to content

Commit 991c710

Browse files
subomiclaude
andcommitted
refactor: clean up array subset sync test
- Rename TestSync_ArraySubset_Debug to TestSync_ArraySubset_Success - Remove debug logging statements - Simplify comments to be more concise and professional - Remove unused TestSimpleArrayModel and TestSimpleArrayHighModel - Update model comments to be clearer and less verbose 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ee23a08 commit 991c710

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed

marshaller/syncing_test.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,11 +1144,10 @@ func TestSync_EmbeddedMapComparison_PointerVsValue_Success(t *testing.T) {
11441144
})
11451145
}
11461146

1147-
func TestSync_ArraySubset_Debug(t *testing.T) {
1147+
func TestSync_ArraySubset_Success(t *testing.T) {
11481148
t.Parallel()
11491149

1150-
// Create items for the high-level model (3 items - subset)
1151-
// Source: items one, four, and six
1150+
// Create high-level model with 3 items
11521151
itemOne := &tests.TestItemHighModel{
11531152
Name: "one",
11541153
Description: "First item",
@@ -1166,9 +1165,7 @@ func TestSync_ArraySubset_Debug(t *testing.T) {
11661165
Items: []*tests.TestItemHighModel{itemOne, itemFour, itemSix},
11671166
}
11681167

1169-
// Set the root node for the high-level model by creating a YAML node
1170-
// This simulates the case where we have an existing YAML document with 6 items
1171-
// Target: items three, five, one, four, second, and six (in this order)
1168+
// Populate core model with 6 items from YAML
11721169
initialYAML := `items:
11731170
- name: three
11741171
description: Third item
@@ -1187,18 +1184,13 @@ func TestSync_ArraySubset_Debug(t *testing.T) {
11871184
err := yaml.Unmarshal([]byte(initialYAML), &rootNode)
11881185
require.NoError(t, err)
11891186

1190-
// Get the core model
11911187
coreModel := highModel.GetCore()
1188+
coreModel.SetRootNode(rootNode.Content[0])
11921189

1193-
// Set the root node on the core model (accessed through GetCore())
1194-
coreModel.SetRootNode(rootNode.Content[0]) // Content[0] is the actual root mapping node
1195-
1196-
// Unmarshal the YAML into the core model to populate it with the 6 items
11971190
_, err = marshaller.UnmarshalModel(t.Context(), rootNode.Content[0], coreModel)
11981191
require.NoError(t, err)
11991192

1200-
// Use SetCore to link each high-level item to its corresponding core item
1201-
// This establishes the connection between high-level items and their core counterparts
1193+
// Link high-level items to their corresponding core items
12021194
for _, item := range coreModel.Items.Value {
12031195
switch item.Name.Value {
12041196
case "one":
@@ -1210,21 +1202,14 @@ func TestSync_ArraySubset_Debug(t *testing.T) {
12101202
}
12111203
}
12121204

1213-
// Sync the high model (3 items) to the core model (currently 6 items)
1214-
// This tests what happens when syncing a subset
1205+
// Sync high model subset to core model
12151206
resultNode, err := marshaller.SyncValue(t.Context(), &highModel, highModel.GetCore(), highModel.GetRootNode(), false)
12161207
require.NoError(t, err)
12171208
require.NotNil(t, resultNode)
12181209

1219-
// Verify the synced array - should now match the high model's subset (3 items)
1220-
// After sync, items two, three, five, and second should be removed
1210+
// Verify synced array matches high model subset
12211211
items := coreModel.Items.Value
1222-
require.Len(t, items, 3, "After sync, core model should have 3 items matching high model")
1223-
1224-
// Debug: Print what we actually got
1225-
t.Logf("Item 0: %s - %s", items[0].Name.Value, items[0].Description.Value)
1226-
t.Logf("Item 1: %s - %s", items[1].Name.Value, items[1].Description.Value)
1227-
t.Logf("Item 2: %s - %s", items[2].Name.Value, items[2].Description.Value)
1212+
require.Len(t, items, 3)
12281213

12291214
require.Equal(t, "one", items[0].Name.Value)
12301215
require.Equal(t, "First item", items[0].Description.Value)
@@ -1235,7 +1220,7 @@ func TestSync_ArraySubset_Debug(t *testing.T) {
12351220
require.Equal(t, "six", items[2].Name.Value)
12361221
require.Equal(t, "Sixth item", items[2].Description.Value)
12371222

1238-
// Verify the core model's RootNode contains the correct YAML
1223+
// Verify YAML output
12391224
expectedYAML := `items:
12401225
- name: one
12411226
description: First item

marshaller/tests/core/models.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,15 @@ type TestTypeConversionCoreModel struct {
184184
Extensions core.Extensions `key:"extensions"`
185185
}
186186

187-
// TestSimpleArrayModel is a minimal model with only an array field for testing array sync behavior
188-
type TestSimpleArrayModel struct {
189-
marshaller.CoreModel `model:"testSimpleArrayModel"`
190-
191-
ArrayField marshaller.Node[[]string] `key:"arrayField"`
192-
}
193-
194-
// TestItemModel represents a simple item with name and description
187+
// TestItemModel represents an item with a name and description
195188
type TestItemModel struct {
196189
marshaller.CoreModel `model:"testItemModel"`
197190

198191
Name marshaller.Node[string] `key:"name"`
199192
Description marshaller.Node[string] `key:"description"`
200193
}
201194

202-
// TestArrayOfObjectsModel is a minimal model with an array of objects for testing array sync behavior
195+
// TestArrayOfObjectsModel contains an array of items
203196
type TestArrayOfObjectsModel struct {
204197
marshaller.CoreModel `model:"testArrayOfObjectsModel"`
205198

marshaller/tests/models.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,14 @@ type TestEmbeddedMapWithFieldsPointerHighModel struct {
129129
Extensions *extensions.Extensions
130130
}
131131

132-
// TestSimpleArrayHighModel is a minimal high-level model with only an array field for testing array sync behavior
133-
type TestSimpleArrayHighModel struct {
134-
marshaller.Model[core.TestSimpleArrayModel]
135-
ArrayField []string
136-
}
137-
138-
// TestItemHighModel represents a simple item with name and description
132+
// TestItemHighModel represents an item with a name and description
139133
type TestItemHighModel struct {
140134
marshaller.Model[core.TestItemModel]
141135
Name string
142136
Description string
143137
}
144138

145-
// TestArrayOfObjectsHighModel is a minimal high-level model with an array of objects for testing array sync behavior
139+
// TestArrayOfObjectsHighModel contains an array of items
146140
type TestArrayOfObjectsHighModel struct {
147141
marshaller.Model[core.TestArrayOfObjectsModel]
148142
Items []*TestItemHighModel

0 commit comments

Comments
 (0)