diff --git a/cmd/controller-manager/controller-manager.go b/cmd/controller-manager/controller-manager.go index efbee00538..d32992b120 100644 --- a/cmd/controller-manager/controller-manager.go +++ b/cmd/controller-manager/controller-manager.go @@ -46,7 +46,7 @@ func main() { glog.Fatal("usage: controller-manager -master ") } - controllerManager := controller.MakeReplicationManager( + controllerManager := controller.NewReplicationManager( client.New("http://"+*master, nil)) controllerManager.Run(10 * time.Second) diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 9138824b0d..198ab4b755 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -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!) diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index 4539dd63f9..89a859f550 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -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, diff --git a/pkg/controller/replication_controller.go b/pkg/controller/replication_controller.go index b39e863511..898efa29aa 100644 --- a/pkg/controller/replication_controller.go +++ b/pkg/controller/replication_controller.go @@ -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{ diff --git a/pkg/controller/replication_controller_test.go b/pkg/controller/replication_controller_test.go index 19f996f377..659613f88a 100644 --- a/pkg/controller/replication_controller_test.go +++ b/pkg/controller/replication_controller_test.go @@ -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, @@ -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{ @@ -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), @@ -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), @@ -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), @@ -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) @@ -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), }, }, }, @@ -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 @@ -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 { diff --git a/pkg/election/etcd_master_test.go b/pkg/election/etcd_master_test.go index 5e342153f4..ea1a69d4fe 100644 --- a/pkg/election/etcd_master_test.go +++ b/pkg/election/etcd_master_test.go @@ -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") @@ -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{ @@ -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 diff --git a/pkg/health/health_test.go b/pkg/health/health_test.go index 72713117ff..88a0bdc371 100644 --- a/pkg/health/health_test.go +++ b/pkg/health/health_test.go @@ -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, }, @@ -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 { diff --git a/pkg/health/http_test.go b/pkg/health/http_test.go index 508f6096b4..6a5c1418f7 100644 --- a/pkg/health/http_test.go +++ b/pkg/health/http_test.go @@ -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 { @@ -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) diff --git a/pkg/health/tcp_test.go b/pkg/health/tcp_test.go index ade5c53bc5..2168e981d3 100644 --- a/pkg/health/tcp_test.go +++ b/pkg/health/tcp_test.go @@ -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 { @@ -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 { diff --git a/pkg/httplog/log.go b/pkg/httplog/log.go index eb428e57f4..0982fc3fbb 100644 --- a/pkg/httplog/log.go +++ b/pkg/httplog/log.go @@ -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) }) } @@ -59,11 +59,11 @@ 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!) // @@ -71,10 +71,10 @@ func DefaultStacktracePred(status int) bool { // 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(), @@ -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 diff --git a/pkg/httplog/log_test.go b/pkg/httplog/log_test.go index 0a53c33d50..e287c8b11d 100644 --- a/pkg/httplog/log_test.go +++ b/pkg/httplog/log_test.go @@ -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) @@ -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 { @@ -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 { diff --git a/pkg/kubecfg/kubecfg.go b/pkg/kubecfg/kubecfg.go index 8a89f6917c..40cae52294 100644 --- a/pkg/kubecfg/kubecfg.go +++ b/pkg/kubecfg/kubecfg.go @@ -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 { @@ -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), }, }, }, diff --git a/pkg/kubecfg/kubecfg_test.go b/pkg/kubecfg/kubecfg_test.go index 7967c8b9b1..8c5696fea4 100644 --- a/pkg/kubecfg/kubecfg_test.go +++ b/pkg/kubecfg/kubecfg_test.go @@ -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 }{ @@ -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) } diff --git a/pkg/kubecfg/proxy_server.go b/pkg/kubecfg/proxy_server.go index ccc5f38751..d254991651 100644 --- a/pkg/kubecfg/proxy_server.go +++ b/pkg/kubecfg/proxy_server.go @@ -31,7 +31,7 @@ type ProxyServer struct { Client *client.Client } -func makeFileHandler(prefix, base string) http.Handler { +func newFileHandler(prefix, base string) http.Handler { return http.StripPrefix(prefix, http.FileServer(http.Dir(base))) } @@ -44,7 +44,7 @@ func NewProxyServer(filebase, host string, auth *client.AuthInfo) *ProxyServer { Client: client.New(host, auth), } http.Handle("/api/", server) - http.Handle("/static/", makeFileHandler("/static/", filebase)) + http.Handle("/static/", newFileHandler("/static/", filebase)) return server } diff --git a/pkg/kubecfg/proxy_server_test.go b/pkg/kubecfg/proxy_server_test.go index 197c363dc8..f5a4980109 100644 --- a/pkg/kubecfg/proxy_server_test.go +++ b/pkg/kubecfg/proxy_server_test.go @@ -34,7 +34,7 @@ func TestFileServing(t *testing.T) { t.Errorf("Unexpected error: %v", err) } prefix := "/foo/" - handler := makeFileHandler(prefix, dir) + handler := newFileHandler(prefix, dir) server := httptest.NewServer(handler) client := http.Client{} req, err := http.NewRequest("GET", server.URL+prefix+"test.txt", nil) diff --git a/pkg/kubelet/config/etcd_test.go b/pkg/kubelet/config/etcd_test.go index c044c99ed0..5f77711c87 100644 --- a/pkg/kubelet/config/etcd_test.go +++ b/pkg/kubelet/config/etcd_test.go @@ -30,7 +30,7 @@ import ( // TODO(lavalamp): Use the etcd watcher from the tools package, and make sure all test cases here are tested there. func TestGetEtcdData(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}) fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -57,7 +57,7 @@ func TestGetEtcdData(t *testing.T) { } func TestGetEtcdNoData(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}, 1) fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{}, @@ -72,7 +72,7 @@ func TestGetEtcdNoData(t *testing.T) { } func TestGetEtcd(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}, 1) manifest := api.ContainerManifest{ID: "foo", Version: "v1beta1", Containers: []api.Container{{Name: "1", Image: "foo"}}} fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ @@ -107,7 +107,7 @@ func TestGetEtcd(t *testing.T) { } func TestWatchEtcd(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}, 1) fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -134,7 +134,7 @@ func TestWatchEtcd(t *testing.T) { } func TestGetEtcdNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}, 1) fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{}, @@ -149,7 +149,7 @@ func TestGetEtcdNotFound(t *testing.T) { } func TestGetEtcdError(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) ch := make(chan interface{}, 1) fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{ R: &etcd.Response{}, diff --git a/pkg/kubelet/kubelet_test.go b/pkg/kubelet/kubelet_test.go index 8db2a41beb..4bb60df085 100644 --- a/pkg/kubelet/kubelet_test.go +++ b/pkg/kubelet/kubelet_test.go @@ -36,8 +36,8 @@ import ( "github.com/stretchr/testify/mock" ) -func makeTestKubelet(t *testing.T) (*Kubelet, *tools.FakeEtcdClient, *FakeDockerClient) { - fakeEtcdClient := tools.MakeFakeEtcdClient(t) +func newTestKubelet(t *testing.T) (*Kubelet, *tools.FakeEtcdClient, *FakeDockerClient) { + fakeEtcdClient := tools.NewFakeEtcdClient(t) fakeDocker := &FakeDockerClient{ err: nil, } @@ -114,7 +114,7 @@ func TestContainerManifestNaming(t *testing.T) { } func TestGetContainerID(t *testing.T) { - _, _, fakeDocker := makeTestKubelet(t) + _, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { ID: "foobar", @@ -164,7 +164,7 @@ func TestKillContainerWithError(t *testing.T) { }, }, } - kubelet, _, _ := makeTestKubelet(t) + kubelet, _, _ := newTestKubelet(t) kubelet.dockerClient = fakeDocker err := kubelet.killContainer(&fakeDocker.containerList[0]) if err == nil { @@ -174,7 +174,7 @@ func TestKillContainerWithError(t *testing.T) { } func TestKillContainer(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { ID: "1234", @@ -223,7 +223,7 @@ func (cr *channelReader) GetList() [][]Pod { } func TestSyncPodsDoesNothing(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) container := api.Container{Name: "bar"} fakeDocker.containerList = []docker.APIContainers{ { @@ -278,7 +278,7 @@ func matchString(t *testing.T, pattern, str string) bool { } func TestSyncPodsCreatesNetAndContainer(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{} err := kubelet.SyncPods([]Pod{ { @@ -310,7 +310,7 @@ func TestSyncPodsCreatesNetAndContainer(t *testing.T) { } func TestSyncPodsWithNetCreatesContainer(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { // network container @@ -347,7 +347,7 @@ func TestSyncPodsWithNetCreatesContainer(t *testing.T) { } func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { // format is k8s---- @@ -388,7 +388,7 @@ func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) { } func TestSyncPodsDeletes(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { // the k8s prefix is required for the kubelet to manage the container @@ -426,7 +426,7 @@ func TestSyncPodsDeletes(t *testing.T) { } func TestSyncPodDeletesDuplicate(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) dockerContainers := DockerContainers{ "1234": &docker.APIContainers{ // the k8s prefix is required for the kubelet to manage the container @@ -478,7 +478,7 @@ func (f *FalseHealthChecker) HealthCheck(podFullName string, state api.PodState, } func TestSyncPodBadHash(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.healthChecker = &FalseHealthChecker{} dockerContainers := DockerContainers{ "1234": &docker.APIContainers{ @@ -520,7 +520,7 @@ func TestSyncPodBadHash(t *testing.T) { } func TestSyncPodUnhealthy(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.healthChecker = &FalseHealthChecker{} dockerContainers := DockerContainers{ "1234": &docker.APIContainers{ @@ -567,7 +567,7 @@ func TestSyncPodUnhealthy(t *testing.T) { } func TestEventWriting(t *testing.T) { - kubelet, fakeEtcd, _ := makeTestKubelet(t) + kubelet, fakeEtcd, _ := newTestKubelet(t) expectedEvent := api.Event{ Event: "test", Container: &api.Container{ @@ -600,7 +600,7 @@ func TestEventWriting(t *testing.T) { } func TestEventWritingError(t *testing.T) { - kubelet, fakeEtcd, _ := makeTestKubelet(t) + kubelet, fakeEtcd, _ := newTestKubelet(t) fakeEtcd.Err = fmt.Errorf("test error") err := kubelet.LogEvent(&api.Event{ Event: "test", @@ -639,7 +639,7 @@ func TestMakeEnvVariables(t *testing.T) { } func TestMountExternalVolumes(t *testing.T) { - kubelet, _, _ := makeTestKubelet(t) + kubelet, _, _ := newTestKubelet(t) manifest := api.ContainerManifest{ Volumes: []api.Volume{ { @@ -887,7 +887,7 @@ func TestGetContainerInfo(t *testing.T) { cadvisorReq := getCadvisorContainerInfoRequest(req) mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil) - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.cadvisorClient = mockCadvisor fakeDocker.containerList = []docker.APIContainers{ { @@ -958,7 +958,7 @@ func TestGetRooInfo(t *testing.T) { } func TestGetContainerInfoWithoutCadvisor(t *testing.T) { - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{ { ID: "foobar", @@ -995,7 +995,7 @@ func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) { expectedErr := fmt.Errorf("some error") mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, expectedErr) - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.cadvisorClient = mockCadvisor fakeDocker.containerList = []docker.APIContainers{ { @@ -1023,7 +1023,7 @@ func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) { func TestGetContainerInfoOnNonExistContainer(t *testing.T) { mockCadvisor := &mockCadvisorClient{} - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.cadvisorClient = mockCadvisor fakeDocker.containerList = []docker.APIContainers{} @@ -1048,7 +1048,7 @@ func (f *fakeContainerCommandRunner) RunInContainer(id string, cmd []string) ([] func TestRunInContainerNoSuchPod(t *testing.T) { fakeCommandRunner := fakeContainerCommandRunner{} - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) fakeDocker.containerList = []docker.APIContainers{} kubelet.runner = &fakeCommandRunner @@ -1069,7 +1069,7 @@ func TestRunInContainerNoSuchPod(t *testing.T) { func TestRunInContainer(t *testing.T) { fakeCommandRunner := fakeContainerCommandRunner{} - kubelet, _, fakeDocker := makeTestKubelet(t) + kubelet, _, fakeDocker := newTestKubelet(t) kubelet.runner = &fakeCommandRunner containerID := "abc1234" diff --git a/pkg/kubelet/server.go b/pkg/kubelet/server.go index 57383b09d0..c0def80ee2 100644 --- a/pkg/kubelet/server.go +++ b/pkg/kubelet/server.go @@ -206,7 +206,7 @@ func (s *Server) handleSpec(w http.ResponseWriter, req *http.Request) { // ServeHTTP responds to HTTP requests on the Kubelet func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { - defer httplog.MakeLogged(req, &w).StacktraceWhen( + defer httplog.NewLogged(req, &w).StacktraceWhen( httplog.StatusIsNot( http.StatusOK, http.StatusNotFound, diff --git a/pkg/kubelet/server_test.go b/pkg/kubelet/server_test.go index 99a542e00b..b6662a86cc 100644 --- a/pkg/kubelet/server_test.go +++ b/pkg/kubelet/server_test.go @@ -70,7 +70,7 @@ type serverTestFramework struct { testHTTPServer *httptest.Server } -func makeServerTest() *serverTestFramework { +func newServerTest() *serverTestFramework { fw := &serverTestFramework{ updateChan: make(chan interface{}), } @@ -89,11 +89,11 @@ func readResp(resp *http.Response) (string, error) { } func TestContainer(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expected := []api.ContainerManifest{ {ID: "test_manifest"}, } - body := bytes.NewBuffer([]byte(util.MakeJSONString(expected[0]))) // Only send a single ContainerManifest + body := bytes.NewBuffer([]byte(util.EncodeJSON(expected[0]))) // Only send a single ContainerManifest resp, err := http.Post(fw.testHTTPServer.URL+"/container", "application/json", body) if err != nil { t.Errorf("Post returned: %v", err) @@ -111,12 +111,12 @@ func TestContainer(t *testing.T) { } func TestContainers(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expected := []api.ContainerManifest{ {ID: "test_manifest_1"}, {ID: "test_manifest_2"}, } - body := bytes.NewBuffer([]byte(util.MakeJSONString(expected))) + body := bytes.NewBuffer([]byte(util.EncodeJSON(expected))) resp, err := http.Post(fw.testHTTPServer.URL+"/containers", "application/json", body) if err != nil { t.Errorf("Post returned: %v", err) @@ -134,7 +134,7 @@ func TestContainers(t *testing.T) { } func TestPodInfo(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expected := api.PodInfo{"goodpod": docker.Container{ID: "myContainerID"}} fw.fakeKubelet.infoFunc = func(name string) (api.PodInfo, error) { if name == "goodpod.etcd" { @@ -160,7 +160,7 @@ func TestPodInfo(t *testing.T) { } func TestContainerInfo(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expectedInfo := &info.ContainerInfo{ StatsPercentiles: &info.ContainerStatsPercentiles{ MaxMemoryUsage: 1024001, @@ -201,7 +201,7 @@ func TestContainerInfo(t *testing.T) { } func TestRootInfo(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expectedInfo := &info.ContainerInfo{ StatsPercentiles: &info.ContainerStatsPercentiles{ MaxMemoryUsage: 1024001, @@ -237,7 +237,7 @@ func TestRootInfo(t *testing.T) { } func TestMachineInfo(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() expectedInfo := &info.MachineInfo{ NumCores: 4, MemoryCapacity: 1024, @@ -262,7 +262,7 @@ func TestMachineInfo(t *testing.T) { } func TestServeLogs(t *testing.T) { - fw := makeServerTest() + fw := newServerTest() content := string(`
kubelet.loggoogle.log
`) diff --git a/pkg/registry/endpoint/endpoints_test.go b/pkg/registry/endpoint/endpoints_test.go index 87fe7d4e92..58ba391332 100644 --- a/pkg/registry/endpoint/endpoints_test.go +++ b/pkg/registry/endpoint/endpoints_test.go @@ -28,7 +28,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) -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{ @@ -122,7 +122,7 @@ func TestFindPort(t *testing.T) { } func TestSyncEndpointsEmpty(t *testing.T) { - body, _ := json.Marshal(makePodList(0)) + body, _ := json.Marshal(newPodList(0)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -139,7 +139,7 @@ func TestSyncEndpointsEmpty(t *testing.T) { } func TestSyncEndpointsError(t *testing.T) { - body, _ := json.Marshal(makePodList(0)) + body, _ := json.Marshal(newPodList(0)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), @@ -157,7 +157,7 @@ func TestSyncEndpointsError(t *testing.T) { } func TestSyncEndpointsItems(t *testing.T) { - body, _ := json.Marshal(makePodList(1)) + body, _ := json.Marshal(newPodList(1)) fakeHandler := util.FakeHandler{ StatusCode: 200, ResponseBody: string(body), diff --git a/pkg/registry/etcd/etcd_test.go b/pkg/registry/etcd/etcd_test.go index 6ef0889c93..0e10c22631 100644 --- a/pkg/registry/etcd/etcd_test.go +++ b/pkg/registry/etcd/etcd_test.go @@ -30,7 +30,7 @@ import ( "github.com/coreos/go-etcd/etcd" ) -func MakeTestEtcdRegistry(client tools.EtcdClient, machines []string) *Registry { +func NewTestEtcdRegistry(client tools.EtcdClient, machines []string) *Registry { registry := NewRegistry(client, minion.NewRegistry(machines)) registry.manifestFactory = &BasicManifestFactory{ serviceRegistry: ®istrytest.ServiceRegistry{}, @@ -39,9 +39,9 @@ func MakeTestEtcdRegistry(client tools.EtcdClient, machines []string) *Registry } func TestEtcdGetPod(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Set("/registry/pods/foo", api.EncodeOrDie(api.Pod{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) pod, err := registry.GetPod("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -53,14 +53,14 @@ func TestEtcdGetPod(t *testing.T) { } func TestEtcdGetPodNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: nil, }, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) _, err := registry.GetPod("foo") if err == nil { t.Errorf("Unexpected non-error.") @@ -68,7 +68,7 @@ func TestEtcdGetPodNotFound(t *testing.T) { } func TestEtcdCreatePod(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -77,7 +77,7 @@ func TestEtcdCreatePod(t *testing.T) { E: tools.EtcdErrorNotFound, } fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreatePod("machine", api.Pod{ JSONBase: api.JSONBase{ ID: "foo", @@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) { } func TestEtcdCreatePodAlreadyExisting(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ @@ -131,7 +131,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) { }, E: nil, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreatePod("machine", api.Pod{ JSONBase: api.JSONBase{ ID: "foo", @@ -143,7 +143,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) { } func TestEtcdCreatePodWithContainersError(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -157,7 +157,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) { }, E: tools.EtcdErrorValueRequired, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreatePod("machine", api.Pod{ JSONBase: api.JSONBase{ ID: "foo", @@ -176,7 +176,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) { } func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -190,7 +190,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { }, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreatePod("machine", api.Pod{ JSONBase: api.JSONBase{ ID: "foo", @@ -236,7 +236,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) { } func TestEtcdCreatePodWithExistingContainers(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -249,7 +249,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { {ID: "bar"}, }, }), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreatePod("machine", api.Pod{ JSONBase: api.JSONBase{ ID: "foo", @@ -295,7 +295,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) { } func TestEtcdDeletePod(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true key := "/registry/pods/foo" @@ -308,7 +308,7 @@ func TestEtcdDeletePod(t *testing.T) { {ID: "foo"}, }, }), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.DeletePod("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -331,7 +331,7 @@ func TestEtcdDeletePod(t *testing.T) { } func TestEtcdDeletePodMultipleContainers(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true key := "/registry/pods/foo" @@ -345,7 +345,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { {ID: "bar"}, }, }), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.DeletePod("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -372,7 +372,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) { } func TestEtcdEmptyListPods(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/pods" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -382,7 +382,7 @@ func TestEtcdEmptyListPods(t *testing.T) { }, E: nil, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) pods, err := registry.ListPods(labels.Everything()) if err != nil { t.Errorf("unexpected error: %v", err) @@ -394,13 +394,13 @@ func TestEtcdEmptyListPods(t *testing.T) { } func TestEtcdListPodsNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/pods" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{}, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) pods, err := registry.ListPods(labels.Everything()) if err != nil { t.Errorf("unexpected error: %v", err) @@ -412,7 +412,7 @@ func TestEtcdListPodsNotFound(t *testing.T) { } func TestEtcdListPods(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/pods" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -435,7 +435,7 @@ func TestEtcdListPods(t *testing.T) { }, E: nil, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) pods, err := registry.ListPods(labels.Everything()) if err != nil { t.Errorf("unexpected error: %v", err) @@ -451,13 +451,13 @@ func TestEtcdListPods(t *testing.T) { } func TestEtcdListControllersNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/controllers" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{}, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) controllers, err := registry.ListControllers() if err != nil { t.Errorf("unexpected error: %v", err) @@ -469,13 +469,13 @@ func TestEtcdListControllersNotFound(t *testing.T) { } func TestEtcdListServicesNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/services/specs" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{}, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) services, err := registry.ListServices() if err != nil { t.Errorf("unexpected error: %v", err) @@ -487,7 +487,7 @@ func TestEtcdListServicesNotFound(t *testing.T) { } func TestEtcdListControllers(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/controllers" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -504,7 +504,7 @@ func TestEtcdListControllers(t *testing.T) { }, E: nil, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) controllers, err := registry.ListControllers() if err != nil { t.Errorf("unexpected error: %v", err) @@ -516,9 +516,9 @@ func TestEtcdListControllers(t *testing.T) { } func TestEtcdGetController(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) ctrl, err := registry.GetController("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -530,14 +530,14 @@ func TestEtcdGetController(t *testing.T) { } func TestEtcdGetControllerNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Data["/registry/controllers/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: nil, }, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) ctrl, err := registry.GetController("foo") if ctrl != nil { t.Errorf("Unexpected non-nil controller: %#v", ctrl) @@ -548,8 +548,8 @@ func TestEtcdGetControllerNotFound(t *testing.T) { } func TestEtcdDeleteController(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + fakeClient := tools.NewFakeEtcdClient(t) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.DeleteController("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -565,8 +565,8 @@ func TestEtcdDeleteController(t *testing.T) { } func TestEtcdCreateController(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + fakeClient := tools.NewFakeEtcdClient(t) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreateController(api.ReplicationController{ JSONBase: api.JSONBase{ ID: "foo", @@ -592,10 +592,10 @@ func TestEtcdCreateController(t *testing.T) { } func TestEtcdCreateControllerAlreadyExisting(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreateController(api.ReplicationController{ JSONBase: api.JSONBase{ ID: "foo", @@ -607,11 +607,11 @@ func TestEtcdCreateControllerAlreadyExisting(t *testing.T) { } func TestEtcdUpdateController(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true resp, _ := fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.UpdateController(api.ReplicationController{ JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex}, DesiredState: api.ReplicationControllerState{ @@ -629,7 +629,7 @@ func TestEtcdUpdateController(t *testing.T) { } func TestEtcdListServices(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) key := "/registry/services/specs" fakeClient.Data[key] = tools.EtcdResponseWithError{ R: &etcd.Response{ @@ -646,7 +646,7 @@ func TestEtcdListServices(t *testing.T) { }, E: nil, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) services, err := registry.ListServices() if err != nil { t.Errorf("unexpected error: %v", err) @@ -658,8 +658,8 @@ func TestEtcdListServices(t *testing.T) { } func TestEtcdCreateService(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + fakeClient := tools.NewFakeEtcdClient(t) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreateService(api.Service{ JSONBase: api.JSONBase{ID: "foo"}, }) @@ -684,9 +684,9 @@ func TestEtcdCreateService(t *testing.T) { } func TestEtcdCreateServiceAlreadyExisting(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.CreateService(api.Service{ JSONBase: api.JSONBase{ID: "foo"}, }) @@ -696,9 +696,9 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) { } func TestEtcdGetService(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) service, err := registry.GetService("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -710,14 +710,14 @@ func TestEtcdGetService(t *testing.T) { } func TestEtcdGetServiceNotFound(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.Data["/registry/services/specs/foo"] = tools.EtcdResponseWithError{ R: &etcd.Response{ Node: nil, }, E: tools.EtcdErrorNotFound, } - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) _, err := registry.GetService("foo") if err == nil { t.Errorf("Unexpected non-error.") @@ -725,8 +725,8 @@ func TestEtcdGetServiceNotFound(t *testing.T) { } func TestEtcdDeleteService(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + fakeClient := tools.NewFakeEtcdClient(t) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) err := registry.DeleteService("foo") if err != nil { t.Errorf("unexpected error: %v", err) @@ -746,11 +746,11 @@ func TestEtcdDeleteService(t *testing.T) { } func TestEtcdUpdateService(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true resp, _ := fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0) - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) testService := api.Service{ JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex}, Labels: map[string]string{ @@ -779,9 +779,9 @@ func TestEtcdUpdateService(t *testing.T) { } func TestEtcdUpdateEndpoints(t *testing.T) { - fakeClient := tools.MakeFakeEtcdClient(t) + fakeClient := tools.NewFakeEtcdClient(t) fakeClient.TestIndex = true - registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"}) + registry := NewTestEtcdRegistry(fakeClient, []string{"machine"}) endpoints := api.Endpoints{ JSONBase: api.JSONBase{ID: "foo"}, Endpoints: []string{"baz", "bar"}, diff --git a/pkg/registry/pod/storage.go b/pkg/registry/pod/storage.go index dc01c536f7..0168ae42e3 100644 --- a/pkg/registry/pod/storage.go +++ b/pkg/registry/pod/storage.go @@ -105,7 +105,7 @@ func (rs *RegistryStorage) Get(id string) (interface{}, error) { } if rs.podCache != nil || rs.podInfoGetter != nil { rs.fillPodInfo(pod) - pod.CurrentState.Status = makePodStatus(pod) + pod.CurrentState.Status = getPodStatus(pod) } pod.CurrentState.HostIP = getInstanceIP(rs.cloudProvider, pod.CurrentState.Host) return pod, err @@ -210,7 +210,7 @@ func getInstanceIP(cloud cloudprovider.Interface, host string) string { return addr.String() } -func makePodStatus(pod *api.Pod) api.PodStatus { +func getPodStatus(pod *api.Pod) api.PodStatus { if pod.CurrentState.Info == nil || pod.CurrentState.Host == "" { return api.PodWaiting } diff --git a/pkg/registry/pod/storage_test.go b/pkg/registry/pod/storage_test.go index 6f1dd4209e..8c4e81f72d 100644 --- a/pkg/registry/pod/storage_test.go +++ b/pkg/registry/pod/storage_test.go @@ -263,7 +263,7 @@ func TestMakePodStatus(t *testing.T) { Host: "machine", } pod := &api.Pod{DesiredState: desiredState, CurrentState: currentState} - status := makePodStatus(pod) + status := getPodStatus(pod) if status != api.PodWaiting { t.Errorf("Expected 'Waiting', got '%s'", status) } @@ -290,7 +290,7 @@ func TestMakePodStatus(t *testing.T) { Host: "machine", }, } - status = makePodStatus(pod) + status = getPodStatus(pod) if status != api.PodRunning { t.Errorf("Expected 'Running', got '%s'", status) } @@ -306,7 +306,7 @@ func TestMakePodStatus(t *testing.T) { Host: "machine", }, } - status = makePodStatus(pod) + status = getPodStatus(pod) if status != api.PodTerminated { t.Errorf("Expected 'Terminated', got '%s'", status) } @@ -322,7 +322,7 @@ func TestMakePodStatus(t *testing.T) { Host: "machine", }, } - status = makePodStatus(pod) + status = getPodStatus(pod) if status != api.PodWaiting { t.Errorf("Expected 'Waiting', got '%s'", status) } @@ -337,7 +337,7 @@ func TestMakePodStatus(t *testing.T) { Host: "machine", }, } - status = makePodStatus(pod) + status = getPodStatus(pod) if status != api.PodWaiting { t.Errorf("Expected 'Waiting', got '%s'", status) } @@ -388,7 +388,7 @@ func TestCreatePod(t *testing.T) { storage := RegistryStorage{ registry: podRegistry, podPollPeriod: time.Millisecond * 100, - scheduler: scheduler.MakeRoundRobinScheduler(), + scheduler: scheduler.NewRoundRobinScheduler(), minionLister: minion.NewRegistry([]string{"machine"}), } desiredState := api.PodState{ diff --git a/pkg/scheduler/random.go b/pkg/scheduler/random.go index 6cf0e9057b..f01ac52e81 100644 --- a/pkg/scheduler/random.go +++ b/pkg/scheduler/random.go @@ -29,7 +29,7 @@ type RandomScheduler struct { randomLock sync.Mutex } -func MakeRandomScheduler(random *rand.Rand) Scheduler { +func NewRandomScheduler(random *rand.Rand) Scheduler { return &RandomScheduler{ random: random, } diff --git a/pkg/scheduler/random_test.go b/pkg/scheduler/random_test.go index 142b5f6436..92b4ae2d3b 100644 --- a/pkg/scheduler/random_test.go +++ b/pkg/scheduler/random_test.go @@ -27,7 +27,7 @@ func TestRandomScheduler(t *testing.T) { random := rand.New(rand.NewSource(0)) st := schedulerTester{ t: t, - scheduler: MakeRandomScheduler(random), + scheduler: NewRandomScheduler(random), minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"}, } st.expectSuccess(api.Pod{}) diff --git a/pkg/scheduler/randomfit_test.go b/pkg/scheduler/randomfit_test.go index 642179249e..8b139cf1d3 100644 --- a/pkg/scheduler/randomfit_test.go +++ b/pkg/scheduler/randomfit_test.go @@ -36,7 +36,7 @@ func TestRandomFitSchedulerNothingScheduled(t *testing.T) { func TestRandomFitSchedulerFirstScheduled(t *testing.T) { fakeRegistry := FakePodLister{ - makePod("m1", 8080), + newPod("m1", 8080), } r := rand.New(rand.NewSource(0)) st := schedulerTester{ @@ -44,14 +44,14 @@ func TestRandomFitSchedulerFirstScheduled(t *testing.T) { scheduler: NewRandomFitScheduler(fakeRegistry, r), minionLister: FakeMinionLister{"m1", "m2", "m3"}, } - st.expectSchedule(makePod("", 8080), "m3") + st.expectSchedule(newPod("", 8080), "m3") } func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) { fakeRegistry := FakePodLister{ - makePod("m1", 80, 8080), - makePod("m2", 8081, 8082, 8083), - makePod("m3", 80, 443, 8085), + newPod("m1", 80, 8080), + newPod("m2", 8081, 8082, 8083), + newPod("m3", 80, 443, 8085), } r := rand.New(rand.NewSource(0)) st := schedulerTester{ @@ -59,14 +59,14 @@ func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) { scheduler: NewRandomFitScheduler(fakeRegistry, r), minionLister: FakeMinionLister{"m1", "m2", "m3"}, } - st.expectSchedule(makePod("", 8080, 8081), "m3") + st.expectSchedule(newPod("", 8080, 8081), "m3") } func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) { fakeRegistry := FakePodLister{ - makePod("m1", 8080), - makePod("m2", 8081), - makePod("m3", 8080), + newPod("m1", 8080), + newPod("m2", 8081), + newPod("m3", 8080), } r := rand.New(rand.NewSource(0)) st := schedulerTester{ @@ -74,5 +74,5 @@ func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) { scheduler: NewRandomFitScheduler(fakeRegistry, r), minionLister: FakeMinionLister{"m1", "m2", "m3"}, } - st.expectFailure(makePod("", 8080, 8081)) + st.expectFailure(newPod("", 8080, 8081)) } diff --git a/pkg/scheduler/roundrobin.go b/pkg/scheduler/roundrobin.go index 02ad62a088..26d3d1cd70 100644 --- a/pkg/scheduler/roundrobin.go +++ b/pkg/scheduler/roundrobin.go @@ -25,7 +25,7 @@ type RoundRobinScheduler struct { currentIndex int } -func MakeRoundRobinScheduler() Scheduler { +func NewRoundRobinScheduler() Scheduler { return &RoundRobinScheduler{ currentIndex: -1, } diff --git a/pkg/scheduler/roundrobin_test.go b/pkg/scheduler/roundrobin_test.go index 3ce410a1df..8fc9f74b70 100644 --- a/pkg/scheduler/roundrobin_test.go +++ b/pkg/scheduler/roundrobin_test.go @@ -25,7 +25,7 @@ import ( func TestRoundRobinScheduler(t *testing.T) { st := schedulerTester{ t: t, - scheduler: MakeRoundRobinScheduler(), + scheduler: NewRoundRobinScheduler(), minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"}, } st.expectSchedule(api.Pod{}, "m1") diff --git a/pkg/scheduler/scheduler_test.go b/pkg/scheduler/scheduler_test.go index bfec2dfc41..7aa6c0edc6 100644 --- a/pkg/scheduler/scheduler_test.go +++ b/pkg/scheduler/scheduler_test.go @@ -59,7 +59,7 @@ func (st *schedulerTester) expectFailure(pod api.Pod) { } } -func makePod(host string, hostPorts ...int) api.Pod { +func newPod(host string, hostPorts ...int) api.Pod { networkPorts := []api.Port{} for _, port := range hostPorts { networkPorts = append(networkPorts, api.Port{HostPort: port}) diff --git a/pkg/tools/etcd_tools_test.go b/pkg/tools/etcd_tools_test.go index 1fd98ac799..2b36bc8e52 100644 --- a/pkg/tools/etcd_tools_test.go +++ b/pkg/tools/etcd_tools_test.go @@ -65,7 +65,7 @@ func TestIsEtcdNotFound(t *testing.T) { } func TestExtractList(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ @@ -107,9 +107,9 @@ func TestExtractList(t *testing.T) { } func TestExtractObj(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) expect := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - fakeClient.Set("/some/key", util.MakeJSONString(expect), 0) + fakeClient.Set("/some/key", util.EncodeJSON(expect), 0) helper := EtcdHelper{fakeClient, codec, versioner} var got api.Pod err := helper.ExtractObj("/some/key", &got, false) @@ -122,7 +122,7 @@ func TestExtractObj(t *testing.T) { } func TestExtractObjNotFoundErr(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: nil, @@ -163,7 +163,7 @@ func TestExtractObjNotFoundErr(t *testing.T) { func TestSetObj(t *testing.T) { obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) helper := EtcdHelper{fakeClient, codec, versioner} err := helper.SetObj("/some/key", obj) if err != nil { @@ -182,7 +182,7 @@ func TestSetObj(t *testing.T) { func TestSetObjWithVersion(t *testing.T) { obj := api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}} - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ @@ -211,7 +211,7 @@ func TestSetObjWithVersion(t *testing.T) { func TestSetObjWithoutResourceVersioner(t *testing.T) { obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) helper := EtcdHelper{fakeClient, codec, nil} err := helper.SetObj("/some/key", obj) if err != nil { @@ -229,7 +229,7 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) { } func TestAtomicUpdate(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true codec := scheme helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()} @@ -284,7 +284,7 @@ func TestAtomicUpdate(t *testing.T) { } func TestAtomicUpdateNoChange(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true helper := EtcdHelper{fakeClient, scheme, api.NewJSONBaseResourceVersioner()} @@ -315,7 +315,7 @@ func TestAtomicUpdateNoChange(t *testing.T) { } func TestAtomicUpdate_CreateCollision(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.TestIndex = true codec := scheme helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()} @@ -486,7 +486,7 @@ func TestWatchInterpretation_ResponseBadData(t *testing.T) { } func TestWatch(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{} h := EtcdHelper{fakeClient, codec, versioner} @@ -572,7 +572,7 @@ func TestWatchFromZeroIndex(t *testing.T) { } for k, testCase := range testCases { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = testCase.Response h := EtcdHelper{fakeClient, codec, versioner} @@ -609,7 +609,7 @@ func TestWatchFromZeroIndex(t *testing.T) { func TestWatchListFromZeroIndex(t *testing.T) { pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}} - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: &etcd.Node{ @@ -662,7 +662,7 @@ func TestWatchListFromZeroIndex(t *testing.T) { } func TestWatchFromNotFound(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: nil, @@ -688,7 +688,7 @@ func TestWatchFromNotFound(t *testing.T) { } func TestWatchFromOtherError(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) fakeClient.Data["/some/key"] = EtcdResponseWithError{ R: &etcd.Response{ Node: nil, @@ -720,7 +720,7 @@ func TestWatchFromOtherError(t *testing.T) { } func TestWatchPurposefulShutdown(t *testing.T) { - fakeClient := MakeFakeEtcdClient(t) + fakeClient := NewFakeEtcdClient(t) h := EtcdHelper{fakeClient, codec, versioner} fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{} diff --git a/pkg/tools/fake_etcd_client.go b/pkg/tools/fake_etcd_client.go index afd96fa4fc..96293a2670 100644 --- a/pkg/tools/fake_etcd_client.go +++ b/pkg/tools/fake_etcd_client.go @@ -59,7 +59,7 @@ type FakeEtcdClient struct { WatchStop chan<- bool } -func MakeFakeEtcdClient(t TestLogger) *FakeEtcdClient { +func NewFakeEtcdClient(t TestLogger) *FakeEtcdClient { ret := &FakeEtcdClient{ t: t, expectNotFoundGetSet: map[string]struct{}{}, diff --git a/pkg/util/util.go b/pkg/util/util.go index 27ab57eb92..1a670072e0 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -59,8 +59,8 @@ func Forever(f func(), period time.Duration) { } } -// MakeJSONString returns obj marshalled as a JSON string, ignoring any errors. -func MakeJSONString(obj interface{}) string { +// EncodeJSON returns obj marshalled as a JSON string, ignoring any errors. +func EncodeJSON(obj interface{}) string { data, _ := json.Marshal(obj) return string(data) } @@ -83,13 +83,13 @@ const ( IntstrString // The IntOrString holds a string. ) -// MakeIntOrStringFromInt creates an IntOrString object with an int value. -func MakeIntOrStringFromInt(val int) IntOrString { +// NewIntOrStringFromInt creates an IntOrString object with an int value. +func NewIntOrStringFromInt(val int) IntOrString { return IntOrString{Kind: IntstrInt, IntVal: val} } -// MakeIntOrStringFromInt creates an IntOrString object with a string value. -func MakeIntOrStringFromString(val string) IntOrString { +// NewIntOrStringFromInt creates an IntOrString object with a string value. +func NewIntOrStringFromString(val string) IntOrString { return IntOrString{Kind: IntstrString, StrVal: val} } diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 43445af8a7..210ebb0b92 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -34,7 +34,7 @@ type FakePod struct { Str string } -func TestMakeJSONString(t *testing.T) { +func TestEncodeJSON(t *testing.T) { pod := FakePod{ FakeJSONBase: FakeJSONBase{ID: "foo"}, Labels: map[string]string{ @@ -45,7 +45,7 @@ func TestMakeJSONString(t *testing.T) { Str: "a string", } - body := MakeJSONString(pod) + body := EncodeJSON(pod) expectedBody, err := json.Marshal(pod) if err != nil { @@ -72,15 +72,15 @@ func TestHandleCrash(t *testing.T) { } } -func TestMakeIntOrStringFromInt(t *testing.T) { - i := MakeIntOrStringFromInt(93) +func TestNewIntOrStringFromInt(t *testing.T) { + i := NewIntOrStringFromInt(93) if i.Kind != IntstrInt || i.IntVal != 93 { t.Errorf("Expected IntVal=93, got %+v", i) } } -func TestMakeIntOrStringFromString(t *testing.T) { - i := MakeIntOrStringFromString("76") +func TestNewIntOrStringFromString(t *testing.T) { + i := NewIntOrStringFromString("76") if i.Kind != IntstrString || i.StrVal != "76" { t.Errorf("Expected StrVal=\"76\", got %+v", i) }