diff --git a/kafka/topic_manager.go b/kafka/topic_manager.go index 6c3eeb11..2063d844 100644 --- a/kafka/topic_manager.go +++ b/kafka/topic_manager.go @@ -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 diff --git a/kafka/topic_manager_test.go b/kafka/topic_manager_test.go index 603d6f5d..a2a838dc 100644 --- a/kafka/topic_manager_test.go +++ b/kafka/topic_manager_test.go @@ -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) {