From 9fff21d209ed42c631132ae02f30b1f702abe63a Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Mon, 22 Jan 2024 20:32:20 +0000 Subject: [PATCH] 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 31aa145..0551f0c 100644 --- a/pkg/eventstreams/e2e_test.go +++ b/pkg/eventstreams/e2e_test.go @@ -471,7 +471,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 bf114d4..1fd5353 100644 --- a/pkg/eventstreams/manager.go +++ b/pkg/eventstreams/manager.go @@ -260,7 +260,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.ID) diff --git a/pkg/eventstreams/manager_test.go b/pkg/eventstreams/manager_test.go index 162e167..b1484fb 100644 --- a/pkg/eventstreams/manager_test.go +++ b/pkg/eventstreams/manager_test.go @@ -460,6 +460,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[testESConfig, testData]{ activeState: &activeStream[testESConfig, testData]{},