Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions merge/conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ func (c Conflicts) Equals(c2 Conflicts) bool {
return true
}

// ToSet aggregates conflicts for all managers into a single Set.
func (c Conflicts) ToSet() *fieldpath.Set {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, maybe write a quick test?

set := fieldpath.NewSet()
for _, conflict := range []Conflict(c) {
set.Insert(conflict.Path)
}
return set
}

// ConflictsFromManagers creates a list of conflicts given Managers sets.
func ConflictsFromManagers(sets fieldpath.ManagedFields) Conflicts {
conflicts := []Conflict{}
Expand Down
31 changes: 31 additions & 0 deletions merge/conflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,34 @@ conflicts with "Bob":
t.Errorf("Got %v, wanted %v", got.Error(), wanted)
}
}

func TestToSet(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test, now that you've done that, I realize that it's aggregating the conflicts one has with all users. You need to document the method above to explain that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, done

conflicts := merge.ConflictsFromManagers(fieldpath.ManagedFields{
"Bob": fieldpath.NewVersionedSet(
_NS(
_P("key"),
_P("list", _KBF("key", "a", "id", 2), "id"),
),
"v1",
false,
),
"Alice": fieldpath.NewVersionedSet(
_NS(
_P("value"),
_P("list", _KBF("key", "a", "id", 2), "key"),
),
"v1",
false,
),
})
expected := fieldpath.NewSet(
_P("key"),
_P("value"),
_P("list", _KBF("key", "a", "id", 2), "id"),
_P("list", _KBF("key", "a", "id", 2), "key"),
)
actual := conflicts.ToSet()
if !expected.Equals(actual) {
t.Fatalf("expected\n%v\n, but got\n%v\n", expected, actual)
}
}