1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-30 19:54:46 +00:00
node-feature-discovery/mockapihelpers.go
Cody Roseborough 88c15c2358 Fixes #25: Deletes non-discovered nfd labels
Adds RemoveLabels() to remove all labels from a node that contains the
supplied search string. Uses this to remove node-feature-discovery
labels prior to re-applying newly discovered labels.

This behavior applies to consecutive runs of node-feature-discovery and
whatever restrictions are placed on it. For example if a whitelist is
specified that changes the labels that are discovered, any labels that
do not match the whitelist will be removed. Adds a small note to the
readme to point out this fact.

Adds tests to main_test.go to test the behavior of AddLabels and
RemoveLabels.
2016-11-02 14:40:17 -07:00

86 lines
2 KiB
Go

package main
import (
"github.com/stretchr/testify/mock"
"k8s.io/kubernetes/pkg/api"
client "k8s.io/kubernetes/pkg/client/unversioned"
)
type MockAPIHelpers struct {
mock.Mock
}
// GetClient provides a mock function with no input arguments and
// *client.Client and error as return value
func (_m *MockAPIHelpers) GetClient() (*client.Client, error) {
ret := _m.Called()
var r0 *client.Client
if rf, ok := ret.Get(0).(func() *client.Client); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*client.Client)
}
}
var r1 error
if rf, ok := ret.Get(1).(func() error); ok {
r1 = rf()
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetNode provides a mock function with *client.Client as input argument and
// *api.Node and error as return values
func (_m *MockAPIHelpers) GetNode(_a0 *client.Client) (*api.Node, error) {
ret := _m.Called(_a0)
var r0 *api.Node
if rf, ok := ret.Get(0).(func(*client.Client) *api.Node); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*api.Node)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(*client.Client) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// RemoveLabels provides a mock function with *api.Node and main.Labels as the input arguments and
// no return value
func (_m *MockAPIHelpers) RemoveLabels(_a0 *api.Node, _a1 string) {
_m.Called(_a0, _a1)
}
// AddLabels provides a mock function with *api.Node and main.Labels as the input arguments and
// no return value
func (_m *MockAPIHelpers) AddLabels(_a0 *api.Node, _a1 Labels) {
_m.Called(_a0, _a1)
}
// UpdateNode provides a mock function with *client.Client and *api.Node as the input arguments and
// error as the return value
func (_m *MockAPIHelpers) UpdateNode(_a0 *client.Client, _a1 *api.Node) error {
ret := _m.Called(_a0, _a1)
var r0 error
if rf, ok := ret.Get(0).(func(*client.Client, *api.Node) error); ok {
r0 = rf(_a0, _a1)
} else {
r0 = ret.Error(0)
}
return r0
}