diff --git a/pulsaradmin/pkg/admin/namespace_test.go b/pulsaradmin/pkg/admin/namespace_test.go index f934a96865..715102a9c5 100644 --- a/pulsaradmin/pkg/admin/namespace_test.go +++ b/pulsaradmin/pkg/admin/namespace_test.go @@ -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) @@ -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), }, @@ -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] " + @@ -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), }, @@ -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: "", @@ -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), }, @@ -98,7 +102,7 @@ func TestSetTopicAutoCreation(t *testing.T) { name: "Disable topic auto creation", namespace: "public/default", config: utils.TopicAutoCreationConfig{ - Allow: false, + Allow: boolPtr(false), }, errReason: "", }, @@ -106,7 +110,7 @@ func TestSetTopicAutoCreation(t *testing.T) { 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", @@ -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", @@ -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) @@ -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: boolPtr(false), Type: "", } assert.Equal(t, expected, *topicAutoCreation) diff --git a/pulsaradmin/pkg/utils/topic_auto_creation_config.go b/pulsaradmin/pkg/utils/topic_auto_creation_config.go index 8444514250..9b8dfd7165 100644 --- a/pulsaradmin/pkg/utils/topic_auto_creation_config.go +++ b/pulsaradmin/pkg/utils/topic_auto_creation_config.go @@ -18,7 +18,7 @@ package utils type TopicAutoCreationConfig struct { - Allow bool `json:"allowAutoTopicCreation"` + Allow *bool `json:"allowAutoTopicCreation"` Type TopicType `json:"topicType"` Partitions *int `json:"defaultNumPartitions"` }