
This diff contains a strict refactor; there are no behavioral changes. Address a long standing TODO in `oom_watcher_linux_test.go` around test coverage. We refactor our `oom.Watcher` so it takes in a struct fulfulling the `streamer` interface (i.e. defines `StreamOoms` method). In production, we will continue to use the `oomparser` from `cadvisor`. However, for testing purposes, we can now create our own `fakeStreamer`, and control how it streams `oomparser.OomInstance`. With this fake, we can implement richer unit testing for the `oom.Watcher` itself. Actually adding the additional unit tests will come in a later commit.
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
/*
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
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 oom
|
|
|
|
import (
|
|
"testing"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
"k8s.io/client-go/tools/record"
|
|
|
|
"github.com/google/cadvisor/utils/oomparser"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestBasic verifies that the OOMWatch works without error.
|
|
func TestBasic(t *testing.T) {
|
|
fakeRecorder := &record.FakeRecorder{}
|
|
node := &v1.ObjectReference{}
|
|
|
|
// TODO: Substitute this `oomStreamer` out for a fake, and then write
|
|
// more comprehensive unit tests of the actual behavior.
|
|
oomStreamer, err := oomparser.New()
|
|
assert.NoError(t, err)
|
|
|
|
oomWatcher := &realWatcher{
|
|
recorder: fakeRecorder,
|
|
oomStreamer: oomStreamer,
|
|
}
|
|
assert.NoError(t, oomWatcher.Start(node))
|
|
}
|