sigs.k8s.io/controller-runtime@v0.18.2/pkg/cluster/cluster_suite_test.go (about) 1 /* 2 Copyright 2020 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 cluster 18 19 import ( 20 "net/http" 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/envtest" 28 logf "sigs.k8s.io/controller-runtime/pkg/log" 29 "sigs.k8s.io/controller-runtime/pkg/log/zap" 30 ) 31 32 func TestSource(t *testing.T) { 33 RegisterFailHandler(Fail) 34 RunSpecs(t, "Cluster Suite") 35 } 36 37 var testenv *envtest.Environment 38 var cfg *rest.Config 39 var clientset *kubernetes.Clientset 40 41 // clientTransport is used to force-close keep-alives in tests that check for leaks. 42 var clientTransport *http.Transport 43 44 var _ = BeforeSuite(func() { 45 logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) 46 47 testenv = &envtest.Environment{} 48 49 var err error 50 cfg, err = testenv.Start() 51 Expect(err).NotTo(HaveOccurred()) 52 53 cfg.WrapTransport = func(rt http.RoundTripper) http.RoundTripper { 54 // NB(directxman12): we can't set Transport *and* use TLS options, 55 // so we grab the transport right after it gets created so that we can 56 // type-assert on it (hopefully)? 57 // hopefully this doesn't break 🤞 58 clientTransport = rt.(*http.Transport) 59 return rt 60 } 61 62 clientset, err = kubernetes.NewForConfig(cfg) 63 Expect(err).NotTo(HaveOccurred()) 64 }) 65 66 var _ = AfterSuite(func() { 67 Expect(testenv.Stop()).To(Succeed()) 68 })