Skip to content
Open
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
26 changes: 15 additions & 11 deletions pulsaradmin/pkg/admin/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func ptr(n int) *int {
return &n
}

func boolPtr(b bool) *bool {
return &b
}

func TestSetTopicAutoCreation(t *testing.T) {
config := &config.Config{}
admin, err := New(config)
Expand All @@ -47,7 +51,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set partitioned type topic auto creation",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.Partitioned,
Partitions: ptr(3),
},
Expand All @@ -57,7 +61,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set partitioned type topic auto creation without partitions",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.Partitioned,
},
errReason: "Invalid configuration for autoTopicCreationOverride. the detail is [defaultNumPartitions] " +
Expand All @@ -67,7 +71,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set partitioned type topic auto creation with partitions < 1",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.Partitioned,
Partitions: ptr(-1),
},
Expand All @@ -78,7 +82,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set non-partitioned type topic auto creation",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
},
errReason: "",
Expand All @@ -87,7 +91,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set non-partitioned type topic auto creation with partitions",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
Partitions: ptr(3),
},
Expand All @@ -98,15 +102,15 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Disable topic auto creation",
namespace: "public/default",
config: utils.TopicAutoCreationConfig{
Allow: false,
Allow: boolPtr(false),
},
errReason: "",
},
{
name: "Set topic auto creation on a non-exist namespace",
namespace: "public/nonexist",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
},
errReason: "Namespace does not exist",
Expand All @@ -115,7 +119,7 @@ func TestSetTopicAutoCreation(t *testing.T) {
name: "Set topic auto creation on a non-exist tenant",
namespace: "non-exist/default",
config: utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
},
errReason: "Tenant does not exist",
Expand Down Expand Up @@ -149,14 +153,14 @@ func TestGetTopicAutoCreation(t *testing.T) {

// set the topic auto creation config and get it
err = admin.Namespaces().SetTopicAutoCreation(*namespace, utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
})
assert.Equal(t, nil, err)
topicAutoCreation, err := admin.Namespaces().GetTopicAutoCreation(*namespace)
assert.Equal(t, nil, err)
expected := utils.TopicAutoCreationConfig{
Allow: true,
Allow: boolPtr(true),
Type: utils.NonPartitioned,
}
assert.Equal(t, expected, *topicAutoCreation)
Expand All @@ -168,7 +172,7 @@ func TestGetTopicAutoCreation(t *testing.T) {
topicAutoCreation, err = admin.Namespaces().GetTopicAutoCreation(*namespace)
assert.Equal(t, nil, err)
expected = utils.TopicAutoCreationConfig{
Allow: false,
Allow: nil,
Type: "",
}
assert.Equal(t, expected, *topicAutoCreation)
Expand Down
4 changes: 2 additions & 2 deletions pulsaradmin/pkg/utils/topic_auto_creation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package utils

type TopicAutoCreationConfig struct {
Allow bool `json:"allowAutoTopicCreation"`
Allow *bool `json:"allowAutoTopicCreation,omitempty"`
Type TopicType `json:"topicType"`
Partitions *int `json:"defaultNumPartitions"`
Partitions *int `json:"defaultNumPartitions,omitempty"`
}