@@ -402,3 +402,127 @@ func TestGDRCopyGetImagePath(t *testing.T) {
402402 })
403403 }
404404}
405+
406+ func TestGDRCopyGetPrecompiledImagePath (t * testing.T ) {
407+ testCases := []struct {
408+ description string
409+ spec * GDRCopySpec
410+ osVersion string
411+ kernelVersion string
412+ errorExpected bool
413+ expectedImage string
414+ }{
415+ {
416+ description : "malformed repository" ,
417+ spec : & GDRCopySpec {
418+ Repository : "malformed?/repo" ,
419+ },
420+ errorExpected : true ,
421+ expectedImage : "" ,
422+ },
423+ {
424+ description : "malformed image" ,
425+ spec : & GDRCopySpec {
426+ Image : "malformed?image" ,
427+ },
428+ errorExpected : true ,
429+ expectedImage : "" ,
430+ },
431+ {
432+ description : "only image provided with no tag or digest" ,
433+ spec : & GDRCopySpec {
434+ Image : "nvcr.io/nvidia/cloud-native/gdrdrv" ,
435+ },
436+ errorExpected : true ,
437+ expectedImage : "" ,
438+ },
439+ {
440+ description : "only image provided with tag" ,
441+ spec : & GDRCopySpec {
442+ Image : "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2" ,
443+ },
444+ osVersion : "ubuntu22.04" ,
445+ kernelVersion : "5.4.0-150-generic" ,
446+ expectedImage : "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2-5.4.0-150-generic-ubuntu22.04" ,
447+ },
448+ {
449+ description : "only image provided with digest" ,
450+ spec : & GDRCopySpec {
451+ Image : "nvcr.io/nvidia/cloud-native/gdrdrv@sha256:" + testDigest ,
452+ },
453+ osVersion : "ubuntu22.04" ,
454+ kernelVersion : "5.4.0-150-generic" ,
455+ errorExpected : true ,
456+ expectedImage : "" ,
457+ },
458+ {
459+ description : "repository, image, and version set but image contains a tag" ,
460+ spec : & GDRCopySpec {
461+ Repository : "nvcr.io/nvidia/cloud-native" ,
462+ Image : "nvcr.io/nvidia/cloud-native/gdrdrv:v2.4.1" ,
463+ Version : "v2.5.2" ,
464+ },
465+ osVersion : "ubuntu22.04" ,
466+ kernelVersion : "5.4.0-150-generic" ,
467+ errorExpected : true ,
468+ expectedImage : "" ,
469+ },
470+ {
471+ description : "repository, image, and version set but image contains a digest" ,
472+ spec : & GDRCopySpec {
473+ Repository : "nvcr.io/nvidia/cloud-native" ,
474+ Image : "nvcr.io/nvidia/cloud-native/gdrdrv@sha256:" + testDigest ,
475+ Version : "v2.5.2" ,
476+ },
477+ osVersion : "ubuntu22.04" ,
478+ kernelVersion : "5.4.0-150-generic" ,
479+ errorExpected : true ,
480+ expectedImage : "" ,
481+ },
482+ {
483+ description : "missing version" ,
484+ spec : & GDRCopySpec {
485+ Repository : "nvcr.io/nvidia/cloud-native" ,
486+ Image : "gdrdrv" ,
487+ },
488+ osVersion : "ubuntu22.04" ,
489+ kernelVersion : "5.4.0-150-generic" ,
490+ errorExpected : true ,
491+ expectedImage : "" ,
492+ },
493+ {
494+ description : "repository, image, and version set; version is a tag" ,
495+ spec : & GDRCopySpec {
496+ Repository : "nvcr.io/nvidia/cloud-native" ,
497+ Image : "gdrdrv" ,
498+ Version : "v2.5.2" ,
499+ },
500+ osVersion : "ubuntu22.04" ,
501+ kernelVersion : "5.4.0-150-generic" ,
502+ expectedImage : "nvcr.io/nvidia/cloud-native/gdrdrv:v2.5.2-5.4.0-150-generic-ubuntu22.04" ,
503+ },
504+ {
505+ description : "repository, image, and version set; version is a digest" ,
506+ spec : & GDRCopySpec {
507+ Repository : "nvcr.io/nvidia/cloud-native" ,
508+ Image : "gdrdrv" ,
509+ Version : "sha256:" + testDigest ,
510+ },
511+ osVersion : "ubuntu22.04" ,
512+ kernelVersion : "5.4.0-150-generic" ,
513+ errorExpected : true ,
514+ },
515+ }
516+
517+ for _ , tc := range testCases {
518+ t .Run (tc .description , func (t * testing.T ) {
519+ image , err := tc .spec .GetPrecompiledImagePath (tc .osVersion , tc .kernelVersion )
520+ if tc .errorExpected {
521+ require .Error (t , err )
522+ } else {
523+ require .NoError (t , err )
524+ }
525+ require .Equal (t , image , tc .expectedImage )
526+ })
527+ }
528+ }
0 commit comments