Skip to content

Commit 621c035

Browse files
authored
Merge pull request #162 from julianvmodesto/conflicts-to-set
Add Conflicts.ToSet()
2 parents e95fcaa + ef55256 commit 621c035

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

merge/conflict.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ func (c Conflicts) Equals(c2 Conflicts) bool {
9595
return true
9696
}
9797

98+
// ToSet aggregates conflicts for all managers into a single Set.
99+
func (c Conflicts) ToSet() *fieldpath.Set {
100+
set := fieldpath.NewSet()
101+
for _, conflict := range []Conflict(c) {
102+
set.Insert(conflict.Path)
103+
}
104+
return set
105+
}
106+
98107
// ConflictsFromManagers creates a list of conflicts given Managers sets.
99108
func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts {
100109
conflicts := []Conflict{}

merge/conflict_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ conflicts with "Bob":
6161
t.Errorf("Got %v, wanted %v", got.Error(), wanted)
6262
}
6363
}
64+
65+
func TestToSet(t *testing.T) {
66+
conflicts := merge.ConflictsFromManagers(fieldpath.ManagedFields{
67+
"Bob": fieldpath.NewVersionedSet(
68+
_NS(
69+
_P("key"),
70+
_P("list", _KBF("key", "a", "id", 2), "id"),
71+
),
72+
"v1",
73+
false,
74+
),
75+
"Alice": fieldpath.NewVersionedSet(
76+
_NS(
77+
_P("value"),
78+
_P("list", _KBF("key", "a", "id", 2), "key"),
79+
),
80+
"v1",
81+
false,
82+
),
83+
})
84+
expected := fieldpath.NewSet(
85+
_P("key"),
86+
_P("value"),
87+
_P("list", _KBF("key", "a", "id", 2), "id"),
88+
_P("list", _KBF("key", "a", "id", 2), "key"),
89+
)
90+
actual := conflicts.ToSet()
91+
if !expected.Equals(actual) {
92+
t.Fatalf("expected\n%v\n, but got\n%v\n", expected, actual)
93+
}
94+
}

0 commit comments

Comments
 (0)