Skip to content

Commit

Permalink
deep copy slice object during append
Browse files Browse the repository at this point in the history
  • Loading branch information
kmala committed Jul 7, 2023
1 parent 8e33abb commit 24aa83d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion merge/conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts {
set.Set().Iterate(func(p fieldpath.Path) {
conflicts = append(conflicts, Conflict{
Manager: manager,
Path: p,
Path: p.Copy(),
})
})
}
Expand Down
42 changes: 42 additions & 0 deletions merge/conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package merge_test

import (
"reflect"
"testing"

"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
Expand Down Expand Up @@ -92,3 +93,44 @@ func TestToSet(t *testing.T) {
t.Fatalf("expected\n%v\n, but got\n%v\n", expected, actual)
}
}

func TestConflictsFromManagers(t *testing.T) {
type args struct {
sets fieldpath.ManagedFields
}
tests := []struct {
name string
args args
want string
}{
{
name: "test with common prefix",
args: args{
sets: fieldpath.ManagedFields{
"Bob": fieldpath.NewVersionedSet(
_NS(
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "livenessProbe", "exec", "command"),
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "livenessProbe", "periodSeconds"),
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "readinessProbe", "exec", "command"),
_P("spec", "template", "spec", "containers", _KBF("name", "probe"), "readinessProbe", "periodSeconds"),
),
"v1",
false,
),
},
},
want: `conflicts with "Bob":
- .spec.template.spec.containers[name="probe"].livenessProbe.periodSeconds
- .spec.template.spec.containers[name="probe"].livenessProbe.exec.command
- .spec.template.spec.containers[name="probe"].readinessProbe.periodSeconds
- .spec.template.spec.containers[name="probe"].readinessProbe.exec.command`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := merge.ConflictsFromManagers(tt.args.sets); !reflect.DeepEqual(got.Error(), tt.want) {
t.Errorf("ConflictsFromManagers() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 24aa83d

Please sign in to comment.