fix: make auth source group sync correctly handle team removal (#37161)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-07-24 04:05:38 +02:00
committed by GitHub
parent 3c66ec4064
commit 99ca4bff7d
4 changed files with 134 additions and 8 deletions
+22
View File
@@ -52,6 +52,28 @@ func (s Set[T]) Remove(value T) bool {
return false
}
// RemoveFromSet removes the specified elements from the set.
// Returns the number of elements successfully removed.
func (s Set[T]) RemoveFromSet(o Set[T]) (n int) {
for value := range o {
if s.Remove(value) {
n++
}
}
return n
}
// RemoveFromSlice removes the specified elements from the slice.
// Returns the number of elements successfully removed.
func (s Set[T]) RemoveFromSlice(o []T) (n int) {
for _, value := range o {
if s.Remove(value) {
n++
}
}
return n
}
// Values gets a list of all elements in the set.
func (s Set[T]) Values() []T {
keys := make([]T, 0, len(s))
+10
View File
@@ -35,4 +35,14 @@ func TestSet(t *testing.T) {
assert.False(t, s.Contains("key1"))
assert.True(t, s.Contains("key6"))
assert.True(t, s.Contains("key7"))
s = SetOf("a", "b", "c")
n := s.RemoveFromSet(SetOf("b", "c", "d"))
assert.Equal(t, 2, n)
assert.ElementsMatch(t, []string{"a"}, s.Values())
s = SetOf("a", "b", "c")
n = s.RemoveFromSlice([]string{"b", "c", "d"})
assert.Equal(t, 2, n)
assert.ElementsMatch(t, []string{"a"}, s.Values())
}