diff --git a/pkg/internal/checkup/checkup.go b/pkg/internal/checkup/checkup.go index 66135a29..c792db28 100644 --- a/pkg/internal/checkup/checkup.go +++ b/pkg/internal/checkup/checkup.go @@ -1047,7 +1047,8 @@ func uniqueVMName() string { type checkVMIStatusFn func(*kvcorev1.VirtualMachineInstance) (done bool, err error) -func (c *Checkup) waitForVMIStatus(ctx context.Context, vmName, checkMsg string, result, errStr *string, checkVMIStatus checkVMIStatusFn) error { +func (c *Checkup) waitForVMIStatus(ctx context.Context, vmName, checkMsg string, result, errStr *string, + checkVMIStatus checkVMIStatusFn) error { conditionFn := func(ctx context.Context) (bool, error) { vmi, err := c.client.GetVirtualMachineInstance(ctx, c.namespace, vmName) if err != nil { diff --git a/pkg/internal/checkup/checkup_test.go b/pkg/internal/checkup/checkup_test.go index da7ab4e8..7d54af0d 100644 --- a/pkg/internal/checkup/checkup_test.go +++ b/pkg/internal/checkup/checkup_test.go @@ -83,82 +83,82 @@ func TestCheckupShouldSucceed(t *testing.T) { assert.Equal(t, expectedResults, actualResults) } -func TestCheckupShouldReturnErrorWhen(t *testing.T) { - tests := map[string]struct { - clientConfig clientConfig - expectedResults map[string]string - expectedErr string - }{ - "noStorageClasses": { - clientConfig: clientConfig{noStorageClasses: true}, - expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrNoDefaultStorageClass}, - expectedErr: checkup.ErrNoDefaultStorageClass, - }, - "noDefaultStorageClass": { - clientConfig: clientConfig{noDefaultStorageClass: true}, - expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrNoDefaultStorageClass}, - expectedErr: checkup.ErrNoDefaultStorageClass, - }, - "multipleDefaultStorageClasses": { - clientConfig: clientConfig{multipleDefaultStorageClasses: true}, - expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrMultipleDefaultStorageClasses}, - expectedErr: checkup.ErrMultipleDefaultStorageClasses, - }, - "failPvcBound": { - clientConfig: clientConfig{failPvcBound: true}, - expectedResults: map[string]string{reporter.PVCBoundKey: checkup.ErrPvcNotBound}, - expectedErr: checkup.ErrPvcNotBound, - }, - "storageProfileIncomplete": { - clientConfig: clientConfig{spIncomplete: true}, - expectedResults: map[string]string{reporter.StorageProfilesWithEmptyClaimPropertySetsKey: testScName, - reporter.StorageProfilesWithSpecClaimPropertySetsKey: testScName, reporter.StorageProfilesWithRWXKey: ""}, - expectedErr: checkup.ErrEmptyClaimPropertySets, - }, - "noVolumeSnapshotClasses": { - clientConfig: clientConfig{noVolumeSnapshotClasses: true}, - expectedResults: map[string]string{reporter.StorageProfileMissingVolumeSnapshotClassKey: testScName, - reporter.StorageProfilesWithSmartCloneKey: ""}, - expectedErr: "", - }, - "dataSourceNotReady": { - clientConfig: clientConfig{dataSourceNotReady: true, expectNoVMI: true}, - expectedResults: map[string]string{reporter.GoldenImagesNotUpToDateKey: testNamespace + "/" + testDIC, - reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage, - reporter.ConcurrentVMBootKey: checkup.MessageSkipNoGoldenImage, - }, - expectedErr: checkup.ErrGoldenImagesNotUpToDate, +var tests = map[string]struct { + clientConfig clientConfig + expectedResults map[string]string + expectedErr string +}{ + "noStorageClasses": { + clientConfig: clientConfig{noStorageClasses: true}, + expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrNoDefaultStorageClass}, + expectedErr: checkup.ErrNoDefaultStorageClass, + }, + "noDefaultStorageClass": { + clientConfig: clientConfig{noDefaultStorageClass: true}, + expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrNoDefaultStorageClass}, + expectedErr: checkup.ErrNoDefaultStorageClass, + }, + "multipleDefaultStorageClasses": { + clientConfig: clientConfig{multipleDefaultStorageClasses: true}, + expectedResults: map[string]string{reporter.DefaultStorageClassKey: checkup.ErrMultipleDefaultStorageClasses}, + expectedErr: checkup.ErrMultipleDefaultStorageClasses, + }, + "failPvcBound": { + clientConfig: clientConfig{failPvcBound: true}, + expectedResults: map[string]string{reporter.PVCBoundKey: checkup.ErrPvcNotBound}, + expectedErr: checkup.ErrPvcNotBound, + }, + "storageProfileIncomplete": { + clientConfig: clientConfig{spIncomplete: true}, + expectedResults: map[string]string{reporter.StorageProfilesWithEmptyClaimPropertySetsKey: testScName, + reporter.StorageProfilesWithSpecClaimPropertySetsKey: testScName, reporter.StorageProfilesWithRWXKey: ""}, + expectedErr: checkup.ErrEmptyClaimPropertySets, + }, + "noVolumeSnapshotClasses": { + clientConfig: clientConfig{noVolumeSnapshotClasses: true}, + expectedResults: map[string]string{reporter.StorageProfileMissingVolumeSnapshotClassKey: testScName, + reporter.StorageProfilesWithSmartCloneKey: ""}, + expectedErr: "", + }, + "dataSourceNotReady": { + clientConfig: clientConfig{dataSourceNotReady: true, expectNoVMI: true}, + expectedResults: map[string]string{reporter.GoldenImagesNotUpToDateKey: testNamespace + "/" + testDIC, + reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage, + reporter.ConcurrentVMBootKey: checkup.MessageSkipNoGoldenImage, }, - "dicNoDataSource": { - clientConfig: clientConfig{dicNoDataSource: true, expectNoVMI: true}, - expectedResults: map[string]string{reporter.GoldenImagesNoDataSourceKey: testNamespace + "/" + testDIC, - reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage, - reporter.ConcurrentVMBootKey: checkup.MessageSkipNoGoldenImage, - }, - expectedErr: checkup.ErrGoldenImageNoDataSource, - }, - "vmisWithUnsetEfsSC": { - clientConfig: clientConfig{unsetEfsStorageClass: true}, - expectedResults: map[string]string{reporter.VMsWithUnsetEfsStorageClassKey: testNamespace + "/" + testVMIName}, - expectedErr: checkup.ErrVMsWithUnsetEfsStorageClass, - }, - "dvCloneFallback": { - clientConfig: clientConfig{cloneFallback: true}, - expectedResults: map[string]string{reporter.VMVolumeCloneKey: "DV cloneType: \"host-assisted\"\nDV clone fallback reason: reason"}, - expectedErr: "DV clone fallback reason: reason", - }, - "migrationFails": { - clientConfig: clientConfig{failMigration: true}, - expectedResults: map[string]string{reporter.VMLiveMigrationKey: "failed waiting for VMI \"%s\" migration completed: migration failed"}, - expectedErr: "migration failed", + expectedErr: checkup.ErrGoldenImagesNotUpToDate, + }, + "dicNoDataSource": { + clientConfig: clientConfig{dicNoDataSource: true, expectNoVMI: true}, + expectedResults: map[string]string{reporter.GoldenImagesNoDataSourceKey: testNamespace + "/" + testDIC, + reporter.VMBootFromGoldenImageKey: checkup.MessageSkipNoGoldenImage, + reporter.ConcurrentVMBootKey: checkup.MessageSkipNoGoldenImage, }, - "skipMigrationOnSingleNode": { - clientConfig: clientConfig{singleNode: true}, - expectedResults: map[string]string{reporter.VMLiveMigrationKey: "Skip check - single node"}, - expectedErr: "", - }, - } + expectedErr: checkup.ErrGoldenImageNoDataSource, + }, + "vmisWithUnsetEfsSC": { + clientConfig: clientConfig{unsetEfsStorageClass: true}, + expectedResults: map[string]string{reporter.VMsWithUnsetEfsStorageClassKey: testNamespace + "/" + testVMIName}, + expectedErr: checkup.ErrVMsWithUnsetEfsStorageClass, + }, + "dvCloneFallback": { + clientConfig: clientConfig{cloneFallback: true}, + expectedResults: map[string]string{reporter.VMVolumeCloneKey: "DV cloneType: \"host-assisted\"\nDV clone fallback reason: reason"}, + expectedErr: "DV clone fallback reason: reason", + }, + "migrationFails": { + clientConfig: clientConfig{failMigration: true}, + expectedResults: map[string]string{reporter.VMLiveMigrationKey: "failed waiting for VMI \"%s\" migration completed: migration failed"}, + expectedErr: "migration failed", + }, + "skipMigrationOnSingleNode": { + clientConfig: clientConfig{singleNode: true}, + expectedResults: map[string]string{reporter.VMLiveMigrationKey: "Skip check - single node"}, + expectedErr: "", + }, +} +func TestCheckupShouldReturnErrorWhen(t *testing.T) { for name, tc := range tests { t.Run(name, func(t *testing.T) { testClient := newClientStub(tc.clientConfig) diff --git a/pkg/internal/reporter/reporter_test.go b/pkg/internal/reporter/reporter_test.go index e1c0c7b2..dd9968f4 100644 --- a/pkg/internal/reporter/reporter_test.go +++ b/pkg/internal/reporter/reporter_test.go @@ -41,6 +41,8 @@ import ( const ( testNamespace = "target-ns" testConfigMapName = "storage-checkup-config" + failureReason1 = "some reason" + failureReason2 = "some other reason" ) func TestReportShouldSucceed(t *testing.T) { @@ -51,11 +53,6 @@ func TestReportShouldSucceed(t *testing.T) { } func TestReportShouldSuccessfullyReportResults(t *testing.T) { - const ( - failureReason1 = "some reason" - failureReason2 = "some other reason" - ) - t.Run("on checkup success", func(t *testing.T) { fakeClient := fake.NewSimpleClientset(newConfigMap()) testReporter := reporter.New(fakeClient, testNamespace, testConfigMapName)