Skip to content

Commit ba6bfbc

Browse files
feat: replace WorkspaceID with WorkspaceIDs in AdvisoryUpdateEvent
Updated AdvisoryUpdateEvent structure to support multiple workspace IDs
1 parent 743010c commit ba6bfbc

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

base/mqueue/advisory_update_event.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import (
55
"context"
66

77
"github.com/bytedance/sonic"
8-
"github.com/google/uuid"
98
"github.com/pkg/errors"
109
)
1110

1211
type AdvisoryUpdateEvent struct {
13-
RhAccountID int `json:"rh_account_id"`
14-
WorkspaceID uuid.UUID `json:"workspace_id"`
15-
AdvisoryIDs []int64 `json:"advisory_ids"`
16-
ProducedAt types.Rfc3339Timestamp `json:"produced_at"`
12+
RhAccountID int `json:"rh_account_id"`
13+
WorkspaceIDs []string `json:"workspace_ids"`
14+
AdvisoryIDs []int64 `json:"advisory_ids"`
15+
ProducedAt types.Rfc3339Timestamp `json:"produced_at"`
1716
}
1817

1918
type AdvisoryUpdateEvents []AdvisoryUpdateEvent

base/mqueue/advisory_update_event_test.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ import (
77
"time"
88

99
"github.com/bytedance/sonic"
10-
"github.com/google/uuid"
1110
"github.com/stretchr/testify/assert"
1211
)
1312

1413
var (
15-
testWorkspaceID = uuid.New()
16-
testNow = types.Rfc3339Timestamp(time.Now())
14+
testWorkspaceIDs = []string{"00000000-0000-0000-0000-000000000001", "00000000-0000-0000-0000-000000000002"}
15+
testNow = types.Rfc3339Timestamp(time.Now())
1716
)
1817

1918
func TestAdvisoryUpdateEventMarshal(t *testing.T) {
2019
event := AdvisoryUpdateEvent{
21-
RhAccountID: 1,
22-
WorkspaceID: testWorkspaceID,
23-
AdvisoryIDs: []int64{101, 202, 303},
24-
ProducedAt: testNow,
20+
RhAccountID: 1,
21+
WorkspaceIDs: testWorkspaceIDs,
22+
AdvisoryIDs: []int64{101, 202, 303},
23+
ProducedAt: testNow,
2524
}
2625

2726
data, err := sonic.Marshal(&event)
@@ -31,7 +30,7 @@ func TestAdvisoryUpdateEventMarshal(t *testing.T) {
3130
err = sonic.Unmarshal(data, &parsed)
3231
assert.NoError(t, err)
3332
assert.Equal(t, event.RhAccountID, parsed.RhAccountID)
34-
assert.Equal(t, event.WorkspaceID, parsed.WorkspaceID)
33+
assert.Equal(t, event.WorkspaceIDs, parsed.WorkspaceIDs)
3534
assert.Equal(t, event.AdvisoryIDs, parsed.AdvisoryIDs)
3635
assert.NotNil(t, parsed.ProducedAt)
3736
}
@@ -41,16 +40,16 @@ func TestAdvisoryUpdateEventsWriteEvents(t *testing.T) {
4140

4241
events := AdvisoryUpdateEvents{
4342
{
44-
RhAccountID: 1,
45-
WorkspaceID: testWorkspaceID,
46-
AdvisoryIDs: []int64{100, 200},
47-
ProducedAt: testNow,
43+
RhAccountID: 1,
44+
WorkspaceIDs: testWorkspaceIDs,
45+
AdvisoryIDs: []int64{100, 200},
46+
ProducedAt: testNow,
4847
},
4948
{
50-
RhAccountID: 2,
51-
WorkspaceID: testWorkspaceID,
52-
AdvisoryIDs: []int64{300},
53-
ProducedAt: testNow,
49+
RhAccountID: 2,
50+
WorkspaceIDs: testWorkspaceIDs,
51+
AdvisoryIDs: []int64{300},
52+
ProducedAt: testNow,
5453
},
5554
}
5655

@@ -64,15 +63,15 @@ func TestAdvisoryUpdateEventsWriteEvents(t *testing.T) {
6463
err = sonic.Unmarshal(mockWriter.Messages[0].Value, &firstEvent)
6564
assert.NoError(t, err)
6665
assert.Equal(t, events[0].RhAccountID, firstEvent.RhAccountID)
67-
assert.Equal(t, events[0].WorkspaceID, firstEvent.WorkspaceID)
66+
assert.Equal(t, events[0].WorkspaceIDs, firstEvent.WorkspaceIDs)
6867
assert.Equal(t, events[0].AdvisoryIDs, firstEvent.AdvisoryIDs)
6968
assert.NotNil(t, firstEvent.ProducedAt)
7069

7170
var secondEvent AdvisoryUpdateEvent
7271
err = sonic.Unmarshal(mockWriter.Messages[1].Value, &secondEvent)
7372
assert.NoError(t, err)
7473
assert.Equal(t, events[1].RhAccountID, secondEvent.RhAccountID)
75-
assert.Equal(t, events[1].WorkspaceID, secondEvent.WorkspaceID)
74+
assert.Equal(t, events[1].WorkspaceIDs, secondEvent.WorkspaceIDs)
7675
assert.Equal(t, events[1].AdvisoryIDs, secondEvent.AdvisoryIDs)
7776
assert.NotNil(t, secondEvent.ProducedAt)
7877
}

0 commit comments

Comments
 (0)