(t *testing.T, ctx context.Context, enableStatusReport bool)
| 44 | } |
| 45 | |
| 46 | func newPeerConfigTestFixture(t *testing.T, ctx context.Context, enableStatusReport bool) (*peerConfigTestFixture, func()) { |
| 47 | f := &peerConfigTestFixture{} |
| 48 | |
| 49 | type watchSync struct { |
| 50 | once sync.Once |
| 51 | watchCh chan any |
| 52 | } |
| 53 | |
| 54 | rws := map[string]*watchSync{ |
| 55 | "ciliumbgppeerconfigs": {watchCh: make(chan any)}, |
| 56 | } |
| 57 | |
| 58 | if enableStatusReport { |
| 59 | rws["secrets"] = &watchSync{watchCh: make(chan any)} |
| 60 | } |
| 61 | |
| 62 | reactorFn := func(tracker k8sTesting.ObjectTracker) func(action k8sTesting.Action) (handled bool, ret watch.Interface, err error) { |
| 63 | return func(action k8sTesting.Action) (handled bool, ret watch.Interface, err error) { |
| 64 | w := action.(k8sTesting.WatchAction) |
| 65 | gvr := w.GetResource() |
| 66 | ns := w.GetNamespace() |
| 67 | |
| 68 | // Extract ListOptions for WatchList semantics (SendInitialEvents) |
| 69 | var opts []meta_v1.ListOptions |
| 70 | if watchAction, ok := action.(k8sTesting.WatchActionImpl); ok { |
| 71 | opts = append(opts, watchAction.ListOptions) |
| 72 | } |
| 73 | |
| 74 | watch, err := tracker.Watch(gvr, ns, opts...) |
| 75 | if err != nil { |
| 76 | return false, nil, err |
| 77 | } |
| 78 | rw, ok := rws[w.GetResource().Resource] |
| 79 | if !ok { |
| 80 | return false, watch, nil |
| 81 | } |
| 82 | rw.once.Do(func() { close(rw.watchCh) }) |
| 83 | return true, watch, nil |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // make sure watchers are initialized before the test starts |
| 88 | watchersReadyFn := func() { |
| 89 | for name, rw := range rws { |
| 90 | select { |
| 91 | case <-ctx.Done(): |
| 92 | require.Fail(t, fmt.Sprintf("Context expired while waiting for %s", name)) |
| 93 | case <-rw.watchCh: |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | hive := hive.New( |
| 99 | cell.Module("test", "test", |
| 100 | cell.Provide( |
| 101 | k8sClient.NewFakeClientset, |
| 102 | newSecretResource, |
| 103 | k8s.CiliumBGPPeerConfigResource, |
no test coverage detected
searching dependent graphs…