Skip to content

Commit ad7887e

Browse files
authored
Add test for admin topic creation (#1152)
### Motivation Lacking tests for creating topic using pulsarAdmin ### Modifications - Add test for admin topic creation
1 parent cae74c5 commit ad7887e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 admin
19+
20+
import (
21+
"testing"
22+
23+
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin/config"
24+
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
25+
)
26+
27+
func TestCreateTopic(t *testing.T) {
28+
checkError := func(err error) {
29+
if err != nil {
30+
t.Error(err)
31+
}
32+
}
33+
34+
cfg := &config.Config{}
35+
admin, err := New(cfg)
36+
checkError(err)
37+
38+
topic := "persistent://public/default/testCreateTopic"
39+
40+
topicName, err := utils.GetTopicName(topic)
41+
checkError(err)
42+
43+
err = admin.Topics().Create(*topicName, 0)
44+
checkError(err)
45+
46+
topicLists, err := admin.Namespaces().GetTopics("public/default")
47+
checkError(err)
48+
49+
for _, t := range topicLists {
50+
if t == topic {
51+
return
52+
}
53+
}
54+
t.Error("Couldn't find topic: " + topic)
55+
}

0 commit comments

Comments
 (0)