k8s.io/client-go@v0.22.2/tools/events/fake.go (about) 1 /* 2 Copyright 2019 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 events 18 19 import ( 20 "fmt" 21 22 "k8s.io/apimachinery/pkg/runtime" 23 ) 24 25 // FakeRecorder is used as a fake during tests. It is thread safe. It is usable 26 // when created manually and not by NewFakeRecorder, however all events may be 27 // thrown away in this case. 28 type FakeRecorder struct { 29 Events chan string 30 } 31 32 // Eventf emits an event 33 func (f *FakeRecorder) Eventf(regarding runtime.Object, related runtime.Object, eventtype, reason, action, note string, args ...interface{}) { 34 if f.Events != nil { 35 f.Events <- fmt.Sprintf(eventtype+" "+reason+" "+note, args...) 36 } 37 } 38 39 // NewFakeRecorder creates new fake event recorder with event channel with 40 // buffer of given size. 41 func NewFakeRecorder(bufferSize int) *FakeRecorder { 42 return &FakeRecorder{ 43 Events: make(chan string, bufferSize), 44 } 45 }