|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package namespace |
| 19 | + |
| 20 | +import ( |
| 21 | + "encoding/json" |
| 22 | + "fmt" |
| 23 | + "testing" |
| 24 | + |
| 25 | + "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils" |
| 26 | + "github.com/onsi/gomega" |
| 27 | + |
| 28 | + "github.com/streamnative/pulsarctl/pkg/test" |
| 29 | +) |
| 30 | + |
| 31 | +func TestTopicAutoCreationCmd(t *testing.T) { |
| 32 | + g := gomega.NewWithT(t) |
| 33 | + |
| 34 | + nsName := fmt.Sprintf("public/test-topic-auto-creation-ns-%s", test.RandomSuffix()) |
| 35 | + createArgs := []string{"create", nsName} |
| 36 | + _, execErr, _, _ := TestNamespaceCommands(createNs, createArgs) |
| 37 | + g.Expect(execErr).Should(gomega.BeNil()) |
| 38 | + |
| 39 | + setArgs := []string{"set-topic-auto-creation", nsName, "--type", "partitioned", "--partitions", "2"} |
| 40 | + out, execErr, _, _ := TestNamespaceCommands(setTopicAutoCreation, setArgs) |
| 41 | + g.Expect(execErr).Should(gomega.BeNil()) |
| 42 | + g.Expect(out.String()).Should(gomega.Equal( |
| 43 | + fmt.Sprintf("Set topic auto-creation config successfully for [%s]\n", nsName))) |
| 44 | + |
| 45 | + getArgs := []string{"get-topic-auto-creation", nsName} |
| 46 | + g.Eventually(func(g gomega.Gomega) { |
| 47 | + out, execErr, _, _ = TestNamespaceCommands(GetTopicAutoCreationCmd, getArgs) |
| 48 | + g.Expect(execErr).Should(gomega.BeNil()) |
| 49 | + |
| 50 | + var cfg utils.TopicAutoCreationConfig |
| 51 | + err := json.Unmarshal(out.Bytes(), &cfg) |
| 52 | + g.Expect(err).Should(gomega.BeNil()) |
| 53 | + g.Expect(cfg.Allow).Should(gomega.BeTrue()) |
| 54 | + g.Expect(cfg.Type.String()).Should(gomega.Equal("partitioned")) |
| 55 | + g.Expect(cfg.Partitions).ShouldNot(gomega.BeNil()) |
| 56 | + g.Expect(*cfg.Partitions).Should(gomega.Equal(2)) |
| 57 | + }).Should(gomega.Succeed()) |
| 58 | + |
| 59 | + removeArgs := []string{"remove-topic-auto-creation", nsName} |
| 60 | + out, execErr, _, _ = TestNamespaceCommands(removeTopicAutoCreation, removeArgs) |
| 61 | + g.Expect(execErr).Should(gomega.BeNil()) |
| 62 | + g.Expect(out.String()).Should(gomega.Equal( |
| 63 | + fmt.Sprintf("Removed topic auto-creation config successfully for [%s]\n", nsName))) |
| 64 | +} |
0 commit comments