Skip to content

Commit a9bab8e

Browse files
author
jennybuckley
committed
Add passing tests
1 parent d09bb18 commit a9bab8e

File tree

1 file changed

+157
-13
lines changed

1 file changed

+157
-13
lines changed

merge/multiple_appliers_test.go

Lines changed: 157 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,152 @@ import (
2121

2222
"sigs.k8s.io/structured-merge-diff/fieldpath"
2323
. "sigs.k8s.io/structured-merge-diff/internal/fixture"
24+
"sigs.k8s.io/structured-merge-diff/merge"
2425
)
2526

27+
func TestMultipleAppliersSet(t *testing.T) {
28+
tests := map[string]TestCase{
29+
"remove_one": {
30+
Ops: []Operation{
31+
Apply{
32+
Manager: "apply-one",
33+
APIVersion: "v1",
34+
Object: `
35+
list:
36+
- name: a
37+
- name: b
38+
`,
39+
},
40+
Apply{
41+
Manager: "apply-two",
42+
APIVersion: "v2",
43+
Object: `
44+
list:
45+
- name: c
46+
`,
47+
},
48+
Apply{
49+
Manager: "apply-one",
50+
APIVersion: "v3",
51+
Object: `
52+
list:
53+
- name: a
54+
`,
55+
},
56+
},
57+
Object: `
58+
list:
59+
- name: a
60+
- name: c
61+
`,
62+
Managed: fieldpath.ManagedFields{
63+
"apply-one": &fieldpath.VersionedSet{
64+
Set: _NS(
65+
_P("list", _KBF("name", _SV("a")), "name"),
66+
),
67+
APIVersion: "v3",
68+
},
69+
"apply-two": &fieldpath.VersionedSet{
70+
Set: _NS(
71+
_P("list", _KBF("name", _SV("c")), "name"),
72+
),
73+
APIVersion: "v2",
74+
},
75+
},
76+
},
77+
"same_value_no_conflict": {
78+
Ops: []Operation{
79+
Apply{
80+
Manager: "apply-one",
81+
APIVersion: "v1",
82+
Object: `
83+
list:
84+
- name: a
85+
value: 0
86+
`,
87+
},
88+
Apply{
89+
Manager: "apply-two",
90+
APIVersion: "v2",
91+
Object: `
92+
list:
93+
- name: a
94+
value: 0
95+
`,
96+
},
97+
},
98+
Object: `
99+
list:
100+
- name: a
101+
value: 0
102+
`,
103+
Managed: fieldpath.ManagedFields{
104+
"apply-one": &fieldpath.VersionedSet{
105+
Set: _NS(
106+
_P("list", _KBF("name", _SV("a")), "name"),
107+
_P("list", _KBF("name", _SV("a")), "value"),
108+
),
109+
APIVersion: "v1",
110+
},
111+
"apply-two": &fieldpath.VersionedSet{
112+
Set: _NS(
113+
_P("list", _KBF("name", _SV("a")), "name"),
114+
_P("list", _KBF("name", _SV("a")), "value"),
115+
),
116+
APIVersion: "v2",
117+
},
118+
},
119+
},
120+
"change_value_yes_conflict": {
121+
Ops: []Operation{
122+
Apply{
123+
Manager: "apply-one",
124+
APIVersion: "v1",
125+
Object: `
126+
list:
127+
- name: a
128+
value: 0
129+
`,
130+
},
131+
Apply{
132+
Manager: "apply-two",
133+
APIVersion: "v2",
134+
Object: `
135+
list:
136+
- name: a
137+
value: 1
138+
`,
139+
Conflicts: merge.Conflicts{
140+
merge.Conflict{Manager: "apply-one", Path: _P("list", _KBF("name", _SV("a")), "value")},
141+
},
142+
},
143+
},
144+
Object: `
145+
list:
146+
- name: a
147+
value: 0
148+
`,
149+
Managed: fieldpath.ManagedFields{
150+
"apply-one": &fieldpath.VersionedSet{
151+
Set: _NS(
152+
_P("list", _KBF("name", _SV("a")), "name"),
153+
_P("list", _KBF("name", _SV("a")), "value"),
154+
),
155+
APIVersion: "v1",
156+
},
157+
},
158+
},
159+
}
160+
161+
for name, test := range tests {
162+
t.Run(name, func(t *testing.T) {
163+
if err := test.Test(associativeListParser); err != nil {
164+
t.Fatal(err)
165+
}
166+
})
167+
}
168+
}
169+
26170
func TestMultipleAppliersSetBroken(t *testing.T) {
27171
tests := map[string]TestCase{
28172
"remove_one_keep_one": {
@@ -32,46 +176,46 @@ func TestMultipleAppliersSetBroken(t *testing.T) {
32176
APIVersion: "v1",
33177
Object: `
34178
list:
35-
- a
36-
- b
37-
- c
179+
- name: a
180+
- name: b
181+
- name: c
38182
`,
39183
},
40184
Apply{
41185
Manager: "apply-two",
42186
APIVersion: "v2",
43187
Object: `
44188
list:
45-
- c
46-
- d
189+
- name: c
190+
- name: d
47191
`,
48192
},
49193
Apply{
50194
Manager: "apply-one",
51195
APIVersion: "v3",
52196
Object: `
53197
list:
54-
- a
198+
- name: a
55199
`,
56200
},
57201
},
58202
Object: `
59203
list:
60-
- a
61-
- c
62-
- d
204+
- name: a
205+
- name: c
206+
- name: d
63207
`,
64208
Managed: fieldpath.ManagedFields{
65209
"apply-one": &fieldpath.VersionedSet{
66210
Set: _NS(
67-
_P("list", _SV("a")),
211+
_P("list", _KBF("name", _SV("a")), "name"),
68212
),
69213
APIVersion: "v3",
70214
},
71215
"apply-two": &fieldpath.VersionedSet{
72216
Set: _NS(
73-
_P("list", _SV("c")),
74-
_P("list", _SV("d")),
217+
_P("list", _KBF("name", _SV("c")), "name"),
218+
_P("list", _KBF("name", _SV("d")), "name"),
75219
),
76220
APIVersion: "v2",
77221
},
@@ -81,7 +225,7 @@ func TestMultipleAppliersSetBroken(t *testing.T) {
81225

82226
for name, test := range tests {
83227
t.Run(name, func(t *testing.T) {
84-
if test.Test(setFieldsParser) == nil {
228+
if test.Test(associativeListParser) == nil {
85229
t.Fatal("Broken test passed")
86230
}
87231
})

0 commit comments

Comments
 (0)