mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #110145 from sxllwx/fix/audit-union-var-closures
fix audit union loop variables in closures
This commit is contained in:
commit
4f851ebffb
@ -48,6 +48,7 @@ func (u union) ProcessEvents(events ...*auditinternal.Event) bool {
|
|||||||
func (u union) Run(stopCh <-chan struct{}) error {
|
func (u union) Run(stopCh <-chan struct{}) error {
|
||||||
var funcs []func() error
|
var funcs []func() error
|
||||||
for _, backend := range u.backends {
|
for _, backend := range u.backends {
|
||||||
|
backend := backend
|
||||||
funcs = append(funcs, func() error {
|
funcs = append(funcs, func() error {
|
||||||
return backend.Run(stopCh)
|
return backend.Run(stopCh)
|
||||||
})
|
})
|
||||||
|
@ -80,3 +80,36 @@ func TestUnion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type cannotMultipleRunBackend struct {
|
||||||
|
started chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *cannotMultipleRunBackend) ProcessEvents(events ...*auditinternal.Event) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *cannotMultipleRunBackend) Run(stopCh <-chan struct{}) error {
|
||||||
|
close(b.started)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *cannotMultipleRunBackend) Shutdown() {}
|
||||||
|
|
||||||
|
func (b *cannotMultipleRunBackend) String() string {
|
||||||
|
return "cannotMultipleRunBackend"
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnionRun(t *testing.T) {
|
||||||
|
backends := []Backend{
|
||||||
|
&cannotMultipleRunBackend{started: make(chan struct{})},
|
||||||
|
&cannotMultipleRunBackend{started: make(chan struct{})},
|
||||||
|
&cannotMultipleRunBackend{started: make(chan struct{})},
|
||||||
|
}
|
||||||
|
|
||||||
|
b := Union(backends...)
|
||||||
|
|
||||||
|
if err := b.Run(make(chan struct{})); err != nil {
|
||||||
|
t.Errorf("union backend run: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user