mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-31 04:04:51 +00:00
Add unit tests for extracting and comparing versions
Signed-off-by: Marcin Franczyk <marcin0franczyk@gmail.com>
This commit is contained in:
parent
5490378487
commit
f7a9da693d
2 changed files with 78 additions and 0 deletions
70
api/nfd/v1alpha1/utils_test.go
Normal file
70
api/nfd/v1alpha1/utils_test.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type ValueAssertionFunc func(assert.TestingT, interface{}, ...interface{}) bool
|
||||
|
||||
func TestExtractVersion(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
input string
|
||||
result string
|
||||
err ValueAssertionFunc
|
||||
}{
|
||||
{name: "1", input: "1", result: "1", err: assert.Nil},
|
||||
{name: "2", input: "1.2", result: "1.2", err: assert.Nil},
|
||||
{name: "3", input: "1.2.3", result: "1.2.3", err: assert.Nil},
|
||||
{name: "4", input: "1.2.3-flavor", result: "1.2.3", err: assert.Nil},
|
||||
{name: "5", input: "1.2.3-flavor.2.3.4", result: "1.2.3", err: assert.Nil},
|
||||
{name: "6", input: "flavor-1.2.3", result: "", err: assert.NotNil},
|
||||
{name: "7", input: "A.2.3", result: "", err: assert.NotNil},
|
||||
{name: "8", input: "str", result: "", err: assert.NotNil},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result, err := ExtractVersion(tc.input)
|
||||
assert.Equal(t, result, tc.result)
|
||||
tc.err(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareVersions(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
v1 string
|
||||
v2 string
|
||||
result VersionComparisonResult
|
||||
}{
|
||||
{name: "1", v1: "1", v2: "2", result: CmpLt},
|
||||
{name: "2", v1: "2", v2: "2", result: CmpEq},
|
||||
{name: "3", v1: "3", v2: "2", result: CmpGt},
|
||||
{name: "4", v1: "1.9", v2: "2.0", result: CmpLt},
|
||||
{name: "5", v1: "2.0", v2: "2.0", result: CmpEq},
|
||||
{name: "6", v1: "2.1", v2: "2.0", result: CmpGt},
|
||||
{name: "7", v1: "1.9.9", v2: "2.0.0", result: CmpLt},
|
||||
{name: "8", v1: "2.0.0", v2: "2.0.0", result: CmpEq},
|
||||
{name: "9", v1: "2.0.1", v2: "2.0.0", result: CmpGt},
|
||||
{name: "10", v1: "1", v2: "2.0", result: CmpLt},
|
||||
{name: "11", v1: "2", v2: "2.0", result: CmpEq},
|
||||
{name: "12", v1: "3", v2: "2.0", result: CmpGt},
|
||||
{name: "13", v1: "1", v2: "2.0.0", result: CmpLt},
|
||||
{name: "14", v1: "2", v2: "2.0.0", result: CmpEq},
|
||||
{name: "15", v1: "3", v2: "2.0.0", result: CmpGt},
|
||||
{name: "16", v1: "1.9.9", v2: "2", result: CmpLt},
|
||||
{name: "17", v1: "2.0.0", v2: "2", result: CmpEq},
|
||||
{name: "18", v1: "2.0.1", v2: "2", result: CmpGt},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
result := CompareVersions(tc.v1, tc.v2)
|
||||
assert.Equal(t, result, tc.result)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -786,6 +786,7 @@ feature.
|
|||
value:
|
||||
- <value-1>
|
||||
- ...
|
||||
type: <type>
|
||||
```
|
||||
|
||||
In each MatchExpression the `key` specifies the name of of the feature element
|
||||
|
@ -820,6 +821,13 @@ below.
|
|||
The `value` field of MatchExpression is a list of string arguments to the
|
||||
operator.
|
||||
|
||||
Type optional `type` field specifies the type of the `value` field.
|
||||
Valid types for specific operators are described below.
|
||||
|
||||
| Type | Description | Supported Operators |
|
||||
| --------- | ----------- | ------------------- |
|
||||
| `version` | Input is recognized as a version in the following formats `%d.%d.%d`, `%d.%d`, `%d` (e.g., "1.2.3", "1.2", "1") |`Gt`,`Ge`,`Lt`,`Le`,`GtLt`,`GeLe` |
|
||||
|
||||
##### matchName
|
||||
|
||||
The `.matchFeatures[].matchName` field is used to match against the
|
||||
|
|
Loading…
Add table
Reference in a new issue