2015-04-11 00:29:56 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
2015-04-11 00:29:56 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package kubelet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-17 22:21:55 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-04-11 00:29:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeEvent struct {
|
|
|
|
object runtime.Object
|
2015-09-17 22:21:55 +00:00
|
|
|
timestamp unversioned.Time
|
2015-04-11 00:29:56 +00:00
|
|
|
reason string
|
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeRecorder struct {
|
|
|
|
events []fakeEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f fakeRecorder) Event(object runtime.Object, reason, message string) {
|
2015-09-17 22:21:55 +00:00
|
|
|
f.events = append(f.events, fakeEvent{object, unversioned.Now(), reason, message})
|
2015-04-11 00:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f fakeRecorder) Eventf(object runtime.Object, reason, messageFmt string, args ...interface{}) {
|
2015-09-17 22:21:55 +00:00
|
|
|
f.events = append(f.events, fakeEvent{object, unversioned.Now(), reason, fmt.Sprintf(messageFmt, args...)})
|
2015-04-11 00:29:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 22:21:55 +00:00
|
|
|
func (f fakeRecorder) PastEventf(object runtime.Object, timestamp unversioned.Time, reason, messageFmt string, args ...interface{}) {
|
2015-04-11 00:29:56 +00:00
|
|
|
f.events = append(f.events, fakeEvent{object, timestamp, reason, fmt.Sprintf(messageFmt, args...)})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasic(t *testing.T) {
|
|
|
|
fakeRecorder := fakeRecorder{}
|
|
|
|
mockCadvisor := &cadvisor.Fake{}
|
|
|
|
node := &api.ObjectReference{}
|
|
|
|
oomWatcher := NewOOMWatcher(mockCadvisor, fakeRecorder)
|
2015-05-18 19:18:12 +00:00
|
|
|
err := oomWatcher.Start(node)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Should not have failed: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-04-11 00:29:56 +00:00
|
|
|
// TODO: Improve this test once cadvisor exports events.EventChannel as an interface
|
|
|
|
// and thereby allow using a mock version of cadvisor.
|
|
|
|
}
|