File tree 3 files changed +16
-15
lines changed 3 files changed +16
-15
lines changed Original file line number Diff line number Diff line change @@ -209,18 +209,9 @@ func MinimumRequiredVersion(spec *cdi.Spec) (string, error) {
209
209
210
210
// Validate the Spec.
211
211
func (s * Spec ) validate () (map [string ]* Device , error ) {
212
- if err := cdi .ValidateVersion (s .Version ); err != nil {
212
+ if err := cdi .ValidateVersion (s .Spec ); err != nil {
213
213
return nil , err
214
214
}
215
-
216
- minVersion , err := cdi .MinimumRequiredVersion (s .Spec )
217
- if err != nil {
218
- return nil , fmt .Errorf ("could not determine minimum required version: %v" , err )
219
- }
220
- if cdi .NewVersion (minVersion ).IsGreaterThan (cdi .NewVersion (s .Version )) {
221
- return nil , fmt .Errorf ("the spec version must be at least v%v" , minVersion )
222
- }
223
-
224
215
if err := ValidateVendorName (s .vendor ); err != nil {
225
216
return nil , err
226
217
}
Original file line number Diff line number Diff line change @@ -525,7 +525,7 @@ func specType(content []byte) string {
525
525
}
526
526
527
527
func TestCurrentVersionIsValid (t * testing.T ) {
528
- require .NoError (t , cdi .ValidateVersion (cdi .CurrentVersion ))
528
+ require .NoError (t , cdi .ValidateVersion (& cdi.Spec { Version : cdi . CurrentVersion } ))
529
529
}
530
530
531
531
func TestRequiredVersion (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -58,10 +58,20 @@ var validSpecVersions = requiredVersionMap{
58
58
v080 : requiresV080 ,
59
59
}
60
60
61
- // ValidateVersion checks whether the specified spec version is supported.
62
- func ValidateVersion (version string ) error {
63
- if ! validSpecVersions .isValidVersion (version ) {
64
- return fmt .Errorf ("invalid version %q" , version )
61
+ // ValidateVersion checks whether the specified spec version is valid.
62
+ // In addition to checking whether the spec version is in the set of known versions,
63
+ // the spec is inspected to determine whether the features used are available in specified
64
+ // version.
65
+ func ValidateVersion (spec * Spec ) error {
66
+ if ! validSpecVersions .isValidVersion (spec .Version ) {
67
+ return fmt .Errorf ("invalid version %q" , spec .Version )
68
+ }
69
+ minVersion , err := MinimumRequiredVersion (spec )
70
+ if err != nil {
71
+ return fmt .Errorf ("could not determine minimum required version: %w" , err )
72
+ }
73
+ if newVersion (minVersion ).IsGreaterThan (newVersion (spec .Version )) {
74
+ return fmt .Errorf ("the spec version must be at least v%v" , minVersion )
65
75
}
66
76
return nil
67
77
}
You can’t perform that action at this time.
0 commit comments