(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options)
| 527 | } |
| 528 | |
| 529 | func NonBlockingGetTest(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options) { |
| 530 | Describe("non-blocking get test", func() { |
| 531 | var ( |
| 532 | informerCache cache.Cache |
| 533 | informerCacheCancel context.CancelFunc |
| 534 | ) |
| 535 | BeforeEach(func(ctx SpecContext) { |
| 536 | var informerCacheCtx context.Context |
| 537 | // Has to be derived from context.Background as it has to stay valid past the |
| 538 | // BeforeEach. |
| 539 | informerCacheCtx, informerCacheCancel = context.WithCancel(context.Background()) //nolint:forbidigo |
| 540 | Expect(cfg).NotTo(BeNil()) |
| 541 | |
| 542 | By("creating expected namespaces") |
| 543 | cl, err := client.New(cfg, client.Options{}) |
| 544 | Expect(err).NotTo(HaveOccurred()) |
| 545 | err = ensureNode(ctx, testNodeOne, cl) |
| 546 | Expect(err).NotTo(HaveOccurred()) |
| 547 | err = ensureNamespace(ctx, testNamespaceOne, cl) |
| 548 | Expect(err).NotTo(HaveOccurred()) |
| 549 | err = ensureNamespace(ctx, testNamespaceTwo, cl) |
| 550 | Expect(err).NotTo(HaveOccurred()) |
| 551 | err = ensureNamespace(ctx, testNamespaceThree, cl) |
| 552 | Expect(err).NotTo(HaveOccurred()) |
| 553 | |
| 554 | By("creating the informer cache") |
| 555 | opts.NewInformer = func(_ kcache.ListerWatcher, _ runtime.Object, _ time.Duration, _ kcache.Indexers) kcache.SharedIndexInformer { |
| 556 | return controllertest.NewFakeInformer() |
| 557 | } |
| 558 | informerCache, err = createCacheFunc(cfg, opts) |
| 559 | Expect(err).NotTo(HaveOccurred()) |
| 560 | By("running the cache and waiting for it to sync") |
| 561 | // pass as an arg so that we don't race between close and re-assign |
| 562 | go func(ctx context.Context) { |
| 563 | defer GinkgoRecover() |
| 564 | Expect(informerCache.Start(ctx)).To(Succeed()) |
| 565 | }(informerCacheCtx) |
| 566 | Expect(informerCache.WaitForCacheSync(ctx)).To(BeTrue()) |
| 567 | }) |
| 568 | |
| 569 | AfterEach(func() { |
| 570 | By("cleaning up created pods") |
| 571 | informerCacheCancel() |
| 572 | }) |
| 573 | |
| 574 | Describe("as an Informer", func() { |
| 575 | It("should be able to get informer for the object without blocking", func(specCtx SpecContext) { |
| 576 | By("getting a shared index informer for a pod") |
| 577 | pod := &corev1.Pod{ |
| 578 | ObjectMeta: metav1.ObjectMeta{ |
| 579 | Name: "informer-obj", |
| 580 | Namespace: "default", |
| 581 | }, |
| 582 | Spec: corev1.PodSpec{ |
| 583 | Containers: []corev1.Container{ |
| 584 | { |
| 585 | Name: "nginx", |
| 586 | Image: "nginx", |
no test coverage detected
searching dependent graphs…