Skip to content

Commit 0693b75

Browse files
committed
fix(ui): create delete,compact topic
1 parent fc044d1 commit 0693b75

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

ui/pages/create_topic_page/create_topic_page.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ package create_topic_page
33
import (
44
"errors"
55
"fmt"
6-
bsp "github.com/charmbracelet/bubbles/spinner"
7-
tea "github.com/charmbracelet/bubbletea"
8-
"github.com/charmbracelet/huh"
9-
"github.com/charmbracelet/lipgloss"
106
"ktea/kadmin"
117
"ktea/kontext"
128
"ktea/styles"
@@ -18,6 +14,11 @@ import (
1814
"regexp"
1915
"strconv"
2016
"strings"
17+
18+
bsp "github.com/charmbracelet/bubbles/spinner"
19+
tea "github.com/charmbracelet/bubbletea"
20+
"github.com/charmbracelet/huh"
21+
"github.com/charmbracelet/lipgloss"
2122
)
2223

2324
type formState int
@@ -209,9 +210,9 @@ func (m *Model) initForm(fs formState) {
209210
Title("Cleanup Policy").
210211
Value(&m.formValues.cleanupPolicy).
211212
Options(
212-
huh.NewOption("Retention (delete)", "delete"),
213-
huh.NewOption("Compaction (compact)", "compact"),
214-
huh.NewOption("Retention + Compaction", "delete-compact"))
213+
huh.NewOption("delete", "delete"),
214+
huh.NewOption("compact", "compact"),
215+
huh.NewOption("delete,compact", "delete,compact"))
215216

216217
configInput := huh.NewInput().
217218
Description("Enter custom topic configurations in the format config=value. Leave blank to create the topic.").

ui/pages/create_topic_page/create_topic_page_test.go

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package create_topic_page
33
import (
44
"errors"
55
"fmt"
6-
tea "github.com/charmbracelet/bubbletea"
7-
"github.com/stretchr/testify/assert"
86
"ktea/kadmin"
97
"ktea/kontext"
108
"ktea/tests"
119
"ktea/ui/pages/nav"
1210
"testing"
11+
12+
tea "github.com/charmbracelet/bubbletea"
13+
"github.com/stretchr/testify/assert"
1314
)
1415

1516
func batchUpdate(m *Model, cmd tea.Cmd) {
@@ -170,6 +171,66 @@ func TestCreateTopic(t *testing.T) {
170171
}
171172
m := New(&mockCreator)
172173

174+
// topic name
175+
tests.UpdateKeys(m, "topicA")
176+
cmd := m.Update(tests.Key(tea.KeyEnter))
177+
m.Update(cmd())
178+
// partition count
179+
tests.UpdateKeys(m, "2")
180+
cmd = m.Update(tests.Key(tea.KeyEnter))
181+
m.Update(cmd())
182+
// replication factor
183+
tests.UpdateKeys(m, "3")
184+
cmd = m.Update(tests.Key(tea.KeyEnter))
185+
m.Update(cmd())
186+
// cleanup policy
187+
m.Update(tests.Key(tea.KeyDown))
188+
cmd = m.Update(tests.Key(tea.KeyEnter))
189+
m.Update(cmd())
190+
// config
191+
tests.UpdateKeys(m, "delete.retention.ms=1029394")
192+
cmd = m.Update(tests.Key(tea.KeyEnter))
193+
// next field
194+
cmd = m.Update(cmd())
195+
// next group
196+
m.Update(cmd())
197+
198+
// actual submit
199+
msgs := tests.Submit(m)
200+
201+
var capturedDetails CapturedTopicCreationDetails
202+
for _, msg := range msgs {
203+
switch m := msg.(type) {
204+
case CapturedTopicCreationDetails:
205+
capturedDetails = m
206+
}
207+
}
208+
209+
assert.NotNil(t, capturedDetails)
210+
assert.Equal(t, CapturedTopicCreationDetails{
211+
TopicCreationDetails: kadmin.TopicCreationDetails{
212+
"topicA",
213+
2,
214+
map[string]string{
215+
"cleanup.policy": "compact",
216+
"delete.retention.ms": "1029394",
217+
},
218+
int16(3),
219+
},
220+
}, capturedDetails)
221+
})
222+
223+
t.Run("create delete,compact topic", func(t *testing.T) {
224+
mockCreator := MockTopicCreator{
225+
CreateTopicFunc: func(details kadmin.TopicCreationDetails) tea.Msg {
226+
if details.Name == "" {
227+
return errors.New("topic name cannot be empty")
228+
}
229+
return CapturedTopicCreationDetails{details}
230+
},
231+
}
232+
m := New(&mockCreator)
233+
173234
// topic name
174235
tests.UpdateKeys(m, "topicA")
175236
cmd := m.Update(tests.Key(tea.KeyEnter))
@@ -212,13 +273,14 @@ func TestCreateTopic(t *testing.T) {
212273
"topicA",
213274
2,
214275
map[string]string{
215-
"cleanup.policy": "delete-compact",
276+
"cleanup.policy": "delete,compact",
216277
"delete.retention.ms": "1029394",
217278
},
218279
int16(3),
219280
},
220281
}, capturedDetails)
221282
})
283+
222284
}
223285

224286
func TestCreateTopic_Validation(t *testing.T) {

0 commit comments

Comments
 (0)