Skip to content

Commit

Permalink
Added strings.TrimSuffix to Master URL call
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrunwald committed Jul 12, 2016
1 parent 902e791 commit 77129e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mesos/cluster.go
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"net/url"
"strings"
"time"

"github.com/cloudflare/complainer"
Expand All @@ -27,8 +28,13 @@ type Cluster struct {

// NewCluster creates a new cluster with the provided list of masters
func NewCluster(masters []string) *Cluster {
var cleanMasters []string
for _, master := range masters {
cleanMasters = append(cleanMasters, strings.TrimSuffix(master, "/"))
}

return &Cluster{
masters: masters,
masters: cleanMasters,
client: http.Client{
Timeout: time.Second * 30,
},
Expand Down
30 changes: 30 additions & 0 deletions mesos/cluster_test.go
@@ -0,0 +1,30 @@
package mesos

import (
"reflect"
"testing"
)

func TestNewCluster(t *testing.T) {
inputMasters := []string{
"http://master1.com",
"http://master2.com/",
"http://master3.com/fancy/path",
"http://master4.com/fancy/path/",
}
expectedMasters := []string{
"http://master1.com",
"http://master2.com",
"http://master3.com/fancy/path",
"http://master4.com/fancy/path",
}

cluster := NewCluster(inputMasters)
if cluster == nil {
t.Error("Cluster is nil. Expected mesos.Cluster pointer.")
}

if !reflect.DeepEqual(cluster.masters, expectedMasters) {
t.Errorf("Master list is not equal. Got %+v, expected %+v", cluster.masters, expectedMasters)
}
}

0 comments on commit 77129e9

Please sign in to comment.