|
| 1 | +/* |
| 2 | +2024 NVIDIA CORPORATION & AFFILIATES |
| 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 state_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/Mellanox/network-operator/pkg/clustertype" |
| 21 | + "github.com/Mellanox/network-operator/pkg/nodeinfo" |
| 22 | + "github.com/Mellanox/network-operator/pkg/state" |
| 23 | + "github.com/Mellanox/network-operator/pkg/staticconfig" |
| 24 | +) |
| 25 | + |
| 26 | +type testProvider struct { |
| 27 | + isOpenshift bool |
| 28 | + cniBinDir string |
| 29 | +} |
| 30 | + |
| 31 | +func (tp *testProvider) GetClusterType() clustertype.Type { |
| 32 | + if tp.isOpenshift { |
| 33 | + return clustertype.Openshift |
| 34 | + } |
| 35 | + return clustertype.Kubernetes |
| 36 | +} |
| 37 | + |
| 38 | +func (tp *testProvider) IsKubernetes() bool { |
| 39 | + return !tp.isOpenshift |
| 40 | +} |
| 41 | + |
| 42 | +func (tp *testProvider) IsOpenshift() bool { |
| 43 | + return tp.isOpenshift |
| 44 | +} |
| 45 | + |
| 46 | +func (tp *testProvider) GetStaticConfig() staticconfig.StaticConfig { |
| 47 | + return staticconfig.StaticConfig{CniBinDirectory: tp.cniBinDir} |
| 48 | +} |
| 49 | + |
| 50 | +func (tp *testProvider) GetNodesAttributes(...nodeinfo.Filter) []nodeinfo.NodeAttributes { |
| 51 | + nodeAttr := make(map[nodeinfo.AttributeType]string) |
| 52 | + nodeAttr[nodeinfo.AttrTypeCPUArch] = "amd64" |
| 53 | + nodeAttr[nodeinfo.AttrTypeOSName] = "ubuntu" |
| 54 | + nodeAttr[nodeinfo.AttrTypeOSVer] = "20.04" |
| 55 | + |
| 56 | + return []nodeinfo.NodeAttributes{{Attributes: nodeAttr}} |
| 57 | +} |
| 58 | + |
| 59 | +func getTestCatalog() state.InfoCatalog { |
| 60 | + catalog := state.NewInfoCatalog() |
| 61 | + tp := &testProvider{isOpenshift: false, cniBinDir: ""} |
| 62 | + catalog.Add(state.InfoTypeNodeInfo, tp) |
| 63 | + catalog.Add(state.InfoTypeStaticConfig, tp) |
| 64 | + catalog.Add(state.InfoTypeClusterType, tp) |
| 65 | + |
| 66 | + return catalog |
| 67 | +} |
0 commit comments