Beispiel #1
0
func TestEventWriting(t *testing.T) {
	fakeEtcd := registry.MakeFakeEtcdClient(t)
	kubelet := &Kubelet{
		Client: fakeEtcd,
	}
	expectedEvent := api.Event{
		Event: "test",
		Container: &api.Container{
			Name: "foo",
		},
	}
	err := kubelet.LogEvent(&expectedEvent)
	expectNoError(t, err)
	if fakeEtcd.Ix != 1 {
		t.Errorf("Unexpected number of children added: %d, expected 1", fakeEtcd.Ix)
	}
	response, err := fakeEtcd.Get("/events/foo/1", false, false)
	expectNoError(t, err)
	var event api.Event
	err = json.Unmarshal([]byte(response.Node.Value), &event)
	expectNoError(t, err)
	if event.Event != expectedEvent.Event ||
		event.Container.Name != expectedEvent.Container.Name {
		t.Errorf("Event's don't match.  Expected: %#v Saw: %#v", expectedEvent, event)
	}
}
Beispiel #2
0
func TestEventWritingError(t *testing.T) {
	fakeEtcd := registry.MakeFakeEtcdClient(t)
	kubelet := &Kubelet{
		Client: fakeEtcd,
	}
	fakeEtcd.Err = fmt.Errorf("test error")
	err := kubelet.LogEvent(&api.Event{
		Event: "test",
		Container: &api.Container{
			Name: "foo",
		},
	})
	if err == nil {
		t.Errorf("Unexpected non-error")
	}
}
Beispiel #3
0
func TestGetKubeletStateFromEtcdNotFound(t *testing.T) {
	fakeClient := registry.MakeFakeEtcdClient(t)
	kubelet := Kubelet{
		Client: fakeClient,
	}
	channel := make(chan []api.ContainerManifest)
	reader := startReading(channel)
	fakeClient.Data["/registry/hosts/machine/kubelet"] = registry.EtcdResponseWithError{
		R: &etcd.Response{},
		E: &etcd.EtcdError{
			ErrorCode: 100,
		},
	}
	err := kubelet.getKubeletStateFromEtcd("/registry/hosts/machine", channel)
	expectNoError(t, err)
	close(channel)
	list := reader.GetList()
	if len(list) != 0 {
		t.Errorf("Unexpected list: %#v", list)
	}
}