MCPcopy
hub / github.com/kubernetes-sigs/controller-runtime / CacheTest

Function CacheTest

pkg/cache/cache_test.go:603–2584  ·  view source on GitHub ↗
(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options)

Source from the content-addressed store, hash-verified

601}
602
603func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (cache.Cache, error), opts cache.Options) {
604 Describe("Cache test", func() {
605 var (
606 informerCache cache.Cache
607 informerCacheCancel context.CancelFunc
608 knownPod1 client.Object
609 knownPod2 client.Object
610 knownPod3 client.Object
611 knownPod4 client.Object
612 knownPod5 client.Object
613 knownPod6 client.Object
614 )
615
616 BeforeEach(func(ctx SpecContext) {
617 var informerCacheCtx context.Context
618 // Has to be derived from context.Background as it has to stay valid past the
619 // BeforeEach.
620 informerCacheCtx, informerCacheCancel = context.WithCancel(context.Background()) //nolint:forbidigo
621 Expect(cfg).NotTo(BeNil())
622
623 By("creating three pods")
624 cl, err := client.New(cfg, client.Options{})
625 Expect(err).NotTo(HaveOccurred())
626 err = ensureNode(ctx, testNodeOne, cl)
627 Expect(err).NotTo(HaveOccurred())
628 err = ensureNode(ctx, testNodeTwo, cl)
629 Expect(err).NotTo(HaveOccurred())
630 err = ensureNamespace(ctx, testNamespaceOne, cl)
631 Expect(err).NotTo(HaveOccurred())
632 err = ensureNamespace(ctx, testNamespaceTwo, cl)
633 Expect(err).NotTo(HaveOccurred())
634 err = ensureNamespace(ctx, testNamespaceThree, cl)
635 Expect(err).NotTo(HaveOccurred())
636 // Includes restart policy since these objects are indexed on this field.
637 knownPod1 = createPod(ctx, "test-pod-1", testNamespaceOne, corev1.RestartPolicyNever)
638 knownPod2 = createPod(ctx, "test-pod-2", testNamespaceTwo, corev1.RestartPolicyAlways)
639 knownPod3 = createPodWithLabels(ctx, "test-pod-3", testNamespaceTwo, corev1.RestartPolicyOnFailure, map[string]string{"common-label": "common"})
640 knownPod4 = createPodWithLabels(ctx, "test-pod-4", testNamespaceThree, corev1.RestartPolicyNever, map[string]string{"common-label": "common"})
641 knownPod5 = createPod(ctx, "test-pod-5", testNamespaceOne, corev1.RestartPolicyNever)
642 knownPod6 = createPod(ctx, "test-pod-6", testNamespaceTwo, corev1.RestartPolicyAlways)
643
644 podGVK := schema.GroupVersionKind{
645 Kind: "Pod",
646 Version: "v1",
647 }
648
649 knownPod1.GetObjectKind().SetGroupVersionKind(podGVK)
650 knownPod2.GetObjectKind().SetGroupVersionKind(podGVK)
651 knownPod3.GetObjectKind().SetGroupVersionKind(podGVK)
652 knownPod4.GetObjectKind().SetGroupVersionKind(podGVK)
653 knownPod5.GetObjectKind().SetGroupVersionKind(podGVK)
654 knownPod6.GetObjectKind().SetGroupVersionKind(podGVK)
655
656 By("creating the informer cache")
657 informerCache, err = createCacheFunc(cfg, opts)
658 Expect(err).NotTo(HaveOccurred())
659 By("running the cache and waiting for it to sync")
660 // pass as an arg so that we don't race between close and re-assign

Callers 1

cache_test.goFile · 0.85

Calls 15

NewFunction · 0.92
InNamespaceTypeAlias · 0.92
MatchingLabelsTypeAlias · 0.92
LimitTypeAlias · 0.92
ContinueTypeAlias · 0.92
NewFunction · 0.92
ObjectKeyFromObjectFunction · 0.92
ensureNodeFunction · 0.85
ensureNamespaceFunction · 0.85
createPodFunction · 0.85
createPodWithLabelsFunction · 0.85
deletePodFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…