sigs.k8s.io/controller-runtime@v0.18.2/pkg/source/source_suite_test.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package source_test 18 19 import ( 20 "context" 21 "testing" 22 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 "k8s.io/client-go/kubernetes" 26 "k8s.io/client-go/rest" 27 "sigs.k8s.io/controller-runtime/pkg/cache" 28 "sigs.k8s.io/controller-runtime/pkg/envtest" 29 logf "sigs.k8s.io/controller-runtime/pkg/log" 30 "sigs.k8s.io/controller-runtime/pkg/log/zap" 31 ) 32 33 func TestSource(t *testing.T) { 34 RegisterFailHandler(Fail) 35 RunSpecs(t, "Source Suite") 36 } 37 38 var testenv *envtest.Environment 39 var config *rest.Config 40 var clientset *kubernetes.Clientset 41 var icache cache.Cache 42 var ctx context.Context 43 var cancel context.CancelFunc 44 45 var _ = BeforeSuite(func() { 46 ctx, cancel = context.WithCancel(context.Background()) 47 logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) 48 49 testenv = &envtest.Environment{} 50 51 var err error 52 config, err = testenv.Start() 53 Expect(err).NotTo(HaveOccurred()) 54 55 clientset, err = kubernetes.NewForConfig(config) 56 Expect(err).NotTo(HaveOccurred()) 57 58 icache, err = cache.New(config, cache.Options{}) 59 Expect(err).NotTo(HaveOccurred()) 60 61 go func() { 62 defer GinkgoRecover() 63 Expect(icache.Start(ctx)).NotTo(HaveOccurred()) 64 }() 65 }) 66 67 var _ = AfterSuite(func() { 68 cancel() 69 Expect(testenv.Stop()).To(Succeed()) 70 })