當前位置: 首頁>>代碼示例>>Golang>>正文


Golang registrytest.NewPodRegistry函數代碼示例

本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest.NewPodRegistry函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPodRegistry函數的具體用法?Golang NewPodRegistry怎麽用?Golang NewPodRegistry使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewPodRegistry函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestPodDecode

func TestPodDecode(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	storage := REST{
		registry: podRegistry,
		podCache: &fakeCache{statusToReturn: &api.PodStatus{}},
	}
	expected := &api.Pod{
		ObjectMeta: api.ObjectMeta{
			Name: "foo",
		},
	}
	body, err := latest.Codec.Encode(expected)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	actual := storage.New()
	if err := latest.Codec.DecodeInto(body, actual); err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Expected %#v, Got %#v", expected, actual)
	}
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:25,代碼來源:rest_test.go

示例2: TestPodUpdateAllContainers

func TestPodUpdateAllContainers(t *testing.T) {
	pod := api.Pod{
		ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: api.NamespaceDefault},
		Status: api.PodStatus{
			Host: "machine",
		},
	}

	pods := []api.Pod{pod}
	mockRegistry := registrytest.NewPodRegistry(&api.PodList{Items: pods})

	expected := api.PodInfo{
		"foo": api.ContainerStatus{},
	}
	fake := FakePodInfoGetter{
		data: expected,
	}
	cache := NewPodCache(&fake, mockRegistry)

	cache.UpdateAllContainers()

	if fake.host != "machine" || fake.id != "foo" || fake.namespace != api.NamespaceDefault {
		t.Errorf("Unexpected access: %#v", fake)
	}

	info, err := cache.GetPodInfo("machine", api.NamespaceDefault, "foo")
	if err != nil {
		t.Errorf("Unexpected error: %#v", err)
	}
	if !reflect.DeepEqual(info, expected) {
		t.Errorf("Unexpected mismatch. Expected: %#v, Got: #%v", &expected, info)
	}
}
開發者ID:TencentSA,項目名稱:kubernetes-0.5,代碼行數:33,代碼來源:pod_cache_test.go

示例3: TestCreatePod

func TestCreatePod(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Pod = &api.Pod{
		ObjectMeta: api.ObjectMeta{Name: "foo"},
		Status: api.PodStatus{
			Host: "machine",
		},
	}
	storage := REST{
		registry: podRegistry,
		podCache: &fakeCache{statusToReturn: &api.PodStatus{}},
	}
	pod := &api.Pod{}
	pod.Name = "foo"
	ctx := api.NewDefaultContext()
	channel, err := storage.Create(ctx, pod)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}
	select {
	case <-channel:
		// Do nothing, this is expected.
	case <-time.After(time.Millisecond * 100):
		t.Error("Unexpected timeout on async channel")
	}
	if !api.HasObjectMetaSystemFieldValues(&podRegistry.Pod.ObjectMeta) {
		t.Errorf("Expected ObjectMeta field values were populated")
	}
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:29,代碼來源:rest_test.go

示例4: TestListPodList

