Skip to content

Commit 8db03fe

Browse files
committed
Add unit tests for invalid feature in the compatibility spec
Signed-off-by: Marcin Franczyk <[email protected]>
1 parent 241c886 commit 8db03fe

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/apis/nfd/nodefeaturerule/rule.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,11 @@ func evaluateFeatureMatcher(m *nfdv1alpha1.FeatureMatcher, features *nfdv1alpha1
268268
fA, okA := features.Attributes[featureName]
269269
fI, okI := features.Instances[featureName]
270270
if !okF && !okA && !okI {
271+
klog.V(2).InfoS("feature not available", "featureName", featureName)
271272
if failFast {
272-
klog.V(2).InfoS("feature not available", "featureName", featureName)
273273
return false, nil, nil
274274
}
275+
isMatch = false
275276
continue
276277
}
277278

pkg/client-nfd/compat/node-validator/node-validator_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ func TestNodeValidator(t *testing.T) {
114114
},
115115
},
116116
},
117+
{
118+
Name: "fake_5",
119+
MatchFeatures: v1alpha1.FeatureMatcher{
120+
{
121+
Feature: "unknown.unknown",
122+
MatchExpressions: &v1alpha1.MatchExpressionSet{
123+
"name": &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
124+
},
125+
},
126+
},
127+
},
117128
},
118129
},
119130
},
@@ -219,6 +230,19 @@ func TestNodeValidator(t *testing.T) {
219230
},
220231
},
221232
},
233+
{
234+
Name: "fake_5",
235+
IsMatch: false,
236+
MatchedExpressions: []MatchedExpression{
237+
{
238+
Feature: "unknown.unknown",
239+
Name: "name",
240+
Expression: &v1alpha1.MatchExpression{Op: v1alpha1.MatchIn, Value: v1alpha1.MatchValue{"instance_1"}},
241+
MatcherType: MatchExpressionType,
242+
IsMatch: false,
243+
},
244+
},
245+
},
222246
},
223247
},
224248
}

0 commit comments

Comments
 (0)