2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-11 01:53:53 +00:00
|
|
|
|
|
|
|
package testutil
|
|
|
|
|
2020-08-28 15:59:09 +00:00
|
|
|
import "github.com/suzerain-io/pinniped/internal/controllerlib"
|
2020-08-11 01:53:53 +00:00
|
|
|
|
|
|
|
type ObservableWithInformerOption struct {
|
2020-08-28 15:59:09 +00:00
|
|
|
informerToFilterMap map[controllerlib.InformerGetter]controllerlib.Filter
|
2020-08-11 01:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewObservableWithInformerOption() *ObservableWithInformerOption {
|
|
|
|
return &ObservableWithInformerOption{
|
2020-08-28 15:59:09 +00:00
|
|
|
informerToFilterMap: make(map[controllerlib.InformerGetter]controllerlib.Filter),
|
2020-08-11 01:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *ObservableWithInformerOption) WithInformer(
|
2020-08-28 15:59:09 +00:00
|
|
|
getter controllerlib.InformerGetter,
|
|
|
|
filter controllerlib.Filter,
|
|
|
|
opt controllerlib.InformerOption,
|
|
|
|
) controllerlib.Option {
|
2020-08-11 17:14:57 +00:00
|
|
|
i.informerToFilterMap[getter] = filter
|
2020-08-28 15:59:09 +00:00
|
|
|
return controllerlib.WithInformer(getter, filter, opt)
|
2020-08-11 01:53:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 15:59:09 +00:00
|
|
|
func (i *ObservableWithInformerOption) GetFilterForInformer(getter controllerlib.InformerGetter) controllerlib.Filter {
|
2020-08-11 17:14:57 +00:00
|
|
|
return i.informerToFilterMap[getter]
|
2020-08-11 01:53:53 +00:00
|
|
|
}
|