File tree Expand file tree Collapse file tree 3 files changed +16
-15
lines changed Expand file tree Collapse file tree 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) {
209209
210210// Validate the Spec.
211211func (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 {
213213 return nil , err
214214 }
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-
224215 if err := ValidateVendorName (s .vendor ); err != nil {
225216 return nil , err
226217 }
Original file line number Diff line number Diff line change @@ -525,7 +525,7 @@ func specType(content []byte) string {
525525}
526526
527527func TestCurrentVersionIsValid (t * testing.T ) {
528- require .NoError (t , cdi .ValidateVersion (cdi .CurrentVersion ))
528+ require .NoError (t , cdi .ValidateVersion (& cdi.Spec { Version : cdi . CurrentVersion } ))
529529}
530530
531531func TestRequiredVersion (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -58,10 +58,20 @@ var validSpecVersions = requiredVersionMap{
5858 v080 : requiresV080 ,
5959}
6060
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 )
6575 }
6676 return nil
6777}
You can’t perform that action at this time.
0 commit comments