mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
81378a3235
Implement new registration infrastructure under the "source" package. This change loosens the coupling between label sources and the nfd-worker, making it easier to refactor and move the code around. Also, create a separate interface (ConfigurableSource) for configurable feature sources in order to eliminate boilerplate code. Add safety checks to the sources that they actually implement the interfaces they should. In sake of consistency and predictability (of behavior) change all methods of the sources to use pointer receivers. Add simple unit tests for the new functionality and include source/... into make test target.
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
/*
|
|
Copyright 2021 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 source_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
source "sigs.k8s.io/node-feature-discovery/source"
|
|
|
|
// Register all source packages
|
|
_ "sigs.k8s.io/node-feature-discovery/source/cpu"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/custom"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/fake"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/iommu"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/kernel"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/local"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/memory"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/network"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/pci"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/storage"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/system"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/usb"
|
|
)
|
|
|
|
func TestLabelSources(t *testing.T) {
|
|
sources := source.GetAllLabelSources()
|
|
assert.NotZero(t, len(sources))
|
|
|
|
for n, s := range sources {
|
|
assert.Equalf(t, n, s.Name(), "testing labelsource %q failed", n)
|
|
}
|
|
}
|
|
|
|
func TestConfigurableSources(t *testing.T) {
|
|
sources := source.GetAllConfigurableSources()
|
|
assert.NotZero(t, len(sources))
|
|
|
|
for n, s := range sources {
|
|
assert.Equalf(t, n, s.Name(), "testing ConfigurableSource %q failed", n)
|
|
|
|
c := s.NewConfig()
|
|
s.SetConfig(c)
|
|
rc := s.GetConfig()
|
|
|
|
assert.Equalf(t, c, rc, "testing ConfigurableSource %q failed", n)
|
|
}
|
|
}
|