Skip to content

Commit

Permalink
Merge pull request #1766 from marquiz/devel/simplify
Browse files Browse the repository at this point in the history
Simplify code
  • Loading branch information
k8s-ci-robot committed Jul 9, 2024
2 parents fdddae2 + b5b701f commit 3bb7a1c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions api/nfd/v1alpha1/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ func TestFeature(t *testing.T) {
f2.Instances["dom.inst"] = NewInstanceFeatures(*NewInstanceFeature(map[string]string{"a1": "v3.1", "a3": "v3.3"}))
f2.MergeInto(&f)
expectedFeatures = *NewFeatures()
expectedFeatures.Flags["dom.flag"] = FlagFeatureSet{Elements: map[string]Nil{"k1": Nil{}, "k2": Nil{}, "k3": Nil{}}}
expectedFeatures.Flags["dom.flag"] = FlagFeatureSet{Elements: map[string]Nil{"k1": {}, "k2": {}, "k3": {}}}
expectedFeatures.Attributes["dom.attr"] = AttributeFeatureSet{Elements: map[string]string{"k1": "v1.override", "k2": "v2"}}
expectedFeatures.Instances["dom.inst"] = InstanceFeatureSet{
Elements: []InstanceFeature{
InstanceFeature{Attributes: map[string]string{"a1": "v1.1", "a2": "v1.2"}},
InstanceFeature{Attributes: map[string]string{"a1": "v2.1", "a2": "v2.2"}},
InstanceFeature{Attributes: map[string]string{"a1": "v3.1", "a3": "v3.3"}},
{Attributes: map[string]string{"a1": "v1.1", "a2": "v1.2"}},
{Attributes: map[string]string{"a1": "v2.1", "a2": "v2.2"}},
{Attributes: map[string]string{"a1": "v3.1", "a3": "v3.3"}},
},
}
assert.Equal(t, expectedFeatures, f)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestFeatureSpec(t *testing.T) {

expectedFeatures.Labels["l1"] = "v1.override"
expectedFeatures.Labels["l3"] = "v3"
expectedFeatures.Features.Flags["dom.flag2"] = FlagFeatureSet{Elements: map[string]Nil{"k3": Nil{}}}
expectedFeatures.Features.Flags["dom.flag2"] = FlagFeatureSet{Elements: map[string]Nil{"k3": {}}}

f2.MergeInto(&f)
assert.Equal(t, expectedFeatures, f)
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/nfd/nodefeaturerule/expression-api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ func TestMatchInstances(t *testing.T) {

{name: "2", input: []I{}, output: O{}, result: assert.False, err: assert.Nil}, // zero instances -> false

{name: "3", input: []I{I{Attributes: A{}}}, output: O{A{}}, result: assert.True, err: assert.Nil}, // one "empty" instance
{name: "3", input: []I{{Attributes: A{}}}, output: O{A{}}, result: assert.True, err: assert.Nil}, // one "empty" instance

{name: "4",
mes: `
foo: { op: Exists }
bar: { op: Lt, value: ["10"] }
`,
input: []I{I{Attributes: A{"foo": "1"}}, I{Attributes: A{"bar": "1"}}},
input: []I{{Attributes: A{"foo": "1"}}, {Attributes: A{"bar": "1"}}},
output: O{},
result: assert.False, err: assert.Nil},

Expand All @@ -229,15 +229,15 @@ bar: { op: Lt, value: ["10"] }
foo: { op: Exists }
bar: { op: Lt, value: ["10"] }
`,
input: []I{I{Attributes: A{"foo": "1"}}, I{Attributes: A{"foo": "2", "bar": "1"}}},
input: []I{{Attributes: A{"foo": "1"}}, {Attributes: A{"foo": "2", "bar": "1"}}},
output: O{A{"foo": "2", "bar": "1"}},
result: assert.True, err: assert.Nil},

{name: "6",
mes: `
bar: { op: Lt, value: ["10"] }
`,
input: []I{I{Attributes: A{"foo": "1"}}, I{Attributes: A{"bar": "0x1"}}},
input: []I{{Attributes: A{"foo": "1"}}, {Attributes: A{"bar": "0x1"}}},
result: assert.False, err: assert.NotNil},
}

Expand Down
4 changes: 2 additions & 2 deletions source/custom/static_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// e.g RMDA related features. NFD configuration file may extend these custom features by adding rules.
func getStaticRules() []nfdv1alpha1.Rule {
return []nfdv1alpha1.Rule{
nfdv1alpha1.Rule{
{
Name: "RDMA capable static rule",
Labels: map[string]string{"rdma.capable": "true"},
MatchFeatures: nfdv1alpha1.FeatureMatcher{
Expand All @@ -38,7 +38,7 @@ func getStaticRules() []nfdv1alpha1.Rule {
},
},
},
nfdv1alpha1.Rule{
{
Name: "RDMA available static rule",
Labels: map[string]string{"rdma.available": "true"},
MatchFeatures: nfdv1alpha1.FeatureMatcher{
Expand Down
6 changes: 3 additions & 3 deletions source/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ func newDefaultConfig() *Config {
"attr_3": "10",
},
InstanceFeatures: []FakeInstance{
FakeInstance{
{
"name": "instance_1",
"attr_1": "true",
"attr_2": "false",
"attr_3": "10",
"attr_4": "foobar",
},
FakeInstance{
{
"name": "instance_2",
"attr_1": "true",
"attr_2": "true",
"attr_3": "100",
},
FakeInstance{
{
"name": "instance_3",
},
},
Expand Down
6 changes: 3 additions & 3 deletions source/pci/pci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ func TestPciSource(t *testing.T) {
// Specify expected "raw" features. These are always the same for the same
// mocked sysfs.
expectedFeatures := map[string]*nfdv1alpha1.Features{
"rootfs-empty": &nfdv1alpha1.Features{
"rootfs-empty": {
Flags: map[string]nfdv1alpha1.FlagFeatureSet{},
Attributes: map[string]nfdv1alpha1.AttributeFeatureSet{},
Instances: map[string]nfdv1alpha1.InstanceFeatureSet{},
},
"rootfs-1": &nfdv1alpha1.Features{
"rootfs-1": {
Flags: map[string]nfdv1alpha1.FlagFeatureSet{},
Attributes: map[string]nfdv1alpha1.AttributeFeatureSet{},
Instances: map[string]nfdv1alpha1.InstanceFeatureSet{
"device": nfdv1alpha1.InstanceFeatureSet{
"device": {
Elements: []nfdv1alpha1.InstanceFeature{
{
Attributes: map[string]string{
Expand Down

0 comments on commit 3bb7a1c

Please sign in to comment.