Skip to content

Commit 24aa83d

Browse files
committed
deep copy slice object during append
1 parent 8e33abb commit 24aa83d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

merge/conflict.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts {
112112
set.Set().Iterate(func(p fieldpath.Path) {
113113
conflicts = append(conflicts, Conflict{
114114
Manager: manager,
115-
Path: p,
115+
Path: p.Copy(),
116116
})
117117
})
118118
}

merge/conflict_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package merge_test
1818

1919
import (
20+
"reflect"
2021
"testing"
2122

2223
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
@@ -92,3 +93,44 @@ func TestToSet(t *testing.T) {
9293
t.Fatalf("expected\n%v\n, but got\n%v\n", expected, actual)
9394
}
9495
}
96+
97+
func TestConflictsFromManagers(t *testing.T) {
98+
type args struct {
99+
sets fieldpath.ManagedFields
100+
}
101+
tests := []struct {
102+
name string
103+
args args
104+
want string
105+
}{
106+
{
107+
name: "test with common prefix",
108+
args: args{
109+
sets: fieldpath.ManagedFields{
110+
"Bob": fieldpath.NewVersionedSet(
111+
_NS(
112+
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "livenessProbe", "exec", "command"),
113+
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "livenessProbe", "periodSeconds"),
114+
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "readinessProbe", "exec", "command"),
115+
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "readinessProbe", "periodSeconds"),
116+
),
117+
"v1",
118+
false,
119+
),
120+
},
121+
},
122+
want: `conflicts with "Bob":
123+
- .spec.template.spec.containers[name="probe"].livenessProbe.periodSeconds
124+
- .spec.template.spec.containers[name="probe"].livenessProbe.exec.command
125+
- .spec.template.spec.containers[name="probe"].readinessProbe.periodSeconds
126+
- .spec.template.spec.containers[name="probe"].readinessProbe.exec.command`,
127+
},
128+
}
129+
for _, tt := range tests {
130+
t.Run(tt.name, func(t *testing.T) {
131+
if got := merge.ConflictsFromManagers(tt.args.sets); !reflect.DeepEqual(got.Error(), tt.want) {
132+
t.Errorf("ConflictsFromManagers() = %v, want %v", got, tt.want)
133+
}
134+
})
135+
}
136+
}

0 commit comments

Comments
 (0)