Skip to content

Commit eab13b6

Browse files
author
t-feadeaga
committed
pr resolution
1 parent fd81d3b commit eab13b6

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

internal/actionplan/executehelper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func (actionPlan *ActionPlan) executeHelper(registryHandler packageregistry.IPac
4343
// return early for Cleanup operation
4444
if vmAppPackageCurrent.OngoingOperation == packageregistry.Cleanup {
4545
delete(registry, appName)
46-
return ewc, registryHandler.WriteToDisk(registry)
46+
err := registryHandler.WriteToDisk(registry)
47+
ewc = vmextensionhelper.NewErrorWithClarification(utils.WriteToDiskError, err)
48+
return ewc, err
4749
}
4850
err := registryHandler.WriteToDisk(registry)
4951
if err != nil {

main/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ func customEnable(ext *vmextensionhelper.VMExtension, hostgaCommunicator hostgac
238238
switch statusResult {
239239
case status.StatusError:
240240
ewc := executeError.GetErrorWithClarification()
241-
supportEwc := false
242241
if ewc != (vmextensionhelper.ErrorWithClarification{}) {
243-
supportEwc = true
244-
}
245-
if supportEwc {
246242
err = utils.ReportStatusWithError(ext.HandlerEnv, requestedSequenceNumber, vmextensionhelper.EnableOperation.ToStatusName(), ewc)
247243
} else {
248244
err = utils.ReportStatus(ext.HandlerEnv, requestedSequenceNumber, statusResult, vmextensionhelper.EnableOperation.ToStatusName(), statusMessage)

main/main_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func Test_customEnable_ErrorWithClarification_ComparisonLogic(t *testing.T) {
643643
}{
644644
{
645645
name: "Empty error clarification",
646-
errorCode: 0,
646+
errorCode: utils.NoError,
647647
errorMessage: "",
648648
expectedSupportEwc: false,
649649
},
@@ -723,16 +723,16 @@ func Test_customEnable_StatusErrorPath_WithClarification(t *testing.T) {
723723
}
724724

725725
// Should be false for empty clarification
726-
assert.False(t, supportEwc, "supportEwc should be false when no error clarification is set")
726+
assert.False(t, supportEwc, "testapp: supportEwc should be false when no error clarification is set")
727727

728728
// Test with ReportStatus for empty clarification
729729
err := utils.ReportStatus(ext.HandlerEnv, requestedSequenceNumber, status.StatusError, vmextensionhelper.EnableOperation.ToStatusName(), statusMessage)
730-
assert.NoError(t, err)
730+
assert.NoError(t, err, "testapp: ReportStatus should not return an error for empty clarification")
731731

732732
// Verify status was written
733733
statusType, err := utils.GetStatusType(ext.HandlerEnv, requestedSequenceNumber)
734-
require.NoError(t, err)
735-
assert.Equal(t, status.StatusError, statusType)
734+
require.NoError(t, err, "testapp: GetStatusType should not return an error")
735+
assert.Equal(t, status.StatusError, statusType, "testapp: status should be error")
736736
}
737737

738738
func Test_customEnable_StatusErrorPath_WithoutClarification(t *testing.T) {
@@ -757,22 +757,16 @@ func Test_customEnable_StatusErrorPath_WithoutClarification(t *testing.T) {
757757

758758
ewc := vmextensionhelper.NewErrorWithClarification(errorCode, testError)
759759

760-
supportEwc := false
761-
if ewc != (vmextensionhelper.ErrorWithClarification{}) {
762-
supportEwc = true
763-
}
764-
765-
// Should be true for populated clarification
766-
assert.True(t, supportEwc, "supportEwc should be true when error clarification is set")
760+
assert.True(t, (ewc != (vmextensionhelper.ErrorWithClarification{})), "testapp2: error clarification should not be empty")
767761

768762
// Test with ReportStatusWithError for populated clarification
769763
err := utils.ReportStatusWithError(ext.HandlerEnv, requestedSequenceNumber, vmextensionhelper.EnableOperation.ToStatusName(), ewc)
770764
assert.NoError(t, err)
771765

772766
// Verify status was written
773767
statusType, err := utils.GetStatusType(ext.HandlerEnv, requestedSequenceNumber)
774-
require.NoError(t, err)
775-
assert.Equal(t, status.StatusError, statusType)
768+
require.NoError(t, err, "testapp2: GetStatusType should not return an error")
769+
assert.Equal(t, status.StatusError, statusType, "testapp2: status should be error")
776770
}
777771

778772
func Test_customEnable_StatusSuccess_NoErrorHandling(t *testing.T) {
@@ -796,11 +790,11 @@ func Test_customEnable_StatusSuccess_NoErrorHandling(t *testing.T) {
796790
if executeError.GetErrorIfDeploymentFailed() == nil {
797791
// For success, we go to the default case in the switch statement
798792
err := utils.ReportStatus(ext.HandlerEnv, requestedSequenceNumber, status.StatusSuccess, vmextensionhelper.EnableOperation.ToStatusName(), statusMessage)
799-
assert.NoError(t, err)
793+
assert.NoError(t, err, "ReportStatus should not return an error for successapp")
800794

801795
// Verify status was written as success
802796
statusType, err := utils.GetStatusType(ext.HandlerEnv, requestedSequenceNumber)
803-
require.NoError(t, err)
797+
require.NoError(t, err, "Successapp: GetStatusType should not return an error")
804798
assert.Equal(t, status.StatusSuccess, statusType)
805799
}
806800
}

pkg/utils/errroclarification.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package utils
22

3-
var WriteToDiskError = -1
4-
var UnexpectedActionError = -2
5-
var FailedToCreateDirectoryError = -3
6-
var FailedToDownloadPackageError = -4
7-
var FailedToDownloadConfigError = -5
8-
var DeleteOperationError = -6
3+
const (
4+
WriteToDiskError = -1
5+
UnexpectedActionError = -2
6+
FailedToCreateDirectoryError = -3
7+
FailedToDownloadPackageError = -4
8+
FailedToDownloadConfigError = -5
9+
DeleteOperationError = -6
10+
CommandExecutionError = 1
11+
DeletedAppVersionError = 2
12+
NonZeroExitCodeError = 3
913

10-
var CommandExecutionError = 1
11-
var DeletedAppVersionError = 2
12-
var NonZeroExitCodeError = 3
14+
NoError = 0
15+
)

0 commit comments

Comments
 (0)