Skip to content

Commit

Permalink
Fix lint noise
Browse files Browse the repository at this point in the history
Signed-off-by: Arnon Gilboa <[email protected]>
  • Loading branch information
arnongilboa committed Aug 5, 2024
1 parent 596379f commit 216489b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 79 deletions.
3 changes: 2 additions & 1 deletion pkg/internal/checkup/checkup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
146 changes: 73 additions & 73 deletions pkg/internal/checkup/checkup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions pkg/internal/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 216489b

Please sign in to comment.