Skip to content

Commit b28d5c1

Browse files
committed
apis/nfd: drop unused validate function
1 parent 74bc3bb commit b28d5c1

File tree

2 files changed

+0
-116
lines changed

2 files changed

+0
-116
lines changed

pkg/apis/nfd/v1alpha1/expression.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -41,55 +41,6 @@ var matchOps = map[MatchOp]struct{}{
4141
MatchIsFalse: {},
4242
}
4343

44-
// Validate validates the expression.
45-
func (m *MatchExpression) Validate() error {
46-
if _, ok := matchOps[m.Op]; !ok {
47-
return fmt.Errorf("invalid Op %q", m.Op)
48-
}
49-
switch m.Op {
50-
case MatchExists, MatchDoesNotExist, MatchIsTrue, MatchIsFalse, MatchAny:
51-
if len(m.Value) != 0 {
52-
return fmt.Errorf("value must be empty for Op %q (have %v)", m.Op, m.Value)
53-
}
54-
case MatchGt, MatchLt:
55-
if len(m.Value) != 1 {
56-
return fmt.Errorf("value must contain exactly one element for Op %q (have %v)", m.Op, m.Value)
57-
}
58-
if _, err := strconv.Atoi(m.Value[0]); err != nil {
59-
return fmt.Errorf("value must be an integer for Op %q (have %v)", m.Op, m.Value[0])
60-
}
61-
case MatchGtLt:
62-
if len(m.Value) != 2 {
63-
return fmt.Errorf("value must contain exactly two elements for Op %q (have %v)", m.Op, m.Value)
64-
}
65-
var err error
66-
v := make([]int, 2)
67-
for i := 0; i < 2; i++ {
68-
if v[i], err = strconv.Atoi(m.Value[i]); err != nil {
69-
return fmt.Errorf("value must contain integers for Op %q (have %v)", m.Op, m.Value)
70-
}
71-
}
72-
if v[0] >= v[1] {
73-
return fmt.Errorf("value[0] must be less than Value[1] for Op %q (have %v)", m.Op, m.Value)
74-
}
75-
case MatchInRegexp:
76-
if len(m.Value) == 0 {
77-
return fmt.Errorf("value must be non-empty for Op %q", m.Op)
78-
}
79-
for _, v := range m.Value {
80-
_, err := regexp.Compile(v)
81-
if err != nil {
82-
return fmt.Errorf("value must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
83-
}
84-
}
85-
default:
86-
if len(m.Value) == 0 {
87-
return fmt.Errorf("value must be non-empty for Op %q", m.Op)
88-
}
89-
}
90-
return nil
91-
}
92-
9344
// Match evaluates the MatchExpression against a single input value.
9445
func (m *MatchExpression) Match(valid bool, value interface{}) (bool, error) {
9546
if _, ok := matchOps[m.Op]; !ok {

pkg/apis/nfd/v1alpha1/expression_test.go

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -29,73 +29,6 @@ type BoolAssertionFunc func(assert.TestingT, bool, ...interface{}) bool
2929

3030
type ValueAssertionFunc func(assert.TestingT, interface{}, ...interface{}) bool
3131

32-
func TestMatchExpressionValidate(t *testing.T) {
33-
type V = api.MatchValue
34-
type TC struct {
35-
name string
36-
op api.MatchOp
37-
values V
38-
err ValueAssertionFunc
39-
}
40-
41-
tcs := []TC{
42-
{name: "1", op: api.MatchAny, err: assert.Nil}, // #0
43-
{name: "2", op: api.MatchAny, values: V{"1"}, err: assert.NotNil},
44-
45-
{name: "3", op: api.MatchIn, err: assert.NotNil},
46-
{name: "4", op: api.MatchIn, values: V{"1"}, err: assert.Nil},
47-
{name: "5", op: api.MatchIn, values: V{"1", "2", "3", "4"}, err: assert.Nil},
48-
49-
{name: "6", op: api.MatchNotIn, err: assert.NotNil},
50-
{name: "7", op: api.MatchNotIn, values: V{"1"}, err: assert.Nil},
51-
{name: "8", op: api.MatchNotIn, values: V{"1", "2"}, err: assert.Nil},
52-
53-
{name: "9", op: api.MatchInRegexp, err: assert.NotNil},
54-
{name: "10", op: api.MatchInRegexp, values: V{"1"}, err: assert.Nil},
55-
{name: "11", op: api.MatchInRegexp, values: V{"()", "2", "3"}, err: assert.Nil},
56-
{name: "12", op: api.MatchInRegexp, values: V{"("}, err: assert.NotNil},
57-
58-
{name: "13", op: api.MatchExists, err: assert.Nil},
59-
{name: "14", op: api.MatchExists, values: V{"1"}, err: assert.NotNil},
60-
61-
{name: "15", op: api.MatchDoesNotExist, err: assert.Nil},
62-
{name: "16", op: api.MatchDoesNotExist, values: V{"1"}, err: assert.NotNil},
63-
64-
{name: "17", op: api.MatchGt, err: assert.NotNil},
65-
{name: "18", op: api.MatchGt, values: V{"1"}, err: assert.Nil},
66-
{name: "19", op: api.MatchGt, values: V{"-10"}, err: assert.Nil},
67-
{name: "20", op: api.MatchGt, values: V{"1", "2"}, err: assert.NotNil},
68-
{name: "21", op: api.MatchGt, values: V{""}, err: assert.NotNil},
69-
70-
{name: "22", op: api.MatchLt, err: assert.NotNil},
71-
{name: "23", op: api.MatchLt, values: V{"1"}, err: assert.Nil},
72-
{name: "24", op: api.MatchLt, values: V{"-1"}, err: assert.Nil},
73-
{name: "25", op: api.MatchLt, values: V{"1", "2", "3"}, err: assert.NotNil},
74-
{name: "26", op: api.MatchLt, values: V{"a"}, err: assert.NotNil},
75-
76-
{name: "27", op: api.MatchGtLt, err: assert.NotNil},
77-
{name: "28", op: api.MatchGtLt, values: V{"1"}, err: assert.NotNil},
78-
{name: "29", op: api.MatchGtLt, values: V{"1", "2"}, err: assert.Nil},
79-
{name: "30", op: api.MatchGtLt, values: V{"2", "1"}, err: assert.NotNil},
80-
{name: "31", op: api.MatchGtLt, values: V{"1", "2", "3"}, err: assert.NotNil},
81-
{name: "32", op: api.MatchGtLt, values: V{"a", "2"}, err: assert.NotNil},
82-
83-
{name: "33", op: api.MatchIsTrue, err: assert.Nil},
84-
{name: "34", op: api.MatchIsTrue, values: V{"1"}, err: assert.NotNil},
85-
86-
{name: "35", op: api.MatchIsFalse, err: assert.Nil},
87-
{name: "36", op: api.MatchIsFalse, values: V{"1", "2"}, err: assert.NotNil},
88-
}
89-
90-
for _, tc := range tcs {
91-
t.Run(tc.name, func(t *testing.T) {
92-
me := api.MatchExpression{Op: tc.op, Value: tc.values}
93-
err := me.Validate()
94-
tc.err(t, err)
95-
})
96-
}
97-
}
98-
9932
func TestMatch(t *testing.T) {
10033
type V = api.MatchValue
10134
type TC struct {

0 commit comments

Comments
 (0)