Skip to content

Commit aaba115

Browse files
committed
fix rollback
1 parent 6ec3ef5 commit aaba115

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

apptrust/commands/version/rollback_app_version_cmd_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ func TestRollbackAppVersionCommand_Run(t *testing.T) {
3939
assert.NoError(t, err)
4040
}
4141

42+
func TestRollbackAppVersionCommand_Run_WithSync(t *testing.T) {
43+
ctrl := gomock.NewController(t)
44+
defer ctrl.Finish()
45+
46+
applicationKey := "test-app"
47+
version := "1.0.0"
48+
serverDetails := &config.ServerDetails{Url: "https://example.com"}
49+
requestPayload := &model.RollbackAppVersionRequest{
50+
FromStage: "qa",
51+
}
52+
53+
mockVersionService := mockversions.NewMockVersionService(ctrl)
54+
mockVersionService.EXPECT().RollbackAppVersion(gomock.Any(), applicationKey, version, requestPayload, true).
55+
Return(nil).Times(1)
56+
57+
cmd := &rollbackAppVersionCommand{
58+
versionService: mockVersionService,
59+
serverDetails: serverDetails,
60+
applicationKey: applicationKey,
61+
version: version,
62+
requestPayload: requestPayload,
63+
fromStage: "qa",
64+
sync: true,
65+
}
66+
67+
err := cmd.Run()
68+
assert.NoError(t, err)
69+
}
70+
4271
func TestRollbackAppVersionCommand_Run_Error(t *testing.T) {
4372
ctrl := gomock.NewController(t)
4473
defer ctrl.Finish()

apptrust/service/versions/version_service.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ func (vs *versionService) RollbackAppVersion(ctx service.Context, applicationKey
8383
return err
8484
}
8585

86-
if response.StatusCode >= http.StatusBadRequest {
86+
// Validate status code based on sync mode
87+
expectedStatusCode := http.StatusAccepted // async mode expects 202
88+
if sync {
89+
expectedStatusCode = http.StatusOK // sync mode expects 200
90+
}
91+
92+
if response.StatusCode != expectedStatusCode {
8793
return fmt.Errorf("failed to rollback app version. Status code: %d. \n%s",
8894
response.StatusCode, responseBody)
8995
}

apptrust/service/versions/version_service_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,28 @@ func TestRollbackAppVersion(t *testing.T) {
459459
expectedStatus: http.StatusBadRequest,
460460
expectedError: true,
461461
},
462+
{
463+
name: "failed rollback - sync=true but got 202",
464+
applicationKey: "video-encoder",
465+
version: "1.5.0",
466+
payload: &model.RollbackAppVersionRequest{
467+
FromStage: "qa",
468+
},
469+
sync: true,
470+
expectedStatus: http.StatusAccepted, // Wrong status for sync=true
471+
expectedError: true,
472+
},
473+
{
474+
name: "failed rollback - sync=false but got 200",
475+
applicationKey: "video-encoder",
476+
version: "1.5.0",
477+
payload: &model.RollbackAppVersionRequest{
478+
FromStage: "prod",
479+
},
480+
sync: false,
481+
expectedStatus: http.StatusOK, // Wrong status for sync=false
482+
expectedError: true,
483+
},
462484
}
463485

464486
for _, tt := range tests {

0 commit comments

Comments
 (0)