@@ -93,6 +93,7 @@ type testParameters struct {
9393 k8sSourceDir string
9494 testFocus string
9595 testSkip string
96+ storageClassFile string
9697 snapshotClassFile string
9798 cloudProviderArgs []string
9899 deploymentStrategy string
@@ -501,21 +502,27 @@ func handle() error {
501502 applicableSnapshotClassFiles = append (applicableSnapshotClassFiles , snapshotClassFile )
502503 }
503504 }
504- if len (applicableSnapshotClassFiles ) == 0 {
505- // when no snapshot class specified, we run the tests without snapshot capability
506- applicableSnapshotClassFiles = append (applicableSnapshotClassFiles , "" )
507- }
508505 var ginkgoErrors []string
509506 var testOutputDirs []string
507+
508+ // Run non-snapshot tests.
509+ testParams .snapshotClassFile = ""
510510 for _ , scFile := range applicableStorageClassFiles {
511511 outputDir := strings .TrimSuffix (scFile , ".yaml" )
512+ testOutputDirs = append (testOutputDirs , outputDir )
513+ testParams .storageClassFile = scFile
514+ if err = runCSITests (testParams , outputDir ); err != nil {
515+ ginkgoErrors = append (ginkgoErrors , err .Error ())
516+ }
517+ }
518+ // Run snapshot tests, if there are applicable files, using the first storage class.
519+ if len (applicableStorageClassFiles ) > 0 {
520+ testParams .storageClassFile = applicableStorageClassFiles [0 ]
512521 for _ , snapshotClassFile := range applicableSnapshotClassFiles {
513- if len (snapshotClassFile ) != 0 {
514- outputDir = fmt .Sprintf ("%s--%s" , outputDir , strings .TrimSuffix (snapshotClassFile , ".yaml" ))
515- }
516- testOutputDirs = append (testOutputDirs , outputDir )
517522 testParams .snapshotClassFile = snapshotClassFile
518- if err = runCSITests (testParams , scFile , outputDir ); err != nil {
523+ outputDir := strings .TrimSuffix (snapshotClassFile , ".yaml" )
524+ testOutputDirs = append (testOutputDirs , outputDir )
525+ if err = runCSITests (testParams , outputDir ); err != nil {
519526 ginkgoErrors = append (ginkgoErrors , err .Error ())
520527 }
521528 }
@@ -633,8 +640,8 @@ func runMigrationTests(testParams *testParameters) error {
633640 return runTestsWithConfig (testParams , "--storage.migratedPlugins=kubernetes.io/gce-pd" , "" )
634641}
635642
636- func runCSITests (testParams * testParameters , storageClassFile string , reportPrefix string ) error {
637- testDriverConfigFile , err := generateDriverConfigFile (testParams , storageClassFile )
643+ func runCSITests (testParams * testParameters , reportPrefix string ) error {
644+ testDriverConfigFile , err := generateDriverConfigFile (testParams )
638645 if err != nil {
639646 return fmt .Errorf ("failed to generated driver config: %w" , err )
640647 }
@@ -668,7 +675,20 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
668675 kubetestDumpDir = artifactsDir
669676 }
670677 }
671- ginkgoArgs := fmt .Sprintf ("--ginkgo.focus=%s --ginkgo.skip=%s" , testParams .testFocus , testParams .testSkip )
678+
679+ focus := testParams .testFocus
680+ skip := testParams .testSkip
681+ // If testParams.snapshotClassFile is empty, then snapshot tests will be automatically skipped. Otherwise confirm
682+ // the right tests are run.
683+ if testParams .snapshotClassFile != "" && strings .Contains (skip , "VolumeSnapshotDataSource" ) {
684+ return fmt .Errorf ("Snapshot class file %s specified, but snapshot tests are skipped: %s" , testParams .snapshotClassFile , skip )
685+ }
686+ if testParams .snapshotClassFile != "" {
687+ // Run exactly the snapshot tests, if there is a snapshot class file.
688+ focus = "Driver:\\ s*csi-gcepd.*Feature:VolumeSnapshotDataSource"
689+ }
690+
691+ ginkgoArgs := fmt .Sprintf ("--ginkgo.focus=%s --ginkgo.skip=%s" , focus , skip )
672692
673693 windowsArgs := ""
674694 if testParams .platform == "windows" {
@@ -728,8 +748,8 @@ func runTestsWithConfig(testParams *testParameters, testConfigArg, reportPrefix
728748 kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--test-package-marker=latest-%s.txt" , * testVersion ))
729749 }
730750 }
731- kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--focus-regex=%s" , testParams . testFocus ))
732- kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--skip-regex=%s" , testParams . testSkip ))
751+ kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--focus-regex=%s" , focus ))
752+ kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--skip-regex=%s" , skip ))
733753 kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--parallel=%d" , testParams .parallel ))
734754 kubeTest2Args = append (kubeTest2Args , fmt .Sprintf ("--test-args=%s %s" , testConfigArg , windowsArgs ))
735755
0 commit comments