sigs.k8s.io/controller-runtime@v0.18.2/pkg/internal/recorder/recorder_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 recorder_test 18 19 import ( 20 "github.com/go-logr/logr" 21 . "github.com/onsi/ginkgo/v2" 22 . "github.com/onsi/gomega" 23 "k8s.io/client-go/kubernetes/scheme" 24 "k8s.io/client-go/tools/record" 25 "sigs.k8s.io/controller-runtime/pkg/internal/recorder" 26 ) 27 28 var _ = Describe("recorder.Provider", func() { 29 makeBroadcaster := func() (record.EventBroadcaster, bool) { return record.NewBroadcaster(), true } 30 Describe("NewProvider", func() { 31 It("should return a provider instance and a nil error.", func() { 32 provider, err := recorder.NewProvider(cfg, httpClient, scheme.Scheme, logr.Discard(), makeBroadcaster) 33 Expect(provider).NotTo(BeNil()) 34 Expect(err).NotTo(HaveOccurred()) 35 }) 36 37 It("should return an error if failed to init client.", func() { 38 // Invalid the config 39 cfg1 := *cfg 40 cfg1.Host = "invalid host" 41 _, err := recorder.NewProvider(&cfg1, httpClient, scheme.Scheme, logr.Discard(), makeBroadcaster) 42 Expect(err).To(HaveOccurred()) 43 Expect(err.Error()).To(ContainSubstring("failed to init client")) 44 }) 45 }) 46 Describe("GetEventRecorder", func() { 47 It("should return a recorder instance.", func() { 48 provider, err := recorder.NewProvider(cfg, httpClient, scheme.Scheme, logr.Discard(), makeBroadcaster) 49 Expect(err).NotTo(HaveOccurred()) 50 51 recorder := provider.GetEventRecorderFor("test") 52 Expect(recorder).NotTo(BeNil()) 53 }) 54 }) 55 })