mirror of https://github.com/k3s-io/k3s
Merge pull request #984 from thockin/make_vs_new
Rename a bunch of "Make" functions to "New"pull/6/head
commit
8f5dd8cf63
|
@ -46,7 +46,7 @@ func main() {
|
||||||
glog.Fatal("usage: controller-manager -master <master>")
|
glog.Fatal("usage: controller-manager -master <master>")
|
||||||
}
|
}
|
||||||
|
|
||||||
controllerManager := controller.MakeReplicationManager(
|
controllerManager := controller.NewReplicationManager(
|
||||||
client.New("http://"+*master, nil))
|
client.New("http://"+*master, nil))
|
||||||
|
|
||||||
controllerManager.Run(10 * time.Second)
|
controllerManager.Run(10 * time.Second)
|
||||||
|
|
|
@ -106,7 +106,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
|
||||||
storage, codec := m.API_v1beta1()
|
storage, codec := m.API_v1beta1()
|
||||||
handler.delegate = apiserver.Handle(storage, codec, "/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
|
// Prove that controllerManager's watch works by making it not sync until after this
|
||||||
// test is over. (Hopefully we don't take 10 minutes!)
|
// test is over. (Hopefully we don't take 10 minutes!)
|
||||||
|
|
|
@ -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())
|
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(
|
httplog.StatusIsNot(
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
http.StatusAccepted,
|
http.StatusAccepted,
|
||||||
|
|
|
@ -72,8 +72,8 @@ func (r RealPodControl) deletePod(podID string) error {
|
||||||
return r.kubeClient.DeletePod(podID)
|
return r.kubeClient.DeletePod(podID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeReplicationManager creates a new ReplicationManager.
|
// NewReplicationManager creates a new ReplicationManager.
|
||||||
func MakeReplicationManager(kubeClient client.Interface) *ReplicationManager {
|
func NewReplicationManager(kubeClient client.Interface) *ReplicationManager {
|
||||||
rm := &ReplicationManager{
|
rm := &ReplicationManager{
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
podControl: RealPodControl{
|
podControl: RealPodControl{
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (f *FakePodControl) deletePod(podID string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeReplicationController(replicas int) api.ReplicationController {
|
func newReplicationController(replicas int) api.ReplicationController {
|
||||||
return api.ReplicationController{
|
return api.ReplicationController{
|
||||||
DesiredState: api.ReplicationControllerState{
|
DesiredState: api.ReplicationControllerState{
|
||||||
Replicas: replicas,
|
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{}
|
pods := []api.Pod{}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
pods = append(pods, api.Pod{
|
pods = append(pods, api.Pod{
|
||||||
|
@ -108,7 +108,7 @@ func validateSyncReplication(t *testing.T, fakePodControl *FakePodControl, expec
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncReplicationControllerDoesNothing(t *testing.T) {
|
func TestSyncReplicationControllerDoesNothing(t *testing.T) {
|
||||||
body, _ := api.Encode(makePodList(2))
|
body, _ := api.Encode(newPodList(2))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -118,17 +118,17 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
|
||||||
|
|
||||||
fakePodControl := FakePodControl{}
|
fakePodControl := FakePodControl{}
|
||||||
|
|
||||||
manager := MakeReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
manager.podControl = &fakePodControl
|
manager.podControl = &fakePodControl
|
||||||
|
|
||||||
controllerSpec := makeReplicationController(2)
|
controllerSpec := newReplicationController(2)
|
||||||
|
|
||||||
manager.syncReplicationController(controllerSpec)
|
manager.syncReplicationController(controllerSpec)
|
||||||
validateSyncReplication(t, &fakePodControl, 0, 0)
|
validateSyncReplication(t, &fakePodControl, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncReplicationControllerDeletes(t *testing.T) {
|
func TestSyncReplicationControllerDeletes(t *testing.T) {
|
||||||
body, _ := api.Encode(makePodList(2))
|
body, _ := api.Encode(newPodList(2))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -138,17 +138,17 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
|
||||||
|
|
||||||
fakePodControl := FakePodControl{}
|
fakePodControl := FakePodControl{}
|
||||||
|
|
||||||
manager := MakeReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
manager.podControl = &fakePodControl
|
manager.podControl = &fakePodControl
|
||||||
|
|
||||||
controllerSpec := makeReplicationController(1)
|
controllerSpec := newReplicationController(1)
|
||||||
|
|
||||||
manager.syncReplicationController(controllerSpec)
|
manager.syncReplicationController(controllerSpec)
|
||||||
validateSyncReplication(t, &fakePodControl, 0, 1)
|
validateSyncReplication(t, &fakePodControl, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncReplicationControllerCreates(t *testing.T) {
|
func TestSyncReplicationControllerCreates(t *testing.T) {
|
||||||
body, _ := api.Encode(makePodList(0))
|
body, _ := api.Encode(newPodList(0))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -158,10 +158,10 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
|
||||||
|
|
||||||
fakePodControl := FakePodControl{}
|
fakePodControl := FakePodControl{}
|
||||||
|
|
||||||
manager := MakeReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
manager.podControl = &fakePodControl
|
manager.podControl = &fakePodControl
|
||||||
|
|
||||||
controllerSpec := makeReplicationController(2)
|
controllerSpec := newReplicationController(2)
|
||||||
|
|
||||||
manager.syncReplicationController(controllerSpec)
|
manager.syncReplicationController(controllerSpec)
|
||||||
validateSyncReplication(t, &fakePodControl, 2, 0)
|
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{
|
fakeEtcd.Data["/registry/controllers"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
Nodes: []*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)
|
testServer := httptest.NewServer(mux)
|
||||||
client := client.New(testServer.URL, nil)
|
client := client.New(testServer.URL, nil)
|
||||||
manager := MakeReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
fakePodControl := FakePodControl{}
|
fakePodControl := FakePodControl{}
|
||||||
manager.podControl = &fakePodControl
|
manager.podControl = &fakePodControl
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ func (fw FakeWatcher) WatchReplicationControllers(l, f labels.Selector, rv uint6
|
||||||
|
|
||||||
func TestWatchControllers(t *testing.T) {
|
func TestWatchControllers(t *testing.T) {
|
||||||
client := FakeWatcher{watch.NewFake(), &client.Fake{}}
|
client := FakeWatcher{watch.NewFake(), &client.Fake{}}
|
||||||
manager := MakeReplicationManager(client)
|
manager := NewReplicationManager(client)
|
||||||
var testControllerSpec api.ReplicationController
|
var testControllerSpec api.ReplicationController
|
||||||
received := make(chan struct{})
|
received := make(chan struct{})
|
||||||
manager.syncHandler = func(controllerSpec api.ReplicationController) error {
|
manager.syncHandler = func(controllerSpec api.ReplicationController) error {
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
func TestEtcdMasterOther(t *testing.T) {
|
func TestEtcdMasterOther(t *testing.T) {
|
||||||
path := "foo"
|
path := "foo"
|
||||||
etcd := tools.MakeFakeEtcdClient(t)
|
etcd := tools.NewFakeEtcdClient(t)
|
||||||
etcd.Set(path, "baz", 0)
|
etcd.Set(path, "baz", 0)
|
||||||
master := NewEtcdMasterElector(etcd)
|
master := NewEtcdMasterElector(etcd)
|
||||||
w := master.Elect(path, "bar")
|
w := master.Elect(path, "bar")
|
||||||
|
@ -39,7 +39,7 @@ func TestEtcdMasterOther(t *testing.T) {
|
||||||
|
|
||||||
func TestEtcdMasterNoOther(t *testing.T) {
|
func TestEtcdMasterNoOther(t *testing.T) {
|
||||||
path := "foo"
|
path := "foo"
|
||||||
e := tools.MakeFakeEtcdClient(t)
|
e := tools.NewFakeEtcdClient(t)
|
||||||
e.TestIndex = true
|
e.TestIndex = true
|
||||||
e.Data["foo"] = tools.EtcdResponseWithError{
|
e.Data["foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -60,7 +60,7 @@ func TestEtcdMasterNoOther(t *testing.T) {
|
||||||
|
|
||||||
func TestEtcdMasterNoOtherThenConflict(t *testing.T) {
|
func TestEtcdMasterNoOtherThenConflict(t *testing.T) {
|
||||||
path := "foo"
|
path := "foo"
|
||||||
e := tools.MakeFakeEtcdClient(t)
|
e := tools.NewFakeEtcdClient(t)
|
||||||
e.TestIndex = true
|
e.TestIndex = true
|
||||||
// Ok, so we set up a chain of responses from etcd:
|
// Ok, so we set up a chain of responses from etcd:
|
||||||
// 1) Nothing there
|
// 1) Nothing there
|
||||||
|
|
|
@ -60,7 +60,7 @@ func TestHealthChecker(t *testing.T) {
|
||||||
container := api.Container{
|
container := api.Container{
|
||||||
LivenessProbe: &api.LivenessProbe{
|
LivenessProbe: &api.LivenessProbe{
|
||||||
HTTPGet: &api.HTTPGetProbe{
|
HTTPGet: &api.HTTPGetProbe{
|
||||||
Port: util.MakeIntOrStringFromString(port),
|
Port: util.NewIntOrStringFromString(port),
|
||||||
Path: "/foo/bar",
|
Path: "/foo/bar",
|
||||||
Host: host,
|
Host: host,
|
||||||
},
|
},
|
||||||
|
@ -132,7 +132,7 @@ func TestMuxHealthChecker(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
container.LivenessProbe.Type = tt.probeType
|
container.LivenessProbe.Type = tt.probeType
|
||||||
container.LivenessProbe.HTTPGet.Port = util.MakeIntOrStringFromString(port)
|
container.LivenessProbe.HTTPGet.Port = util.NewIntOrStringFromString(port)
|
||||||
container.LivenessProbe.HTTPGet.Host = host
|
container.LivenessProbe.HTTPGet.Host = host
|
||||||
health, err := mc.HealthCheck("test", api.PodState{}, container)
|
health, err := mc.HealthCheck("test", api.PodState{}, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,14 +35,14 @@ func TestGetURLParts(t *testing.T) {
|
||||||
port int
|
port int
|
||||||
path string
|
path string
|
||||||
}{
|
}{
|
||||||
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromInt(-1), Path: ""}, false, "", -1, ""},
|
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromInt(-1), Path: ""}, false, "", -1, ""},
|
||||||
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString(""), Path: ""}, false, "", -1, ""},
|
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString(""), Path: ""}, false, "", -1, ""},
|
||||||
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("-1"), Path: ""}, false, "", -1, ""},
|
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("-1"), Path: ""}, false, "", -1, ""},
|
||||||
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("not-found"), Path: ""}, false, "", -1, ""},
|
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("not-found"), Path: ""}, false, "", -1, ""},
|
||||||
{&api.HTTPGetProbe{Host: "", Port: util.MakeIntOrStringFromString("found"), Path: ""}, true, "127.0.0.1", 93, ""},
|
{&api.HTTPGetProbe{Host: "", Port: util.NewIntOrStringFromString("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.NewIntOrStringFromInt(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: "", Port: util.NewIntOrStringFromString("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: "hostname", Port: util.NewIntOrStringFromInt(76), Path: "path"}, true, "hostname", 76, "path"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
@ -122,7 +122,7 @@ func TestHTTPHealthChecker(t *testing.T) {
|
||||||
}
|
}
|
||||||
params := container.LivenessProbe.HTTPGet
|
params := container.LivenessProbe.HTTPGet
|
||||||
if params != nil {
|
if params != nil {
|
||||||
params.Port = util.MakeIntOrStringFromString(port)
|
params.Port = util.NewIntOrStringFromString(port)
|
||||||
params.Host = host
|
params.Host = host
|
||||||
}
|
}
|
||||||
health, err := hc.HealthCheck("test", api.PodState{PodIP: host}, container)
|
health, err := hc.HealthCheck("test", api.PodState{PodIP: host}, container)
|
||||||
|
|
|
@ -34,13 +34,13 @@ func TestGetTCPAddrParts(t *testing.T) {
|
||||||
host string
|
host string
|
||||||
port int
|
port int
|
||||||
}{
|
}{
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromInt(-1)}, false, "", -1},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromInt(-1)}, false, "", -1},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("")}, false, "", -1},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("")}, false, "", -1},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("-1")}, false, "", -1},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("-1")}, false, "", -1},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("not-found")}, false, "", -1},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("not-found")}, false, "", -1},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("found")}, true, "1.2.3.4", 93},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("found")}, true, "1.2.3.4", 93},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromInt(76)}, true, "1.2.3.4", 76},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromInt(76)}, true, "1.2.3.4", 76},
|
||||||
{&api.TCPSocketProbe{Port: util.MakeIntOrStringFromString("118")}, true, "1.2.3.4", 118},
|
{&api.TCPSocketProbe{Port: util.NewIntOrStringFromString("118")}, true, "1.2.3.4", 118},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
@ -100,7 +100,7 @@ func TestTcpHealthChecker(t *testing.T) {
|
||||||
}
|
}
|
||||||
params := container.LivenessProbe.TCPSocket
|
params := container.LivenessProbe.TCPSocket
|
||||||
if params != nil && test.expectedStatus == Healthy {
|
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)
|
status, err := checker.HealthCheck("test", api.PodState{PodIP: host}, container)
|
||||||
if status != test.expectedStatus {
|
if status != test.expectedStatus {
|
||||||
|
|
|
@ -32,7 +32,7 @@ import (
|
||||||
// Intended to wrap calls to your ServeMux.
|
// Intended to wrap calls to your ServeMux.
|
||||||
func Handler(delegate http.Handler, pred StacktracePred) http.Handler {
|
func Handler(delegate http.Handler, pred StacktracePred) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
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)
|
delegate.ServeHTTP(w, req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,11 @@ func DefaultStacktracePred(status int) bool {
|
||||||
return status < http.StatusOK || status >= http.StatusBadRequest
|
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:
|
// 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!)
|
// (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.
|
// through the logger.
|
||||||
//
|
//
|
||||||
// Use LogOf(w).Addf(...) to log something along with the response result.
|
// 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 {
|
if _, ok := (*w).(*respLogger); ok {
|
||||||
// Don't double-wrap!
|
// Don't double-wrap!
|
||||||
panic("multiple MakeLogged calls!")
|
panic("multiple NewLogged calls!")
|
||||||
}
|
}
|
||||||
rl := &respLogger{
|
rl := &respLogger{
|
||||||
startTime: time.Now(),
|
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,
|
// 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 {
|
func LogOf(w http.ResponseWriter) *respLogger {
|
||||||
if rl, ok := w.(*respLogger); ok {
|
if rl, ok := w.(*respLogger); ok {
|
||||||
return rl
|
return rl
|
||||||
|
|
|
@ -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)
|
req, err := http.NewRequest("GET", "http://example.com", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
MakeLogged(req, &w)
|
NewLogged(req, &w)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r == nil {
|
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()
|
w := httptest.NewRecorder()
|
||||||
handler(w, req)
|
handler(w, req)
|
||||||
|
@ -93,7 +93,7 @@ func TestLogOf(t *testing.T) {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
var want *respLogger
|
var want *respLogger
|
||||||
if makeLogger {
|
if makeLogger {
|
||||||
want = MakeLogged(req, &w)
|
want = NewLogged(req, &w)
|
||||||
} else {
|
} else {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r == nil {
|
if r := recover(); r == nil {
|
||||||
|
@ -121,7 +121,7 @@ func TestUnlogged(t *testing.T) {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
want := w
|
want := w
|
||||||
if makeLogger {
|
if makeLogger {
|
||||||
MakeLogged(req, &w)
|
NewLogged(req, &w)
|
||||||
}
|
}
|
||||||
got := Unlogged(w)
|
got := Unlogged(w)
|
||||||
if want != got {
|
if want != got {
|
||||||
|
|
|
@ -129,7 +129,7 @@ func ResizeController(name string, replicas int, client client.Interface) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makePorts(spec string) []api.Port {
|
func portsFromString(spec string) []api.Port {
|
||||||
parts := strings.Split(spec, ",")
|
parts := strings.Split(spec, ",")
|
||||||
var result []api.Port
|
var result []api.Port
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
|
@ -172,7 +172,7 @@ func RunController(image, name string, replicas int, client client.Interface, po
|
||||||
{
|
{
|
||||||
Name: strings.ToLower(name),
|
Name: strings.ToLower(name),
|
||||||
Image: image,
|
Image: image,
|
||||||
Ports: makePorts(portSpec),
|
Ports: portsFromString(portSpec),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -233,7 +233,7 @@ func TestLoadAuthInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakePorts(t *testing.T) {
|
func TestMakePorts(t *testing.T) {
|
||||||
var makePortsTests = []struct {
|
var testCases = []struct {
|
||||||
spec string
|
spec string
|
||||||
ports []api.Port
|
ports []api.Port
|
||||||
}{
|
}{
|
||||||
|
@ -246,8 +246,8 @@ func TestMakePorts(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range makePortsTests {
|
for _, tt := range testCases {
|
||||||
ports := makePorts(tt.spec)
|
ports := portsFromString(tt.spec)
|
||||||
if !reflect.DeepEqual(ports, tt.ports) {
|
if !reflect.DeepEqual(ports, tt.ports) {
|
||||||
t.Errorf("Expected %#v, got %#v", tt.ports, ports)
|
t.Errorf("Expected %#v, got %#v", tt.ports, ports)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ type ProxyServer struct {
|
||||||
Client *client.Client
|
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)))
|
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),
|
Client: client.New(host, auth),
|
||||||
}
|
}
|
||||||
http.Handle("/api/", server)
|
http.Handle("/api/", server)
|
||||||
http.Handle("/static/", makeFileHandler("/static/", filebase))
|
http.Handle("/static/", newFileHandler("/static/", filebase))
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestFileServing(t *testing.T) {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
prefix := "/foo/"
|
prefix := "/foo/"
|
||||||
handler := makeFileHandler(prefix, dir)
|
handler := newFileHandler(prefix, dir)
|
||||||
server := httptest.NewServer(handler)
|
server := httptest.NewServer(handler)
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
req, err := http.NewRequest("GET", server.URL+prefix+"test.txt", nil)
|
req, err := http.NewRequest("GET", server.URL+prefix+"test.txt", nil)
|
||||||
|
|
|
@ -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.
|
// 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) {
|
func TestGetEtcdData(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{})
|
ch := make(chan interface{})
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -57,7 +57,7 @@ func TestGetEtcdData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEtcdNoData(t *testing.T) {
|
func TestGetEtcdNoData(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
|
@ -72,7 +72,7 @@ func TestGetEtcdNoData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEtcd(t *testing.T) {
|
func TestGetEtcd(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
manifest := api.ContainerManifest{ID: "foo", Version: "v1beta1", Containers: []api.Container{{Name: "1", Image: "foo"}}}
|
manifest := api.ContainerManifest{ID: "foo", Version: "v1beta1", Containers: []api.Container{{Name: "1", Image: "foo"}}}
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
|
@ -107,7 +107,7 @@ func TestGetEtcd(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchEtcd(t *testing.T) {
|
func TestWatchEtcd(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -134,7 +134,7 @@ func TestWatchEtcd(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEtcdNotFound(t *testing.T) {
|
func TestGetEtcdNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
|
@ -149,7 +149,7 @@ func TestGetEtcdNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetEtcdError(t *testing.T) {
|
func TestGetEtcdError(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
ch := make(chan interface{}, 1)
|
ch := make(chan interface{}, 1)
|
||||||
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/hosts/machine/kubelet"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
|
|
|
@ -36,8 +36,8 @@ import (
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeTestKubelet(t *testing.T) (*Kubelet, *tools.FakeEtcdClient, *FakeDockerClient) {
|
func newTestKubelet(t *testing.T) (*Kubelet, *tools.FakeEtcdClient, *FakeDockerClient) {
|
||||||
fakeEtcdClient := tools.MakeFakeEtcdClient(t)
|
fakeEtcdClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeDocker := &FakeDockerClient{
|
fakeDocker := &FakeDockerClient{
|
||||||
err: nil,
|
err: nil,
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func TestContainerManifestNaming(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainerID(t *testing.T) {
|
func TestGetContainerID(t *testing.T) {
|
||||||
_, _, fakeDocker := makeTestKubelet(t)
|
_, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
ID: "foobar",
|
ID: "foobar",
|
||||||
|
@ -164,7 +164,7 @@ func TestKillContainerWithError(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
kubelet, _, _ := makeTestKubelet(t)
|
kubelet, _, _ := newTestKubelet(t)
|
||||||
kubelet.dockerClient = fakeDocker
|
kubelet.dockerClient = fakeDocker
|
||||||
err := kubelet.killContainer(&fakeDocker.containerList[0])
|
err := kubelet.killContainer(&fakeDocker.containerList[0])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -174,7 +174,7 @@ func TestKillContainerWithError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKillContainer(t *testing.T) {
|
func TestKillContainer(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
ID: "1234",
|
ID: "1234",
|
||||||
|
@ -223,7 +223,7 @@ func (cr *channelReader) GetList() [][]Pod {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodsDoesNothing(t *testing.T) {
|
func TestSyncPodsDoesNothing(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
container := api.Container{Name: "bar"}
|
container := api.Container{Name: "bar"}
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
|
@ -278,7 +278,7 @@ func matchString(t *testing.T, pattern, str string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodsCreatesNetAndContainer(t *testing.T) {
|
func TestSyncPodsCreatesNetAndContainer(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{}
|
fakeDocker.containerList = []docker.APIContainers{}
|
||||||
err := kubelet.SyncPods([]Pod{
|
err := kubelet.SyncPods([]Pod{
|
||||||
{
|
{
|
||||||
|
@ -310,7 +310,7 @@ func TestSyncPodsCreatesNetAndContainer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodsWithNetCreatesContainer(t *testing.T) {
|
func TestSyncPodsWithNetCreatesContainer(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
// network container
|
// network container
|
||||||
|
@ -347,7 +347,7 @@ func TestSyncPodsWithNetCreatesContainer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) {
|
func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
// format is k8s--<container-id>--<pod-fullname>
|
// format is k8s--<container-id>--<pod-fullname>
|
||||||
|
@ -388,7 +388,7 @@ func TestSyncPodsDeletesWithNoNetContainer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodsDeletes(t *testing.T) {
|
func TestSyncPodsDeletes(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
// the k8s prefix is required for the kubelet to manage the container
|
// 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) {
|
func TestSyncPodDeletesDuplicate(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
dockerContainers := DockerContainers{
|
dockerContainers := DockerContainers{
|
||||||
"1234": &docker.APIContainers{
|
"1234": &docker.APIContainers{
|
||||||
// the k8s prefix is required for the kubelet to manage the container
|
// 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) {
|
func TestSyncPodBadHash(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.healthChecker = &FalseHealthChecker{}
|
kubelet.healthChecker = &FalseHealthChecker{}
|
||||||
dockerContainers := DockerContainers{
|
dockerContainers := DockerContainers{
|
||||||
"1234": &docker.APIContainers{
|
"1234": &docker.APIContainers{
|
||||||
|
@ -520,7 +520,7 @@ func TestSyncPodBadHash(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncPodUnhealthy(t *testing.T) {
|
func TestSyncPodUnhealthy(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.healthChecker = &FalseHealthChecker{}
|
kubelet.healthChecker = &FalseHealthChecker{}
|
||||||
dockerContainers := DockerContainers{
|
dockerContainers := DockerContainers{
|
||||||
"1234": &docker.APIContainers{
|
"1234": &docker.APIContainers{
|
||||||
|
@ -567,7 +567,7 @@ func TestSyncPodUnhealthy(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventWriting(t *testing.T) {
|
func TestEventWriting(t *testing.T) {
|
||||||
kubelet, fakeEtcd, _ := makeTestKubelet(t)
|
kubelet, fakeEtcd, _ := newTestKubelet(t)
|
||||||
expectedEvent := api.Event{
|
expectedEvent := api.Event{
|
||||||
Event: "test",
|
Event: "test",
|
||||||
Container: &api.Container{
|
Container: &api.Container{
|
||||||
|
@ -600,7 +600,7 @@ func TestEventWriting(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEventWritingError(t *testing.T) {
|
func TestEventWritingError(t *testing.T) {
|
||||||
kubelet, fakeEtcd, _ := makeTestKubelet(t)
|
kubelet, fakeEtcd, _ := newTestKubelet(t)
|
||||||
fakeEtcd.Err = fmt.Errorf("test error")
|
fakeEtcd.Err = fmt.Errorf("test error")
|
||||||
err := kubelet.LogEvent(&api.Event{
|
err := kubelet.LogEvent(&api.Event{
|
||||||
Event: "test",
|
Event: "test",
|
||||||
|
@ -639,7 +639,7 @@ func TestMakeEnvVariables(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountExternalVolumes(t *testing.T) {
|
func TestMountExternalVolumes(t *testing.T) {
|
||||||
kubelet, _, _ := makeTestKubelet(t)
|
kubelet, _, _ := newTestKubelet(t)
|
||||||
manifest := api.ContainerManifest{
|
manifest := api.ContainerManifest{
|
||||||
Volumes: []api.Volume{
|
Volumes: []api.Volume{
|
||||||
{
|
{
|
||||||
|
@ -887,7 +887,7 @@ func TestGetContainerInfo(t *testing.T) {
|
||||||
cadvisorReq := getCadvisorContainerInfoRequest(req)
|
cadvisorReq := getCadvisorContainerInfoRequest(req)
|
||||||
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil)
|
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil)
|
||||||
|
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.cadvisorClient = mockCadvisor
|
kubelet.cadvisorClient = mockCadvisor
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
|
@ -958,7 +958,7 @@ func TestGetRooInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainerInfoWithoutCadvisor(t *testing.T) {
|
func TestGetContainerInfoWithoutCadvisor(t *testing.T) {
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
ID: "foobar",
|
ID: "foobar",
|
||||||
|
@ -995,7 +995,7 @@ func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) {
|
||||||
expectedErr := fmt.Errorf("some error")
|
expectedErr := fmt.Errorf("some error")
|
||||||
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, expectedErr)
|
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, expectedErr)
|
||||||
|
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.cadvisorClient = mockCadvisor
|
kubelet.cadvisorClient = mockCadvisor
|
||||||
fakeDocker.containerList = []docker.APIContainers{
|
fakeDocker.containerList = []docker.APIContainers{
|
||||||
{
|
{
|
||||||
|
@ -1023,7 +1023,7 @@ func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) {
|
||||||
func TestGetContainerInfoOnNonExistContainer(t *testing.T) {
|
func TestGetContainerInfoOnNonExistContainer(t *testing.T) {
|
||||||
mockCadvisor := &mockCadvisorClient{}
|
mockCadvisor := &mockCadvisorClient{}
|
||||||
|
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.cadvisorClient = mockCadvisor
|
kubelet.cadvisorClient = mockCadvisor
|
||||||
fakeDocker.containerList = []docker.APIContainers{}
|
fakeDocker.containerList = []docker.APIContainers{}
|
||||||
|
|
||||||
|
@ -1048,7 +1048,7 @@ func (f *fakeContainerCommandRunner) RunInContainer(id string, cmd []string) ([]
|
||||||
|
|
||||||
func TestRunInContainerNoSuchPod(t *testing.T) {
|
func TestRunInContainerNoSuchPod(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
fakeDocker.containerList = []docker.APIContainers{}
|
fakeDocker.containerList = []docker.APIContainers{}
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
|
@ -1069,7 +1069,7 @@ func TestRunInContainerNoSuchPod(t *testing.T) {
|
||||||
|
|
||||||
func TestRunInContainer(t *testing.T) {
|
func TestRunInContainer(t *testing.T) {
|
||||||
fakeCommandRunner := fakeContainerCommandRunner{}
|
fakeCommandRunner := fakeContainerCommandRunner{}
|
||||||
kubelet, _, fakeDocker := makeTestKubelet(t)
|
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||||
kubelet.runner = &fakeCommandRunner
|
kubelet.runner = &fakeCommandRunner
|
||||||
|
|
||||||
containerID := "abc1234"
|
containerID := "abc1234"
|
||||||
|
|
|
@ -206,7 +206,7 @@ func (s *Server) handleSpec(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
// ServeHTTP responds to HTTP requests on the Kubelet
|
// ServeHTTP responds to HTTP requests on the Kubelet
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
defer httplog.MakeLogged(req, &w).StacktraceWhen(
|
defer httplog.NewLogged(req, &w).StacktraceWhen(
|
||||||
httplog.StatusIsNot(
|
httplog.StatusIsNot(
|
||||||
http.StatusOK,
|
http.StatusOK,
|
||||||
http.StatusNotFound,
|
http.StatusNotFound,
|
||||||
|
|
|
@ -70,7 +70,7 @@ type serverTestFramework struct {
|
||||||
testHTTPServer *httptest.Server
|
testHTTPServer *httptest.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeServerTest() *serverTestFramework {
|
func newServerTest() *serverTestFramework {
|
||||||
fw := &serverTestFramework{
|
fw := &serverTestFramework{
|
||||||
updateChan: make(chan interface{}),
|
updateChan: make(chan interface{}),
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,11 @@ func readResp(resp *http.Response) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainer(t *testing.T) {
|
func TestContainer(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expected := []api.ContainerManifest{
|
expected := []api.ContainerManifest{
|
||||||
{ID: "test_manifest"},
|
{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)
|
resp, err := http.Post(fw.testHTTPServer.URL+"/container", "application/json", body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Post returned: %v", err)
|
t.Errorf("Post returned: %v", err)
|
||||||
|
@ -111,12 +111,12 @@ func TestContainer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainers(t *testing.T) {
|
func TestContainers(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expected := []api.ContainerManifest{
|
expected := []api.ContainerManifest{
|
||||||
{ID: "test_manifest_1"},
|
{ID: "test_manifest_1"},
|
||||||
{ID: "test_manifest_2"},
|
{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)
|
resp, err := http.Post(fw.testHTTPServer.URL+"/containers", "application/json", body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Post returned: %v", err)
|
t.Errorf("Post returned: %v", err)
|
||||||
|
@ -134,7 +134,7 @@ func TestContainers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPodInfo(t *testing.T) {
|
func TestPodInfo(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expected := api.PodInfo{"goodpod": docker.Container{ID: "myContainerID"}}
|
expected := api.PodInfo{"goodpod": docker.Container{ID: "myContainerID"}}
|
||||||
fw.fakeKubelet.infoFunc = func(name string) (api.PodInfo, error) {
|
fw.fakeKubelet.infoFunc = func(name string) (api.PodInfo, error) {
|
||||||
if name == "goodpod.etcd" {
|
if name == "goodpod.etcd" {
|
||||||
|
@ -160,7 +160,7 @@ func TestPodInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerInfo(t *testing.T) {
|
func TestContainerInfo(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.ContainerInfo{
|
expectedInfo := &info.ContainerInfo{
|
||||||
StatsPercentiles: &info.ContainerStatsPercentiles{
|
StatsPercentiles: &info.ContainerStatsPercentiles{
|
||||||
MaxMemoryUsage: 1024001,
|
MaxMemoryUsage: 1024001,
|
||||||
|
@ -201,7 +201,7 @@ func TestContainerInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRootInfo(t *testing.T) {
|
func TestRootInfo(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.ContainerInfo{
|
expectedInfo := &info.ContainerInfo{
|
||||||
StatsPercentiles: &info.ContainerStatsPercentiles{
|
StatsPercentiles: &info.ContainerStatsPercentiles{
|
||||||
MaxMemoryUsage: 1024001,
|
MaxMemoryUsage: 1024001,
|
||||||
|
@ -237,7 +237,7 @@ func TestRootInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMachineInfo(t *testing.T) {
|
func TestMachineInfo(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.MachineInfo{
|
expectedInfo := &info.MachineInfo{
|
||||||
NumCores: 4,
|
NumCores: 4,
|
||||||
MemoryCapacity: 1024,
|
MemoryCapacity: 1024,
|
||||||
|
@ -262,7 +262,7 @@ func TestMachineInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServeLogs(t *testing.T) {
|
func TestServeLogs(t *testing.T) {
|
||||||
fw := makeServerTest()
|
fw := newServerTest()
|
||||||
|
|
||||||
content := string(`<pre><a href="kubelet.log">kubelet.log</a><a href="google.log">google.log</a></pre>`)
|
content := string(`<pre><a href="kubelet.log">kubelet.log</a><a href="google.log">google.log</a></pre>`)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makePodList(count int) api.PodList {
|
func newPodList(count int) api.PodList {
|
||||||
pods := []api.Pod{}
|
pods := []api.Pod{}
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
pods = append(pods, api.Pod{
|
pods = append(pods, api.Pod{
|
||||||
|
@ -122,7 +122,7 @@ func TestFindPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncEndpointsEmpty(t *testing.T) {
|
func TestSyncEndpointsEmpty(t *testing.T) {
|
||||||
body, _ := json.Marshal(makePodList(0))
|
body, _ := json.Marshal(newPodList(0))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -139,7 +139,7 @@ func TestSyncEndpointsEmpty(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncEndpointsError(t *testing.T) {
|
func TestSyncEndpointsError(t *testing.T) {
|
||||||
body, _ := json.Marshal(makePodList(0))
|
body, _ := json.Marshal(newPodList(0))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
@ -157,7 +157,7 @@ func TestSyncEndpointsError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncEndpointsItems(t *testing.T) {
|
func TestSyncEndpointsItems(t *testing.T) {
|
||||||
body, _ := json.Marshal(makePodList(1))
|
body, _ := json.Marshal(newPodList(1))
|
||||||
fakeHandler := util.FakeHandler{
|
fakeHandler := util.FakeHandler{
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
ResponseBody: string(body),
|
ResponseBody: string(body),
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"github.com/coreos/go-etcd/etcd"
|
"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 := NewRegistry(client, minion.NewRegistry(machines))
|
||||||
registry.manifestFactory = &BasicManifestFactory{
|
registry.manifestFactory = &BasicManifestFactory{
|
||||||
serviceRegistry: ®istrytest.ServiceRegistry{},
|
serviceRegistry: ®istrytest.ServiceRegistry{},
|
||||||
|
@ -39,9 +39,9 @@ func MakeTestEtcdRegistry(client tools.EtcdClient, machines []string) *Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetPod(t *testing.T) {
|
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)
|
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")
|
pod, err := registry.GetPod("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -53,14 +53,14 @@ func TestEtcdGetPod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetPodNotFound(t *testing.T) {
|
func TestEtcdGetPodNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
},
|
},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
_, err := registry.GetPod("foo")
|
_, err := registry.GetPod("foo")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Unexpected non-error.")
|
t.Errorf("Unexpected non-error.")
|
||||||
|
@ -68,7 +68,7 @@ func TestEtcdGetPodNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreatePod(t *testing.T) {
|
func TestEtcdCreatePod(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -77,7 +77,7 @@ func TestEtcdCreatePod(t *testing.T) {
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
fakeClient.Set("/registry/hosts/machine/kubelet", api.EncodeOrDie(&api.ContainerManifestList{}), 0)
|
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{
|
err := registry.CreatePod("machine", api.Pod{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -122,7 +122,7 @@ func TestEtcdCreatePod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
|
func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
|
@ -131,7 +131,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreatePod("machine", api.Pod{
|
err := registry.CreatePod("machine", api.Pod{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -143,7 +143,7 @@ func TestEtcdCreatePodAlreadyExisting(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -157,7 +157,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: tools.EtcdErrorValueRequired,
|
E: tools.EtcdErrorValueRequired,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreatePod("machine", api.Pod{
|
err := registry.CreatePod("machine", api.Pod{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -176,7 +176,7 @@ func TestEtcdCreatePodWithContainersError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -190,7 +190,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreatePod("machine", api.Pod{
|
err := registry.CreatePod("machine", api.Pod{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -236,7 +236,7 @@ func TestEtcdCreatePodWithContainersNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
|
func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/pods/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -249,7 +249,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
|
||||||
{ID: "bar"},
|
{ID: "bar"},
|
||||||
},
|
},
|
||||||
}), 0)
|
}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreatePod("machine", api.Pod{
|
err := registry.CreatePod("machine", api.Pod{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -295,7 +295,7 @@ func TestEtcdCreatePodWithExistingContainers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDeletePod(t *testing.T) {
|
func TestEtcdDeletePod(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
|
|
||||||
key := "/registry/pods/foo"
|
key := "/registry/pods/foo"
|
||||||
|
@ -308,7 +308,7 @@ func TestEtcdDeletePod(t *testing.T) {
|
||||||
{ID: "foo"},
|
{ID: "foo"},
|
||||||
},
|
},
|
||||||
}), 0)
|
}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.DeletePod("foo")
|
err := registry.DeletePod("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -331,7 +331,7 @@ func TestEtcdDeletePod(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDeletePodMultipleContainers(t *testing.T) {
|
func TestEtcdDeletePodMultipleContainers(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
|
|
||||||
key := "/registry/pods/foo"
|
key := "/registry/pods/foo"
|
||||||
|
@ -345,7 +345,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
|
||||||
{ID: "bar"},
|
{ID: "bar"},
|
||||||
},
|
},
|
||||||
}), 0)
|
}), 0)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.DeletePod("foo")
|
err := registry.DeletePod("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -372,7 +372,7 @@ func TestEtcdDeletePodMultipleContainers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdEmptyListPods(t *testing.T) {
|
func TestEtcdEmptyListPods(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/pods"
|
key := "/registry/pods"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -382,7 +382,7 @@ func TestEtcdEmptyListPods(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
pods, err := registry.ListPods(labels.Everything())
|
pods, err := registry.ListPods(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -394,13 +394,13 @@ func TestEtcdEmptyListPods(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListPodsNotFound(t *testing.T) {
|
func TestEtcdListPodsNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/pods"
|
key := "/registry/pods"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
pods, err := registry.ListPods(labels.Everything())
|
pods, err := registry.ListPods(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -412,7 +412,7 @@ func TestEtcdListPodsNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListPods(t *testing.T) {
|
func TestEtcdListPods(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/pods"
|
key := "/registry/pods"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -435,7 +435,7 @@ func TestEtcdListPods(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
pods, err := registry.ListPods(labels.Everything())
|
pods, err := registry.ListPods(labels.Everything())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -451,13 +451,13 @@ func TestEtcdListPods(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListControllersNotFound(t *testing.T) {
|
func TestEtcdListControllersNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/controllers"
|
key := "/registry/controllers"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
controllers, err := registry.ListControllers()
|
controllers, err := registry.ListControllers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -469,13 +469,13 @@ func TestEtcdListControllersNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListServicesNotFound(t *testing.T) {
|
func TestEtcdListServicesNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/services/specs"
|
key := "/registry/services/specs"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{},
|
R: &etcd.Response{},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
services, err := registry.ListServices()
|
services, err := registry.ListServices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -487,7 +487,7 @@ func TestEtcdListServicesNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListControllers(t *testing.T) {
|
func TestEtcdListControllers(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/controllers"
|
key := "/registry/controllers"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -504,7 +504,7 @@ func TestEtcdListControllers(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
controllers, err := registry.ListControllers()
|
controllers, err := registry.ListControllers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -516,9 +516,9 @@ func TestEtcdListControllers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetController(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)
|
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")
|
ctrl, err := registry.GetController("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -530,14 +530,14 @@ func TestEtcdGetController(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetControllerNotFound(t *testing.T) {
|
func TestEtcdGetControllerNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/registry/controllers/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/controllers/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
},
|
},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
ctrl, err := registry.GetController("foo")
|
ctrl, err := registry.GetController("foo")
|
||||||
if ctrl != nil {
|
if ctrl != nil {
|
||||||
t.Errorf("Unexpected non-nil controller: %#v", ctrl)
|
t.Errorf("Unexpected non-nil controller: %#v", ctrl)
|
||||||
|
@ -548,8 +548,8 @@ func TestEtcdGetControllerNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDeleteController(t *testing.T) {
|
func TestEtcdDeleteController(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.DeleteController("foo")
|
err := registry.DeleteController("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -565,8 +565,8 @@ func TestEtcdDeleteController(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreateController(t *testing.T) {
|
func TestEtcdCreateController(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateController(api.ReplicationController{
|
err := registry.CreateController(api.ReplicationController{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -592,10 +592,10 @@ func TestEtcdCreateController(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreateControllerAlreadyExisting(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)
|
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{
|
err := registry.CreateController(api.ReplicationController{
|
||||||
JSONBase: api.JSONBase{
|
JSONBase: api.JSONBase{
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
|
@ -607,11 +607,11 @@ func TestEtcdCreateControllerAlreadyExisting(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdUpdateController(t *testing.T) {
|
func TestEtcdUpdateController(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
|
|
||||||
resp, _ := fakeClient.Set("/registry/controllers/foo", api.EncodeOrDie(api.ReplicationController{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
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{
|
err := registry.UpdateController(api.ReplicationController{
|
||||||
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex},
|
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex},
|
||||||
DesiredState: api.ReplicationControllerState{
|
DesiredState: api.ReplicationControllerState{
|
||||||
|
@ -629,7 +629,7 @@ func TestEtcdUpdateController(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdListServices(t *testing.T) {
|
func TestEtcdListServices(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
key := "/registry/services/specs"
|
key := "/registry/services/specs"
|
||||||
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
fakeClient.Data[key] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -646,7 +646,7 @@ func TestEtcdListServices(t *testing.T) {
|
||||||
},
|
},
|
||||||
E: nil,
|
E: nil,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
services, err := registry.ListServices()
|
services, err := registry.ListServices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -658,8 +658,8 @@ func TestEtcdListServices(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreateService(t *testing.T) {
|
func TestEtcdCreateService(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.CreateService(api.Service{
|
err := registry.CreateService(api.Service{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
})
|
})
|
||||||
|
@ -684,9 +684,9 @@ func TestEtcdCreateService(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdCreateServiceAlreadyExisting(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)
|
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{
|
err := registry.CreateService(api.Service{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
})
|
})
|
||||||
|
@ -696,9 +696,9 @@ func TestEtcdCreateServiceAlreadyExisting(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetService(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)
|
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")
|
service, err := registry.GetService("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -710,14 +710,14 @@ func TestEtcdGetService(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdGetServiceNotFound(t *testing.T) {
|
func TestEtcdGetServiceNotFound(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/registry/services/specs/foo"] = tools.EtcdResponseWithError{
|
fakeClient.Data["/registry/services/specs/foo"] = tools.EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
},
|
},
|
||||||
E: tools.EtcdErrorNotFound,
|
E: tools.EtcdErrorNotFound,
|
||||||
}
|
}
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
_, err := registry.GetService("foo")
|
_, err := registry.GetService("foo")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Unexpected non-error.")
|
t.Errorf("Unexpected non-error.")
|
||||||
|
@ -725,8 +725,8 @@ func TestEtcdGetServiceNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdDeleteService(t *testing.T) {
|
func TestEtcdDeleteService(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
err := registry.DeleteService("foo")
|
err := registry.DeleteService("foo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -746,11 +746,11 @@ func TestEtcdDeleteService(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdUpdateService(t *testing.T) {
|
func TestEtcdUpdateService(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
|
|
||||||
resp, _ := fakeClient.Set("/registry/services/specs/foo", api.EncodeOrDie(api.Service{JSONBase: api.JSONBase{ID: "foo"}}), 0)
|
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{
|
testService := api.Service{
|
||||||
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex},
|
JSONBase: api.JSONBase{ID: "foo", ResourceVersion: resp.Node.ModifiedIndex},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
|
@ -779,9 +779,9 @@ func TestEtcdUpdateService(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEtcdUpdateEndpoints(t *testing.T) {
|
func TestEtcdUpdateEndpoints(t *testing.T) {
|
||||||
fakeClient := tools.MakeFakeEtcdClient(t)
|
fakeClient := tools.NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
|
registry := NewTestEtcdRegistry(fakeClient, []string{"machine"})
|
||||||
endpoints := api.Endpoints{
|
endpoints := api.Endpoints{
|
||||||
JSONBase: api.JSONBase{ID: "foo"},
|
JSONBase: api.JSONBase{ID: "foo"},
|
||||||
Endpoints: []string{"baz", "bar"},
|
Endpoints: []string{"baz", "bar"},
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (rs *RegistryStorage) Get(id string) (interface{}, error) {
|
||||||
}
|
}
|
||||||
if rs.podCache != nil || rs.podInfoGetter != nil {
|
if rs.podCache != nil || rs.podInfoGetter != nil {
|
||||||
rs.fillPodInfo(pod)
|
rs.fillPodInfo(pod)
|
||||||
pod.CurrentState.Status = makePodStatus(pod)
|
pod.CurrentState.Status = getPodStatus(pod)
|
||||||
}
|
}
|
||||||
pod.CurrentState.HostIP = getInstanceIP(rs.cloudProvider, pod.CurrentState.Host)
|
pod.CurrentState.HostIP = getInstanceIP(rs.cloudProvider, pod.CurrentState.Host)
|
||||||
return pod, err
|
return pod, err
|
||||||
|
@ -210,7 +210,7 @@ func getInstanceIP(cloud cloudprovider.Interface, host string) string {
|
||||||
return addr.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 == "" {
|
if pod.CurrentState.Info == nil || pod.CurrentState.Host == "" {
|
||||||
return api.PodWaiting
|
return api.PodWaiting
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ func TestMakePodStatus(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
}
|
}
|
||||||
pod := &api.Pod{DesiredState: desiredState, CurrentState: currentState}
|
pod := &api.Pod{DesiredState: desiredState, CurrentState: currentState}
|
||||||
status := makePodStatus(pod)
|
status := getPodStatus(pod)
|
||||||
if status != api.PodWaiting {
|
if status != api.PodWaiting {
|
||||||
t.Errorf("Expected 'Waiting', got '%s'", status)
|
t.Errorf("Expected 'Waiting', got '%s'", status)
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ func TestMakePodStatus(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
status = makePodStatus(pod)
|
status = getPodStatus(pod)
|
||||||
if status != api.PodRunning {
|
if status != api.PodRunning {
|
||||||
t.Errorf("Expected 'Running', got '%s'", status)
|
t.Errorf("Expected 'Running', got '%s'", status)
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ func TestMakePodStatus(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
status = makePodStatus(pod)
|
status = getPodStatus(pod)
|
||||||
if status != api.PodTerminated {
|
if status != api.PodTerminated {
|
||||||
t.Errorf("Expected 'Terminated', got '%s'", status)
|
t.Errorf("Expected 'Terminated', got '%s'", status)
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ func TestMakePodStatus(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
status = makePodStatus(pod)
|
status = getPodStatus(pod)
|
||||||
if status != api.PodWaiting {
|
if status != api.PodWaiting {
|
||||||
t.Errorf("Expected 'Waiting', got '%s'", status)
|
t.Errorf("Expected 'Waiting', got '%s'", status)
|
||||||
}
|
}
|
||||||
|
@ -337,7 +337,7 @@ func TestMakePodStatus(t *testing.T) {
|
||||||
Host: "machine",
|
Host: "machine",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
status = makePodStatus(pod)
|
status = getPodStatus(pod)
|
||||||
if status != api.PodWaiting {
|
if status != api.PodWaiting {
|
||||||
t.Errorf("Expected 'Waiting', got '%s'", status)
|
t.Errorf("Expected 'Waiting', got '%s'", status)
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ func TestCreatePod(t *testing.T) {
|
||||||
storage := RegistryStorage{
|
storage := RegistryStorage{
|
||||||
registry: podRegistry,
|
registry: podRegistry,
|
||||||
podPollPeriod: time.Millisecond * 100,
|
podPollPeriod: time.Millisecond * 100,
|
||||||
scheduler: scheduler.MakeRoundRobinScheduler(),
|
scheduler: scheduler.NewRoundRobinScheduler(),
|
||||||
minionLister: minion.NewRegistry([]string{"machine"}),
|
minionLister: minion.NewRegistry([]string{"machine"}),
|
||||||
}
|
}
|
||||||
desiredState := api.PodState{
|
desiredState := api.PodState{
|
||||||
|
|
|
@ -29,7 +29,7 @@ type RandomScheduler struct {
|
||||||
randomLock sync.Mutex
|
randomLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeRandomScheduler(random *rand.Rand) Scheduler {
|
func NewRandomScheduler(random *rand.Rand) Scheduler {
|
||||||
return &RandomScheduler{
|
return &RandomScheduler{
|
||||||
random: random,
|
random: random,
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func TestRandomScheduler(t *testing.T) {
|
||||||
random := rand.New(rand.NewSource(0))
|
random := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeRandomScheduler(random),
|
scheduler: NewRandomScheduler(random),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"},
|
||||||
}
|
}
|
||||||
st.expectSuccess(api.Pod{})
|
st.expectSuccess(api.Pod{})
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestRandomFitSchedulerNothingScheduled(t *testing.T) {
|
||||||
|
|
||||||
func TestRandomFitSchedulerFirstScheduled(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduled(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 8080),
|
newPod("m1", 8080),
|
||||||
}
|
}
|
||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
|
@ -44,14 +44,14 @@ func TestRandomFitSchedulerFirstScheduled(t *testing.T) {
|
||||||
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(makePod("", 8080), "m3")
|
st.expectSchedule(newPod("", 8080), "m3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 80, 8080),
|
newPod("m1", 80, 8080),
|
||||||
makePod("m2", 8081, 8082, 8083),
|
newPod("m2", 8081, 8082, 8083),
|
||||||
makePod("m3", 80, 443, 8085),
|
newPod("m3", 80, 443, 8085),
|
||||||
}
|
}
|
||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
|
@ -59,14 +59,14 @@ func TestRandomFitSchedulerFirstScheduledComplicated(t *testing.T) {
|
||||||
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(makePod("", 8080, 8081), "m3")
|
st.expectSchedule(newPod("", 8080, 8081), "m3")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
||||||
fakeRegistry := FakePodLister{
|
fakeRegistry := FakePodLister{
|
||||||
makePod("m1", 8080),
|
newPod("m1", 8080),
|
||||||
makePod("m2", 8081),
|
newPod("m2", 8081),
|
||||||
makePod("m3", 8080),
|
newPod("m3", 8080),
|
||||||
}
|
}
|
||||||
r := rand.New(rand.NewSource(0))
|
r := rand.New(rand.NewSource(0))
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
|
@ -74,5 +74,5 @@ func TestRandomFitSchedulerFirstScheduledImpossible(t *testing.T) {
|
||||||
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
scheduler: NewRandomFitScheduler(fakeRegistry, r),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3"},
|
||||||
}
|
}
|
||||||
st.expectFailure(makePod("", 8080, 8081))
|
st.expectFailure(newPod("", 8080, 8081))
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ type RoundRobinScheduler struct {
|
||||||
currentIndex int
|
currentIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeRoundRobinScheduler() Scheduler {
|
func NewRoundRobinScheduler() Scheduler {
|
||||||
return &RoundRobinScheduler{
|
return &RoundRobinScheduler{
|
||||||
currentIndex: -1,
|
currentIndex: -1,
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
func TestRoundRobinScheduler(t *testing.T) {
|
func TestRoundRobinScheduler(t *testing.T) {
|
||||||
st := schedulerTester{
|
st := schedulerTester{
|
||||||
t: t,
|
t: t,
|
||||||
scheduler: MakeRoundRobinScheduler(),
|
scheduler: NewRoundRobinScheduler(),
|
||||||
minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"},
|
minionLister: FakeMinionLister{"m1", "m2", "m3", "m4"},
|
||||||
}
|
}
|
||||||
st.expectSchedule(api.Pod{}, "m1")
|
st.expectSchedule(api.Pod{}, "m1")
|
||||||
|
|
|
@ -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{}
|
networkPorts := []api.Port{}
|
||||||
for _, port := range hostPorts {
|
for _, port := range hostPorts {
|
||||||
networkPorts = append(networkPorts, api.Port{HostPort: port})
|
networkPorts = append(networkPorts, api.Port{HostPort: port})
|
||||||
|
|
|
@ -65,7 +65,7 @@ func TestIsEtcdNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractList(t *testing.T) {
|
func TestExtractList(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
|
@ -107,9 +107,9 @@ func TestExtractList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractObj(t *testing.T) {
|
func TestExtractObj(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
expect := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
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}
|
helper := EtcdHelper{fakeClient, codec, versioner}
|
||||||
var got api.Pod
|
var got api.Pod
|
||||||
err := helper.ExtractObj("/some/key", &got, false)
|
err := helper.ExtractObj("/some/key", &got, false)
|
||||||
|
@ -122,7 +122,7 @@ func TestExtractObj(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractObjNotFoundErr(t *testing.T) {
|
func TestExtractObjNotFoundErr(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
|
@ -163,7 +163,7 @@ func TestExtractObjNotFoundErr(t *testing.T) {
|
||||||
|
|
||||||
func TestSetObj(t *testing.T) {
|
func TestSetObj(t *testing.T) {
|
||||||
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
helper := EtcdHelper{fakeClient, codec, versioner}
|
helper := EtcdHelper{fakeClient, codec, versioner}
|
||||||
err := helper.SetObj("/some/key", obj)
|
err := helper.SetObj("/some/key", obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -182,7 +182,7 @@ func TestSetObj(t *testing.T) {
|
||||||
|
|
||||||
func TestSetObjWithVersion(t *testing.T) {
|
func TestSetObjWithVersion(t *testing.T) {
|
||||||
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}}
|
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo", ResourceVersion: 1}}
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
|
@ -211,7 +211,7 @@ func TestSetObjWithVersion(t *testing.T) {
|
||||||
|
|
||||||
func TestSetObjWithoutResourceVersioner(t *testing.T) {
|
func TestSetObjWithoutResourceVersioner(t *testing.T) {
|
||||||
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
obj := api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
helper := EtcdHelper{fakeClient, codec, nil}
|
helper := EtcdHelper{fakeClient, codec, nil}
|
||||||
err := helper.SetObj("/some/key", obj)
|
err := helper.SetObj("/some/key", obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -229,7 +229,7 @@ func TestSetObjWithoutResourceVersioner(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAtomicUpdate(t *testing.T) {
|
func TestAtomicUpdate(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
codec := scheme
|
codec := scheme
|
||||||
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
|
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
|
||||||
|
@ -284,7 +284,7 @@ func TestAtomicUpdate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAtomicUpdateNoChange(t *testing.T) {
|
func TestAtomicUpdateNoChange(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
helper := EtcdHelper{fakeClient, scheme, api.NewJSONBaseResourceVersioner()}
|
helper := EtcdHelper{fakeClient, scheme, api.NewJSONBaseResourceVersioner()}
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ func TestAtomicUpdateNoChange(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAtomicUpdate_CreateCollision(t *testing.T) {
|
func TestAtomicUpdate_CreateCollision(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.TestIndex = true
|
fakeClient.TestIndex = true
|
||||||
codec := scheme
|
codec := scheme
|
||||||
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
|
helper := EtcdHelper{fakeClient, codec, api.NewJSONBaseResourceVersioner()}
|
||||||
|
@ -486,7 +486,7 @@ func TestWatchInterpretation_ResponseBadData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatch(t *testing.T) {
|
func TestWatch(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{}
|
fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{}
|
||||||
h := EtcdHelper{fakeClient, codec, versioner}
|
h := EtcdHelper{fakeClient, codec, versioner}
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, testCase := range testCases {
|
for k, testCase := range testCases {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = testCase.Response
|
fakeClient.Data["/some/key"] = testCase.Response
|
||||||
h := EtcdHelper{fakeClient, codec, versioner}
|
h := EtcdHelper{fakeClient, codec, versioner}
|
||||||
|
|
||||||
|
@ -609,7 +609,7 @@ func TestWatchFromZeroIndex(t *testing.T) {
|
||||||
func TestWatchListFromZeroIndex(t *testing.T) {
|
func TestWatchListFromZeroIndex(t *testing.T) {
|
||||||
pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
pod := &api.Pod{JSONBase: api.JSONBase{ID: "foo"}}
|
||||||
|
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: &etcd.Node{
|
Node: &etcd.Node{
|
||||||
|
@ -662,7 +662,7 @@ func TestWatchListFromZeroIndex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchFromNotFound(t *testing.T) {
|
func TestWatchFromNotFound(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
|
@ -688,7 +688,7 @@ func TestWatchFromNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchFromOtherError(t *testing.T) {
|
func TestWatchFromOtherError(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
fakeClient.Data["/some/key"] = EtcdResponseWithError{
|
||||||
R: &etcd.Response{
|
R: &etcd.Response{
|
||||||
Node: nil,
|
Node: nil,
|
||||||
|
@ -720,7 +720,7 @@ func TestWatchFromOtherError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchPurposefulShutdown(t *testing.T) {
|
func TestWatchPurposefulShutdown(t *testing.T) {
|
||||||
fakeClient := MakeFakeEtcdClient(t)
|
fakeClient := NewFakeEtcdClient(t)
|
||||||
h := EtcdHelper{fakeClient, codec, versioner}
|
h := EtcdHelper{fakeClient, codec, versioner}
|
||||||
fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{}
|
fakeClient.expectNotFoundGetSet["/some/key"] = struct{}{}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ type FakeEtcdClient struct {
|
||||||
WatchStop chan<- bool
|
WatchStop chan<- bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeFakeEtcdClient(t TestLogger) *FakeEtcdClient {
|
func NewFakeEtcdClient(t TestLogger) *FakeEtcdClient {
|
||||||
ret := &FakeEtcdClient{
|
ret := &FakeEtcdClient{
|
||||||
t: t,
|
t: t,
|
||||||
expectNotFoundGetSet: map[string]struct{}{},
|
expectNotFoundGetSet: map[string]struct{}{},
|
||||||
|
|
|
@ -59,8 +59,8 @@ func Forever(f func(), period time.Duration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeJSONString returns obj marshalled as a JSON string, ignoring any errors.
|
// EncodeJSON returns obj marshalled as a JSON string, ignoring any errors.
|
||||||
func MakeJSONString(obj interface{}) string {
|
func EncodeJSON(obj interface{}) string {
|
||||||
data, _ := json.Marshal(obj)
|
data, _ := json.Marshal(obj)
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
@ -83,13 +83,13 @@ const (
|
||||||
IntstrString // The IntOrString holds a string.
|
IntstrString // The IntOrString holds a string.
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeIntOrStringFromInt creates an IntOrString object with an int value.
|
// NewIntOrStringFromInt creates an IntOrString object with an int value.
|
||||||
func MakeIntOrStringFromInt(val int) IntOrString {
|
func NewIntOrStringFromInt(val int) IntOrString {
|
||||||
return IntOrString{Kind: IntstrInt, IntVal: val}
|
return IntOrString{Kind: IntstrInt, IntVal: val}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeIntOrStringFromInt creates an IntOrString object with a string value.
|
// NewIntOrStringFromInt creates an IntOrString object with a string value.
|
||||||
func MakeIntOrStringFromString(val string) IntOrString {
|
func NewIntOrStringFromString(val string) IntOrString {
|
||||||
return IntOrString{Kind: IntstrString, StrVal: val}
|
return IntOrString{Kind: IntstrString, StrVal: val}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ type FakePod struct {
|
||||||
Str string
|
Str string
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeJSONString(t *testing.T) {
|
func TestEncodeJSON(t *testing.T) {
|
||||||
pod := FakePod{
|
pod := FakePod{
|
||||||
FakeJSONBase: FakeJSONBase{ID: "foo"},
|
FakeJSONBase: FakeJSONBase{ID: "foo"},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
|
@ -45,7 +45,7 @@ func TestMakeJSONString(t *testing.T) {
|
||||||
Str: "a string",
|
Str: "a string",
|
||||||
}
|
}
|
||||||
|
|
||||||
body := MakeJSONString(pod)
|
body := EncodeJSON(pod)
|
||||||
|
|
||||||
expectedBody, err := json.Marshal(pod)
|
expectedBody, err := json.Marshal(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -72,15 +72,15 @@ func TestHandleCrash(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeIntOrStringFromInt(t *testing.T) {
|
func TestNewIntOrStringFromInt(t *testing.T) {
|
||||||
i := MakeIntOrStringFromInt(93)
|
i := NewIntOrStringFromInt(93)
|
||||||
if i.Kind != IntstrInt || i.IntVal != 93 {
|
if i.Kind != IntstrInt || i.IntVal != 93 {
|
||||||
t.Errorf("Expected IntVal=93, got %+v", i)
|
t.Errorf("Expected IntVal=93, got %+v", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMakeIntOrStringFromString(t *testing.T) {
|
func TestNewIntOrStringFromString(t *testing.T) {
|
||||||
i := MakeIntOrStringFromString("76")
|
i := NewIntOrStringFromString("76")
|
||||||
if i.Kind != IntstrString || i.StrVal != "76" {
|
if i.Kind != IntstrString || i.StrVal != "76" {
|
||||||
t.Errorf("Expected StrVal=\"76\", got %+v", i)
|
t.Errorf("Expected StrVal=\"76\", got %+v", i)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue