Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new error for MockDeleteTopicsResponse #2475

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,35 @@ func TestClusterAdminDeleteEmptyTopic(t *testing.T) {
}
}

func TestClusterAdminDeleteTopicError(t *testing.T) {
seedBroker := NewMockBroker(t, 1)
defer seedBroker.Close()

seedBroker.SetHandlerByMap(map[string]MockResponse{
"MetadataRequest": NewMockMetadataResponse(t).
SetController(seedBroker.BrokerID()).
SetBroker(seedBroker.Addr(), seedBroker.BrokerID()),
"DeleteTopicsRequest": NewMockDeleteTopicsResponse(t).SetError(ErrTopicDeletionDisabled),
})

config := NewTestConfig()
config.Version = V0_10_2_0
admin, err := NewClusterAdmin([]string{seedBroker.Addr()}, config)
if err != nil {
t.Fatal(err)
}

err = admin.DeleteTopic("my_topic")
if !errors.Is(err, ErrTopicDeletionDisabled) {
t.Fatal(err)
}

err = admin.Close()
if err != nil {
t.Fatal(err)
}
}

func TestClusterAdminCreatePartitions(t *testing.T) {
seedBroker := NewMockBroker(t, 1)
defer seedBroker.Close()
Expand Down
10 changes: 8 additions & 2 deletions mockresponses.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ func (mr *MockCreateTopicsResponse) For(reqBody versionedDecoder) encoderWithHea
}

type MockDeleteTopicsResponse struct {
t TestReporter
t TestReporter
error KError
}

func NewMockDeleteTopicsResponse(t TestReporter) *MockDeleteTopicsResponse {
Expand All @@ -681,12 +682,17 @@ func (mr *MockDeleteTopicsResponse) For(reqBody versionedDecoder) encoderWithHea
res.TopicErrorCodes = make(map[string]KError)

for _, topic := range req.Topics {
res.TopicErrorCodes[topic] = ErrNoError
res.TopicErrorCodes[topic] = mr.error
}
res.Version = req.Version
return res
}

func (mr *MockDeleteTopicsResponse) SetError(kerror KError) *MockDeleteTopicsResponse {
mr.error = kerror
return mr
}

type MockCreatePartitionsResponse struct {
t TestReporter
}
Expand Down
Loading