func TestListPodList(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Pods = &api.PodList{
		Items: []api.Pod{
			{
				JSONBase: api.JSONBase{
					ID: "foo",
				},
			},
			{
				JSONBase: api.JSONBase{
					ID: "bar",
				},
			},
		},
	}
	storage := RegistryStorage{
		registry: podRegistry,
	}
	podsObj, err := storage.List(labels.Everything())
	pods := podsObj.(*api.PodList)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if len(pods.Items) != 2 {
		t.Errorf("Unexpected pod list: %#v", pods)
	}
	if pods.Items[0].ID != "foo" {
		t.Errorf("Unexpected pod: %#v", pods.Items[0])
	}
	if pods.Items[1].ID != "bar" {
		t.Errorf("Unexpected pod: %#v", pods.Items[1])
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:35,代碼來源:storage_test.go

示例5: TestPodUpdateAllContainers

func TestPodUpdateAllContainers(t *testing.T) {
	pod := api.Pod{
		JSONBase: api.JSONBase{ID: "foo"},
		CurrentState: api.PodState{
			Host: "machine",
		},
	}

	pods := []api.Pod{pod}
	mockRegistry := registrytest.NewPodRegistry(&api.PodList{Items: pods})

	expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
	fake := FakePodInfoGetter{
		data: expected,
	}
	cache := NewPodCache(&fake, mockRegistry)

	cache.UpdateAllContainers()

	if fake.host != "machine" || fake.id != "foo" {
		t.Errorf("Unexpected access: %#v", fake)
	}

	info, err := cache.GetPodInfo("machine", "foo")
	if err != nil {
		t.Errorf("Unexpected error: %#v", err)
	}
	if !reflect.DeepEqual(info, expected) {
		t.Errorf("Unexpected mismatch. Expected: %#v, Got: #%v", &expected, info)
	}
}
開發者ID:asim,項目名稱:kubernetes,代碼行數:31,代碼來源:pod_cache_test.go

示例6: TestCreatePod

func TestCreatePod(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Pod = &api.Pod{
		JSONBase: api.JSONBase{ID: "foo"},
		CurrentState: api.PodState{
			Host: "machine",
		},
	}
	storage := RegistryStorage{
		registry:      podRegistry,
		podPollPeriod: time.Millisecond * 100,
	}
	desiredState := api.PodState{
		Manifest: api.ContainerManifest{
			Version: "v1beta1",
		},
	}
	pod := &api.Pod{
		JSONBase:     api.JSONBase{ID: "foo"},
		DesiredState: desiredState,
	}
	channel, err := storage.Create(pod)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	select {
	case <-channel:
		// Do nothing, this is expected.
	case <-time.After(time.Millisecond * 100):
		t.Error("Unexpected timeout on async channel")
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:33,代碼來源:storage_test.go

示例7: TestCreatePodSetsIds

func TestCreatePodSetsIds(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := RegistryStorage{
		registry: podRegistry,
	}
	desiredState := api.PodState{
		Manifest: api.ContainerManifest{
			Version: "v1beta1",
		},
	}
	pod := &api.Pod{DesiredState: desiredState}
	ch, err := storage.Create(pod)
	if err != nil {
		t.Errorf("Expected %#v, Got %#v", nil, err)
	}
	expectApiStatusError(t, ch, podRegistry.Err.Error())

	if len(podRegistry.Pod.ID) == 0 {
		t.Errorf("Expected pod ID to be set, Got %#v", pod)
	}
	if podRegistry.Pod.DesiredState.Manifest.ID != podRegistry.Pod.ID {
		t.Errorf("Expected manifest ID to be equal to pod ID, Got %#v", pod)
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:25,代碼來源:storage_test.go

示例8: TestListPodsCacheError

func TestListPodsCacheError(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Pods = &api.PodList{
		Items: []api.Pod{
			{
				ObjectMeta: api.ObjectMeta{
					Name: "foo",
				},
			},
		},
	}
	storage := REST{
		registry: podRegistry,
		podCache: &fakeCache{errorToReturn: client.ErrPodInfoNotAvailable},
	}
	ctx := api.NewContext()
	pods, err := storage.List(ctx, labels.Everything(), labels.Everything())
	if err != nil {
		t.Fatalf("Expected no error, got %#v", err)
	}
	pl := pods.(*api.PodList)
	if len(pl.Items) != 1 {
		t.Fatalf("Unexpected 0-len pod list: %+v", pl)
	}
	if e, a := api.PodUnknown, pl.Items[0].Status.Phase; e != a {
		t.Errorf("Expected %v, got %v", e, a)
	}
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:28,代碼來源:rest_test.go

示例9: TestGetPod

func TestGetPod(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Pod = &api.Pod{
		ObjectMeta: api.ObjectMeta{Name: "foo"},
		Status:     api.PodStatus{Host: "machine"},
	}
	storage := REST{
		registry: podRegistry,
		podCache: &fakeCache{statusToReturn: &api.PodStatus{Phase: api.PodRunning}},
	}
	ctx := api.NewContext()
	obj, err := storage.Get(ctx, "foo")
	pod := obj.(*api.Pod)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	expect := *podRegistry.Pod
	expect.Status.Phase = api.PodRunning
	// TODO: when host is moved to spec, remove this line.
	expect.Status.Host = "machine"
	if e, a := &expect, pod; !reflect.DeepEqual(e, a) {
		t.Errorf("Unexpected pod. Expected %#v, Got %#v", e, a)
	}
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:25,代碼來源:rest_test.go

示例10: TestListEmptyPodList

func TestListEmptyPodList(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	storage := RegistryStorage{
		registry: podRegistry,
	}
	pods, err := storage.List(labels.Everything())
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if len(pods.(api.PodList).Items) != 0 {
		t.Errorf("Unexpected non-zero pod list: %#v", pods)
	}
}
開發者ID:jcantrill,項目名稱:kubernetes,代碼行數:14,代碼來源:storage_test.go

示例11: TestCreatePodRegistryError

func TestCreatePodRegistryError(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := REST{
		registry: podRegistry,
	}
	pod := &api.Pod{}
	ctx := api.NewDefaultContext()
	ch, err := storage.Create(ctx, pod)
	if err != nil {
		t.Errorf("Expected %#v, Got %#v", nil, err)
	}
	expectApiStatusError(t, ch, podRegistry.Err.Error())
}
開發者ID:TencentSA,項目名稱:kubernetes-0.5,代碼行數:14,代碼來源:rest_test.go

示例12: TestListPodsError

func TestListPodsError(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := RegistryStorage{
		registry: podRegistry,
	}
	pods, err := storage.List(labels.Everything())
	if err != podRegistry.Err {
		t.Errorf("Expected %#v, Got %#v", podRegistry.Err, err)
	}
	if pods.(*api.PodList) != nil {
		t.Errorf("Unexpected non-nil pod list: %#v", pods)
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:14,代碼來源:storage_test.go

示例13: TestPodStorageValidatesUpdate

func TestPodStorageValidatesUpdate(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := RegistryStorage{
		registry: podRegistry,
	}
	pod := &api.Pod{}
	c, err := storage.Update(pod)
	if c != nil {
		t.Errorf("Expected nil channel")
	}
	if err == nil {
		t.Errorf("Expected to get an error")
	}
}
開發者ID:hvdb,項目名稱:kubernetes,代碼行數:15,代碼來源:storage_test.go

示例14: TestPodStorageValidatesUpdate

func TestPodStorageValidatesUpdate(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := RegistryStorage{
		registry: podRegistry,
	}
	pod := &api.Pod{}
	c, err := storage.Update(pod)
	if c != nil {
		t.Errorf("Expected nil channel")
	}
	if !apiserver.IsInvalid(err) {
		t.Errorf("Expected to get an invalid resource error, got %v", err)
	}
}
開發者ID:nvdnkpr,項目名稱:kubernetes,代碼行數:15,代碼來源:storage_test.go

示例15: TestPodStorageValidatesUpdate

func TestPodStorageValidatesUpdate(t *testing.T) {
	podRegistry := registrytest.NewPodRegistry(nil)
	podRegistry.Err = fmt.Errorf("test error")
	storage := REST{
		registry: podRegistry,
	}
	ctx := api.NewDefaultContext()
	pod := &api.Pod{}
	c, err := storage.Update(ctx, pod)
	if c != nil {
		t.Errorf("Expected nil channel")
	}
	if !errors.IsInvalid(err) {
		t.Errorf("Expected to get an invalid resource error, got %v", err)
	}
}
開發者ID:ericcapricorn,項目名稱:kubernetes,代碼行數:16,代碼來源:rest_test.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest.NewPodRegistry函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。