Skip to content

Commit 0bb2c57

Browse files
committed
add recorder test
1 parent fb97e26 commit 0bb2c57

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

pkg/recorder/recorder_suite_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
"testing"
21+
"time"
22+
23+
logf "github.com/kubernetes-sigs/controller-runtime/pkg/runtime/log"
24+
"github.com/kubernetes-sigs/controller-runtime/pkg/test"
25+
. "github.com/onsi/ginkgo"
26+
. "github.com/onsi/gomega"
27+
"k8s.io/client-go/kubernetes"
28+
"k8s.io/client-go/rest"
29+
)
30+
31+
func TestRecorder(t *testing.T) {
32+
RegisterFailHandler(Fail)
33+
RunSpecsWithDefaultAndCustomReporters(t, "Recorder Integration Suite", []Reporter{test.NewlineReporter{}})
34+
}
35+
36+
var testenv *test.Environment
37+
var cfg *rest.Config
38+
var clientset *kubernetes.Clientset
39+
40+
var _ = BeforeSuite(func(done Done) {
41+
logf.SetLogger(logf.ZapLogger(false))
42+
43+
testenv = &test.Environment{}
44+
45+
var err error
46+
cfg, err = testenv.Start()
47+
Expect(err).NotTo(HaveOccurred())
48+
49+
time.Sleep(1 * time.Second)
50+
51+
clientset, err = kubernetes.NewForConfig(cfg)
52+
Expect(err).NotTo(HaveOccurred())
53+
54+
close(done)
55+
}, 60)
56+
57+
var _ = AfterSuite(func() {
58+
testenv.Stop()
59+
})

pkg/recorder/recorder_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
"fmt"
21+
22+
"github.com/kubernetes-sigs/controller-runtime/pkg/recorder"
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
"k8s.io/client-go/kubernetes/scheme"
26+
)
27+
28+
var _ = Describe("recorder", func() {
29+
Describe("GetEventRecorder", func() {
30+
It("should return a recorder instance and a nil error.", func() {
31+
provider := recorder.NewProvider()
32+
provider.SetScheme(scheme.Scheme)
33+
provider.SetClientSet(clientset)
34+
35+
_, err := provider.GetEventRecorderFor("test")
36+
Expect(err).NotTo(HaveOccurred())
37+
})
38+
39+
It("should return an error if Scheme not set.", func() {
40+
provider := recorder.NewProvider()
41+
provider.SetClientSet(clientset)
42+
43+
recorder, err := provider.GetEventRecorderFor("test")
44+
Expect(recorder).To(BeNil())
45+
Expect(err).To(Equal(fmt.Errorf("must call SetScheme to specify Scheme before getting recorder")))
46+
})
47+
48+
It("should return an error if ClientSet not set.", func() {
49+
provider := recorder.NewProvider()
50+
provider.SetScheme(scheme.Scheme)
51+
52+
recorder, err := provider.GetEventRecorderFor("test")
53+
Expect(recorder).To(BeNil())
54+
Expect(err).To(Equal(fmt.Errorf("must call SetClientSet to specify ClientSet before getting recorder")))
55+
})
56+
})
57+
})

0 commit comments

Comments
 (0)