Skip to content

Commit

Permalink
Merge pull request #153 from lovoo/126-topic-manager-trailing
Browse files Browse the repository at this point in the history
clean trailing slashes in zookeeper chroot
  • Loading branch information
frairon committed Oct 29, 2018
2 parents e301183 + 2348072 commit 5d9a3f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kafka/topic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func checkPartitions(client sarama.Client, topic string, npar int) error {
func updateChroot(servers []string) (servs []string, chroot string, err error) {
// find chroot in server addresses
for _, server := range servers {
for strings.HasSuffix(server, "/") {
server = server[:len(server)-1]
}
splt := strings.Split(server, "/")
if len(splt) == 1 {
// no chroot in address
Expand Down
11 changes: 11 additions & 0 deletions kafka/topic_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ func TestTopicManager_updateChroot(t *testing.T) {
_, _, err = updateChroot(servers)
ensure.NotNil(t, err)

// check chroot with trailing /
servers = []string{host + "/////"}
_, c, err = updateChroot(servers)
ensure.DeepEqual(t, c, "")
ensure.Nil(t, err)

servers = []string{host + "/test/"}
_, c, err = updateChroot(servers)
ensure.DeepEqual(t, c, "/test")
ensure.Nil(t, err)

}

func TestCheckPartitions(t *testing.T) {
Expand Down

0 comments on commit 5d9a3f4

Please sign in to comment.