Skip to content

Commit 806c48d

Browse files
committed
fix: waiter for rabbitmq
- Adapted tests - Update CHANGELOG.md
1 parent 7e039ab commit 806c48d

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded
1010
- `redis`: [v0.21.2](services/redis/CHANGELOG.md#v0212-2025-04-01)
1111
- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded
12+
- `rabbitmq`: [v0.21.2](services/rabbitmq/CHANGELOG.md#v0212-2025-04-01)
13+
- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded
1214

1315

1416

services/rabbitmq/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.21.2 (2025-04-01)
2+
- **Bugfix:** `PartialUpdateInstanceWaitHandler` does not finish when update is succeeded
3+
14
## v0.21.1 (2025-03-19)
25
- **Internal:** Backwards compatible change to generated code
36

services/rabbitmq/wait/wait.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import (
1313
)
1414

1515
const (
16-
InstanceStateSuccess = "succeeded"
17-
InstanceStateFailed = "failed"
18-
InstanceTypeCreate = "create"
19-
InstanceTypeUpdate = "update"
20-
InstanceTypeDelete = "delete"
16+
InstanceStatusActive = "active"
17+
InstanceStatusFailed = "failed"
18+
InstanceStatusDeleting = "deleting"
19+
InstanceStateSuccess = "succeeded"
20+
InstanceStateFailed = "failed"
21+
InstanceTypeCreate = "create"
22+
InstanceTypeUpdate = "update"
23+
InstanceTypeDelete = "delete"
2124
)
2225

2326
// Interface needed for tests
@@ -37,14 +40,18 @@ func CreateInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
3740
if err != nil {
3841
return false, nil, err
3942
}
40-
if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil {
41-
return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId)
43+
if s.InstanceId == nil || s.Status == nil {
44+
return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the instance id or the status are missing", instanceId)
4245
}
43-
if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateSuccess {
46+
if *s.InstanceId == instanceId && *s.Status == InstanceStatusActive {
4447
return true, s, nil
4548
}
46-
if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeCreate && *s.LastOperation.State == InstanceStateFailed {
47-
return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, *s.LastOperation.Description)
49+
if *s.InstanceId == instanceId && *s.Status == InstanceStatusFailed {
50+
var failedDescription string
51+
if s.LastOperation != nil && s.LastOperation.Description != nil {
52+
failedDescription = *s.LastOperation.Description
53+
}
54+
return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, failedDescription)
4855
}
4956
return false, nil, nil
5057
})
@@ -59,14 +66,18 @@ func PartialUpdateInstanceWaitHandler(ctx context.Context, a APIClientInstanceIn
5966
if err != nil {
6067
return false, nil, err
6168
}
62-
if s.InstanceId == nil || s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil {
69+
if s.InstanceId == nil || s.Status == nil {
6370
return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id, the last operation type or the state are missing", instanceId)
6471
}
65-
if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateSuccess {
72+
if *s.InstanceId == instanceId && *s.Status == InstanceStatusActive {
6673
return true, s, nil
6774
}
68-
if *s.InstanceId == instanceId && *s.LastOperation.Type == InstanceTypeUpdate && *s.LastOperation.State == InstanceStateFailed {
69-
return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, *s.LastOperation.Description)
75+
if *s.InstanceId == instanceId && *s.Status == InstanceStatusFailed {
76+
var failedDescription string
77+
if s.LastOperation != nil && s.LastOperation.Description != nil {
78+
failedDescription = *s.LastOperation.Description
79+
}
80+
return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, failedDescription)
7081
}
7182
return false, nil, nil
7283
})
@@ -79,10 +90,10 @@ func DeleteInstanceWaitHandler(ctx context.Context, a APIClientInstanceInterface
7990
handler := wait.New(func() (waitFinished bool, response *struct{}, err error) {
8091
s, err := a.GetInstanceExecute(ctx, projectId, instanceId)
8192
if err == nil {
82-
if s.LastOperation == nil || s.LastOperation.Type == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil {
83-
return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The last operation type, description or the state are missing", instanceId)
93+
if s.LastOperation == nil || s.Status == nil || s.LastOperation.State == nil || s.LastOperation.Description == nil {
94+
return false, nil, fmt.Errorf("delete failed for instance with id %s. The response is not valid: The status, last operation type, description or the state are missing", instanceId)
8495
}
85-
if *s.LastOperation.Type != InstanceTypeDelete {
96+
if *s.Status != InstanceStatusDeleting {
8697
return false, nil, nil
8798
}
8899
if *s.LastOperation.State == InstanceStateSuccess {

services/rabbitmq/wait/wait_test.go

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ type apiClientInstanceMocked struct {
2121
resourceDescription string
2222
}
2323

24-
var (
25-
instanceTypeCreate = InstanceTypeCreate
26-
instanceTypeUpdate = InstanceTypeUpdate
27-
instanceTypeDelete = InstanceTypeDelete
28-
)
29-
3024
func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ string) (*rabbitmq.Instance, error) {
3125
if a.getFails {
3226
return nil, &oapierror.GenericOpenAPIError{
@@ -37,6 +31,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str
3731
if a.deletionSucceedsWithErrors {
3832
return &rabbitmq.Instance{
3933
InstanceId: &a.resourceId,
34+
Status: &a.resourceState,
4035
LastOperation: &rabbitmq.InstanceLastOperation{
4136
Description: &a.resourceDescription,
4237
Type: a.resourceOperation,
@@ -51,11 +46,7 @@ func (a *apiClientInstanceMocked) GetInstanceExecute(_ context.Context, _, _ str
5146

5247
return &rabbitmq.Instance{
5348
InstanceId: &a.resourceId,
54-
LastOperation: &rabbitmq.InstanceLastOperation{
55-
Description: &a.resourceDescription,
56-
Type: a.resourceOperation,
57-
State: &a.resourceState,
58-
},
49+
Status: utils.Ptr(a.resourceState),
5950
}, nil
6051
}
6152

@@ -96,14 +87,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
9687
{
9788
desc: "create_succeeded",
9889
getFails: false,
99-
resourceState: InstanceStateSuccess,
90+
resourceState: InstanceStatusActive,
10091
wantErr: false,
10192
wantResp: true,
10293
},
10394
{
10495
desc: "create_failed",
10596
getFails: false,
106-
resourceState: InstanceStateFailed,
97+
resourceState: InstanceStatusFailed,
10798
wantErr: true,
10899
wantResp: true,
109100
},
@@ -128,19 +119,15 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
128119
apiClient := &apiClientInstanceMocked{
129120
getFails: tt.getFails,
130121
resourceId: instanceId,
131-
resourceOperation: &instanceTypeCreate,
122+
resourceOperation: utils.Ptr(InstanceTypeCreate),
132123
resourceState: tt.resourceState,
133124
}
134125

135126
var wantRes *rabbitmq.Instance
136127
if tt.wantResp {
137128
wantRes = &rabbitmq.Instance{
138129
InstanceId: &instanceId,
139-
LastOperation: &rabbitmq.InstanceLastOperation{
140-
Type: &instanceTypeCreate,
141-
State: utils.Ptr(tt.resourceState),
142-
Description: utils.Ptr(""),
143-
},
130+
Status: utils.Ptr(tt.resourceState),
144131
}
145132
}
146133

@@ -170,14 +157,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
170157
{
171158
desc: "update_succeeded",
172159
getFails: false,
173-
resourceState: InstanceStateSuccess,
160+
resourceState: InstanceStatusActive,
174161
wantErr: false,
175162
wantResp: true,
176163
},
177164
{
178165
desc: "update_failed",
179166
getFails: false,
180-
resourceState: InstanceStateFailed,
167+
resourceState: InstanceStatusFailed,
181168
wantErr: true,
182169
wantResp: true,
183170
},
@@ -202,19 +189,15 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
202189
apiClient := &apiClientInstanceMocked{
203190
getFails: tt.getFails,
204191
resourceId: instanceId,
205-
resourceOperation: &instanceTypeUpdate,
192+
resourceOperation: utils.Ptr(InstanceTypeUpdate),
206193
resourceState: tt.resourceState,
207194
}
208195

209196
var wantRes *rabbitmq.Instance
210197
if tt.wantResp {
211198
wantRes = &rabbitmq.Instance{
212199
InstanceId: &instanceId,
213-
LastOperation: &rabbitmq.InstanceLastOperation{
214-
Type: &instanceTypeUpdate,
215-
State: utils.Ptr(tt.resourceState),
216-
Description: utils.Ptr(""),
217-
},
200+
Status: utils.Ptr(tt.resourceState),
218201
}
219202
}
220203

@@ -278,7 +261,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) {
278261
getFails: tt.getFails,
279262
deletionSucceedsWithErrors: tt.deleteSucceeedsWithErrors,
280263
resourceId: instanceId,
281-
resourceOperation: &instanceTypeDelete,
264+
resourceOperation: utils.Ptr(InstanceTypeDelete),
282265
resourceDescription: tt.resourceDescription,
283266
resourceState: tt.resourceState,
284267
}

0 commit comments

Comments
 (0)