Code refactoring for bpa operator
[icn.git] / cmd / bpa-operator / vendor / k8s.io / client-go / tools / record / fake.go
1 /*
2 Copyright 2015 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 record
18
19 import (
20         "fmt"
21
22         metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23         "k8s.io/apimachinery/pkg/runtime"
24 )
25
26 // FakeRecorder is used as a fake during tests. It is thread safe. It is usable
27 // when created manually and not by NewFakeRecorder, however all events may be
28 // thrown away in this case.
29 type FakeRecorder struct {
30         Events chan string
31 }
32
33 func (f *FakeRecorder) Event(object runtime.Object, eventtype, reason, message string) {
34         if f.Events != nil {
35                 f.Events <- fmt.Sprintf("%s %s %s", eventtype, reason, message)
36         }
37 }
38
39 func (f *FakeRecorder) Eventf(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) {
40         if f.Events != nil {
41                 f.Events <- fmt.Sprintf(eventtype+" "+reason+" "+messageFmt, args...)
42         }
43 }
44
45 func (f *FakeRecorder) PastEventf(object runtime.Object, timestamp metav1.Time, eventtype, reason, messageFmt string, args ...interface{}) {
46 }
47
48 func (f *FakeRecorder) AnnotatedEventf(object runtime.Object, annotations map[string]string, eventtype, reason, messageFmt string, args ...interface{}) {
49         f.Eventf(object, eventtype, reason, messageFmt, args)
50 }
51
52 // NewFakeRecorder creates new fake event recorder with event channel with
53 // buffer of given size.
54 func NewFakeRecorder(bufferSize int) *FakeRecorder {
55         return &FakeRecorder{
56                 Events: make(chan string, bufferSize),
57         }
58 }