Skip to content

Commit

Permalink
Merge pull request kubernetes#984 from thockin/make_vs_new
Browse files Browse the repository at this point in the history
Rename a bunch of "Make" functions to "New"
  • Loading branch information
brendandburns committed Aug 21, 2014
2 parents 1bd4ae0 + 0f97a73 commit 8f5dd8c
Show file tree
Hide file tree
Showing 33 changed files with 217 additions and 217 deletions.
2 changes: 1 addition & 1 deletion cmd/controller-manager/controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {
glog.Fatal("usage: controller-manager -master <master>")
}

controllerManager := controller.MakeReplicationManager(
controllerManager := controller.NewReplicationManager(
client.New("http://"+*master, nil))

controllerManager.Run(10 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
storage, codec := m.API_v1beta1()
handler.delegate = apiserver.Handle(storage, codec, "/api/v1beta1")

controllerManager := controller.MakeReplicationManager(cl)
controllerManager := controller.NewReplicationManager(cl)

// Prove that controllerManager's watch works by making it not sync until after this
// test is over. (Hopefully we don't take 10 minutes!)
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func RecoverPanics(handler http.Handler) http.Handler {
glog.Infof("APIServer panic'd on %v %v: %#v\n%s\n", req.Method, req.RequestURI, x, debug.Stack())
}
}()
defer httplog.MakeLogged(req, &w).StacktraceWhen(
defer httplog.NewLogged(req, &w).StacktraceWhen(
httplog.StatusIsNot(
http.StatusOK,
http.StatusAccepted,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/replication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (r RealPodControl) deletePod(podID string) error {
return r.kubeClient.DeletePod(podID)
}

// MakeReplicationManager creates a new ReplicationManager.
func MakeReplicationManager(kubeClient client.Interface) *ReplicationManager {
// NewReplicationManager creates a new ReplicationManager.
func NewReplicationManager(kubeClient client.Interface) *ReplicationManager {
rm := &ReplicationManager{
kubeClient: kubeClient,
podControl: RealPodControl{
Expand Down
32 changes: 16 additions & 16 deletions pkg/controller/replication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (f *FakePodControl) deletePod(podID string) error {
return nil
}

func makeReplicationController(replicas int) api.ReplicationController {
func newReplicationController(replicas int) api.ReplicationController {
return api.ReplicationController{
DesiredState: api.ReplicationControllerState{
Replicas: replicas,
Expand All @@ -84,7 +84,7 @@ func makeReplicationController(replicas int) api.ReplicationController {
}
}

func makePodList(count int) api.PodList {
func newPodList(count int) api.PodList {
pods := []api.Pod{}
for i := 0; i < count; i++ {
pods = append(pods, api.Pod{
Expand All @@ -108,7 +108,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
}

func TestSyncReplicationControllerDoesNothing(t *testing.T) {
body, _ := api.Encode(makePodList(2))
body, _ := api.Encode(newPodList(2))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
Expand All @@ -118,17 +118,17 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {

fakePodControl := FakePodControl{}

manager := MakeReplicationManager(client)
manager := NewReplicationManager(client)
manager.podControl = &fakePodControl

controllerSpec := makeReplicationController(2)
controllerSpec := newReplicationController(2)

manager.syncReplicationController(controllerSpec)
validateSyncReplication(t, &fakePodControl, 0, 0)
}

func TestSyncReplicationControllerDeletes(t *testing.T) {
body, _ := api.Encode(makePodList(2))
body, _ := api.Encode(newPodList(2))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
Expand All @@ -138,17 +138,17 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {

fakePodControl := FakePodControl{}

manager := MakeReplicationManager(client)
manager := NewReplicationManager(client)
manager.podControl = &fakePodControl

controllerSpec := makeReplicationController(1)
controllerSpec := newReplicationController(1)

manager.syncReplicationController(controllerSpec)
validateSyncReplication(t, &fakePodControl, 0, 1)
}

func TestSyncReplicationControllerCreates(t *testing.T) {
body, _ := api.Encode(makePodList(0))
body, _ := api.Encode(newPodList(0))
fakeHandler := util.FakeHandler{
StatusCode: 200,
ResponseBody: string(body),
Expand All @@ -158,10 +158,10 @@ func TestSyncReplicationControllerCreates(t *testing.T) {

fakePodControl := FakePodControl{}

manager := MakeReplicationManager(client)
manager := NewReplicationManager(client)
manager.podControl = &fakePodControl

controllerSpec := makeReplicationController(2)
controllerSpec := newReplicationController(2)

manager.syncReplicationController(controllerSpec)
validateSyncReplication(t, &fakePodControl, 2, 0)
Expand Down Expand Up @@ -268,16 +268,16 @@ func TestSyncronize(t *testing.T) {
},
}

fakeEtcd := tools.MakeFakeEtcdClient(t)
fakeEtcd := tools.NewFakeEtcdClient(t)
fakeEtcd.Data["/registry/controllers"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Nodes: []*etcd.Node{
{
Value: util.MakeJSONString(controllerSpec1),
Value: util.EncodeJSON(controllerSpec1),
},
{
Value: util.MakeJSONString(controllerSpec2),
Value: util.EncodeJSON(controllerSpec2),
},
},
},
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestSyncronize(t *testing.T) {
})
testServer := httptest.NewServer(mux)
client := client.New(testServer.URL, nil)
manager := MakeReplicationManager(client)
manager := NewReplicationManager(client)
fakePodControl := FakePodControl{}
manager.podControl = &fakePodControl

Expand All @@ -328,7 +328,7 @@ func (fw FakeWatcher) WatchReplicationControllers(l, f labels.Selector, rv uint6

func TestWatchControllers(t *testing.T) {
client := FakeWatcher{watch.NewFake(), &client.Fake{}}
manager := MakeReplicationManager(client)
manager := NewReplicationManager(client)
var testControllerSpec api.ReplicationController
received := make(chan struct{})
manager.syncHandler = func(controllerSpec api.ReplicationController) error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/election/etcd_master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func TestEtcdMasterOther(t *testing.T) {
path := "foo"
etcd := tools.MakeFakeEtcdClient(t)
etcd := tools.NewFakeEtcdClient(t)
etcd.Set(path, "baz", 0)
master := NewEtcdMasterElector(etcd)
w := master.Elect(path, "bar")
Expand All @@ -39,7 +39,7 @@ func TestEtcdMasterOther(t *testing.T) {

func TestEtcdMasterNoOther(t *testing.T) {
path := "foo"
e := tools.MakeFakeEtcdClient(t)
e := tools.NewFakeEtcdClient(t)
e.TestIndex = true
e.Data["foo"] = tools.EtcdResponseWithError{
R: &etcd.Response{
Expand All @@ -60,7 +60,7 @@ func TestEtcdMasterNoOther(t *testing.T) {

func TestEtcdMasterNoOtherThenConflict(t *testing.T) {
path := "foo"
e := tools.MakeFakeEtcdClient(t)
e := tools.NewFakeEtcdClient(t)
e.TestIndex = true
// Ok, so we set up a chain of responses from etcd:
// 1) Nothing there
Expand Down
4 changes: 2 additions & 2 deletions pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestHealthChecker(t *testing.T) {
container := api.Container{
LivenessProbe: &api.LivenessProbe{
HTTPGet: &api.HTTPGetProbe{
Port: util.MakeIntOrStringFromString(port),
Port: util.NewIntOrStringFromString(port),
Path: "/foo/bar",
Host: host,
},
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestMuxHealthChecker(t *testing.T) {
},
}
container.LivenessProbe.Type = tt.probeType
container.LivenessProbe.HTTPGet.Port = util.MakeIntOrStringFromString(port)
container.LivenessProbe.HTTPGet.Port = util.NewIntOrStringFromString(port)
container.LivenessProbe.HTTPGet.Host = host
health, err := mc.HealthCheck("test", api.PodState{}, container)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions pkg/health/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func TestGetURLParts(t *testing.T) {
port int
path string
}{
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromInt(-1), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString(""), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("-1"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("not-found"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromInt(76), Path: ""}, true, "127.0.0.1", 76, ""},
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("118"), Path: ""}, true, "127.0.0.1", 118, ""},
{&api.HTTPGetProbe{Host: "hostname", Port: util.MakeIntOrStringFromInt(76), Path: "path"}, true, "hostname", 76, "path"},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromInt(-1), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString(""), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("-1"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("not-found"), Path: ""}, false, "", -1, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromInt(76), Path: ""}, true, "127.0.0.1", 76, ""},
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("118"), Path: ""}, true, "127.0.0.1", 118, ""},
{&api.HTTPGetProbe{Host: "hostname", Port: util.NewIntOrStringFromInt(76), Path: "path"}, true, "hostname", 76, "path"},
}

for _, test := range testCases {
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestHTTPHealthChecker(t *testing.T) {
}
params := container.LivenessProbe.HTTPGet
if params != nil {
params.Port = util.MakeIntOrStringFromString(port)
params.Port = util.NewIntOrStringFromString(port)
params.Host = host
}
health, err := hc.HealthCheck("test", api.PodState{PodIP: host}, container)
Expand Down
16 changes: 8 additions & 8 deletions pkg/health/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func TestGetTCPAddrParts(t *testing.T) {
host string
port int
}{
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromInt(-1)}, false, "", -1},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("-1")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("not-found")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("found")}, true, "1.2.3.4", 93},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromInt(76)}, true, "1.2.3.4", 76},
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("118")}, true, "1.2.3.4", 118},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromInt(-1)}, false, "", -1},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("-1")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("not-found")}, false, "", -1},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("found")}, true, "1.2.3.4", 93},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromInt(76)}, true, "1.2.3.4", 76},
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("118")}, true, "1.2.3.4", 118},
}

for _, test := range testCases {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestTcpHealthChecker(t *testing.T) {
}
params := container.LivenessProbe.TCPSocket
if params != nil && test.expectedStatus == Healthy {
params.Port = util.MakeIntOrStringFromString(port)
params.Port = util.NewIntOrStringFromString(port)
}
status, err := checker.HealthCheck("test", api.PodState{PodIP: host}, container)
if status != test.expectedStatus {
Expand Down
12 changes: 6 additions & 6 deletions pkg/httplog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// Intended to wrap calls to your ServeMux.
func Handler(delegate http.Handler, pred StacktracePred) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
defer MakeLogged(req, &w).StacktraceWhen(pred).Log()
defer NewLogged(req, &w).StacktraceWhen(pred).Log()
delegate.ServeHTTP(w, req)
})
}
Expand All @@ -59,22 +59,22 @@ func DefaultStacktracePred(status int) bool {
return status < http.StatusOK || status >= http.StatusBadRequest
}

// MakeLogged turns a normal response writer into a logged response writer.
// NewLogged turns a normal response writer into a logged response writer.
//
// Usage:
//
// defer MakeLogged(req, &w).StacktraceWhen(StatusIsNot(200, 202)).Log()
// defer NewLogged(req, &w).StacktraceWhen(StatusIsNot(200, 202)).Log()
//
// (Only the call to Log() is defered, so you can set everything up in one line!)
//
// Note that this *changes* your writer, to route response writing actions
// through the logger.
//
// Use LogOf(w).Addf(...) to log something along with the response result.
func MakeLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
func NewLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
if _, ok := (*w).(*respLogger); ok {
// Don't double-wrap!
panic("multiple MakeLogged calls!")
panic("multiple NewLogged calls!")
}
rl := &respLogger{
startTime: time.Now(),
Expand All @@ -87,7 +87,7 @@ func MakeLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
}

// LogOf returns the logger hiding in w. Panics if there isn't such a logger,
// because MakeLogged() must have been previously called for the log to work.
// because NewLogged() must have been previously called for the log to work.
func LogOf(w http.ResponseWriter) *respLogger {
if rl, ok := w.(*respLogger); ok {
return rl
Expand Down
12 changes: 6 additions & 6 deletions pkg/httplog/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ func TestStatusIsNot(t *testing.T) {
}
}

func TestMakeLogged(t *testing.T) {
func TestNewLogged(t *testing.T) {
req, err := http.NewRequest("GET", "http://example.com", nil)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
handler := func(w http.ResponseWriter, r *http.Request) {
MakeLogged(req, &w)
NewLogged(req, &w)
defer func() {
if r := recover(); r == nil {
t.Errorf("Expected MakeLogged to panic")
t.Errorf("Expected NewLogged to panic")
}
}()
MakeLogged(req, &w)
NewLogged(req, &w)
}
w := httptest.NewRecorder()
handler(w, req)
Expand All @@ -93,7 +93,7 @@ func TestLogOf(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
var want *respLogger
if makeLogger {
want = MakeLogged(req, &w)
want = NewLogged(req, &w)
} else {
defer func() {
if r := recover(); r == nil {
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestUnlogged(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {
want := w
if makeLogger {
MakeLogged(req, &w)
NewLogged(req, &w)
}
got := Unlogged(w)
if want != got {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubecfg/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func ResizeController(name string, replicas int, client client.Interface) error
return nil
}

func makePorts(spec string) []api.Port {
func portsFromString(spec string) []api.Port {
parts := strings.Split(spec, ",")
var result []api.Port
for _, part := range parts {
Expand Down Expand Up @@ -172,7 +172,7 @@ func RunController(image, name string, replicas int, client client.Interface, po
{
Name: strings.ToLower(name),
Image: image,
Ports: makePorts(portSpec),
Ports: portsFromString(portSpec),
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubecfg/kubecfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestLoadAuthInfo(t *testing.T) {
}

func TestMakePorts(t *testing.T) {
var makePortsTests = []struct {
var testCases = []struct {
spec string
ports []api.Port
}{
Expand All @@ -246,8 +246,8 @@ func TestMakePorts(t *testing.T) {
},
},
}
for _, tt := range makePortsTests {
ports := makePorts(tt.spec)
for _, tt := range testCases {
ports := portsFromString(tt.spec)
if !reflect.DeepEqual(ports, tt.ports) {
t.Errorf("Expected %#v, got %#v", tt.ports, ports)
}
Expand Down
Loading

0 comments on commit 8f5dd8c

Please sign in to comment.