From eea8d9428bfab4a086b3bd04b906bc81f3cbb806 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Mon, 22 Jan 2024 20:32:20 +0000 Subject: [PATCH 1/2] fix: delete stream with name Signed-off-by: Enrique Lacal --- pkg/eventstreams/e2e_test.go | 2 +- pkg/eventstreams/manager.go | 2 +- pkg/eventstreams/manager_test.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pkg/eventstreams/e2e_test.go b/pkg/eventstreams/e2e_test.go index b47826f..40fa0d1 100644 --- a/pkg/eventstreams/e2e_test.go +++ b/pkg/eventstreams/e2e_test.go @@ -464,7 +464,7 @@ func TestE2E_CRUDLifecycle(t *testing.T) { assert.NoError(t, err) // Delete the first stream (which is running still) - err = mgr.DeleteStream(ctx, es1.GetID()) + err = mgr.DeleteStream(ctx, *es1.Name) assert.NoError(t, err) // Check no streams left diff --git a/pkg/eventstreams/manager.go b/pkg/eventstreams/manager.go index 71dc19f..350a33c 100644 --- a/pkg/eventstreams/manager.go +++ b/pkg/eventstreams/manager.go @@ -261,7 +261,7 @@ func (esm *esManager[CT, DT]) DeleteStream(ctx context.Context, nameOrID string) return err } // Now we can delete it fully from the DB - if err := esm.persistence.EventStreams().Delete(ctx, nameOrID); err != nil { + if err := esm.persistence.EventStreams().Delete(ctx, es.spec.GetID()); err != nil { return err } esm.removeStream(es.spec.GetID()) diff --git a/pkg/eventstreams/manager_test.go b/pkg/eventstreams/manager_test.go index b0cfc47..b078b83 100644 --- a/pkg/eventstreams/manager_test.go +++ b/pkg/eventstreams/manager_test.go @@ -475,6 +475,27 @@ func TestDeleteStreamFailDelete(t *testing.T) { } +func TestDeleteStreamByName(t *testing.T) { + es := &EventStreamSpec[testESConfig]{ + ID: ptrTo(fftypes.NewUUID().String()), + Name: ptrTo("stream1"), + Status: ptrTo(EventStreamStatusStopped), + } + ctx, esm, _, done := newMockESManager(t, func(mp *mockPersistence) { + mp.eventStreams.On("GetByUUIDOrName", mock.Anything, mock.Anything).Return(es, nil).Once() + mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*EventStreamSpec[testESConfig]{es}, &ffapi.FilterResult{}, nil).Once() + mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*EventStreamSpec[testESConfig]{}, &ffapi.FilterResult{}, nil).Once() + mp.eventStreams.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() + // Expect the ID to be passed to delete + mp.eventStreams.On("Delete", mock.Anything, *es.ID).Return(nil).Once() + }) + defer done() + + err := esm.DeleteStream(ctx, *es.Name) + assert.Regexp(t, "pop", err) + +} + func TestResetStreamStopFailTimeout(t *testing.T) { existing := &eventStream[*GenericEventStream, testData]{ activeState: &activeStream[*GenericEventStream, testData]{}, From 2e24d70268edfc2bb08371b45d2cd40adc3d4b9f Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Mon, 22 Jan 2024 20:40:07 +0000 Subject: [PATCH 2/2] fix test Signed-off-by: Enrique Lacal --- pkg/eventstreams/manager_test.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/eventstreams/manager_test.go b/pkg/eventstreams/manager_test.go index b078b83..929d4a1 100644 --- a/pkg/eventstreams/manager_test.go +++ b/pkg/eventstreams/manager_test.go @@ -476,24 +476,25 @@ func TestDeleteStreamFailDelete(t *testing.T) { } func TestDeleteStreamByName(t *testing.T) { - es := &EventStreamSpec[testESConfig]{ - ID: ptrTo(fftypes.NewUUID().String()), - Name: ptrTo("stream1"), - Status: ptrTo(EventStreamStatusStopped), + es := &GenericEventStream{ + ResourceBase: dbsql.ResourceBase{ID: fftypes.NewUUID()}, + EventStreamSpecFields: EventStreamSpecFields{ + Name: ptrTo("stream1"), + Status: ptrTo(EventStreamStatusStopped), + }, } ctx, esm, _, done := newMockESManager(t, func(mp *mockPersistence) { - mp.eventStreams.On("GetByUUIDOrName", mock.Anything, mock.Anything).Return(es, nil).Once() - mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*EventStreamSpec[testESConfig]{es}, &ffapi.FilterResult{}, nil).Once() - mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*EventStreamSpec[testESConfig]{}, &ffapi.FilterResult{}, nil).Once() + mp.eventStreams.On("GetByUUIDOrName", mock.Anything, mock.Anything, dbsql.FailIfNotFound).Return(es, nil).Once() + mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*GenericEventStream{es}, &ffapi.FilterResult{}, nil).Once() + mp.eventStreams.On("GetMany", mock.Anything, mock.Anything).Return([]*GenericEventStream{}, &ffapi.FilterResult{}, nil).Once() mp.eventStreams.On("Update", mock.Anything, mock.Anything, mock.Anything).Return(nil).Once() // Expect the ID to be passed to delete - mp.eventStreams.On("Delete", mock.Anything, *es.ID).Return(nil).Once() + mp.eventStreams.On("Delete", mock.Anything, es.GetID()).Return(nil).Once() }) defer done() err := esm.DeleteStream(ctx, *es.Name) - assert.Regexp(t, "pop", err) - + assert.NoError(t, err) } func TestResetStreamStopFailTimeout(t *testing.T) {