当前位置: 首页>>代码示例>>Golang>>正文


Golang testclient.Fake类代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned/testclient.Fake的典型用法代码示例。如果您正苦于以下问题:Golang Fake类的具体用法?Golang Fake怎么用?Golang Fake使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Fake类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestInitCmd_dryRun

func TestInitCmd_dryRun(t *testing.T) {
	// This is purely defensive in this case.
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	dbg := flagDebug
	flagDebug = true
	defer func() {
		os.Remove(home)
		flagDebug = dbg
	}()

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fake.Extensions(),
		clientOnly: true,
		dryRun:     true,
	}
	if err := cmd.run(); err != nil {
		t.Fatal(err)
	}
	if len(fake.Actions()) != 0 {
		t.Error("expected no server calls")
	}

	var y map[string]interface{}
	if err := yaml.Unmarshal(buf.Bytes(), &y); err != nil {
		t.Errorf("Expected parseable YAML, got %q\n\t%s", buf.String(), err)
	}
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:34,代码来源:init_test.go

示例2: TestSyncBatchIgnoresNotFound

func TestSyncBatchIgnoresNotFound(t *testing.T) {
	client := testclient.Fake{}
	syncer := newTestManager(&client)
	client.AddReactor("get", "pods", func(action testclient.Action) (bool, runtime.Object, error) {
		return true, nil, errors.NewNotFound(api.Resource("pods"), "test-pod")
	})
	syncer.SetPodStatus(testPod, getRandomPodStatus())
	syncer.testSyncBatch()

	verifyActions(t, syncer.kubeClient, []testclient.Action{
		testclient.GetActionImpl{ActionImpl: testclient.ActionImpl{Verb: "get", Resource: "pods"}},
	})
}
开发者ID:michaelcoyote,项目名称:kubernetes,代码行数:13,代码来源:manager_test.go

示例3: TestSyncBatchIgnoresNotFound

func TestSyncBatchIgnoresNotFound(t *testing.T) {
	client := testclient.Fake{}
	syncer := newTestManager(&client)
	client.AddReactor("get", "pods", func(action testclient.Action) (bool, runtime.Object, error) {
		return true, nil, errors.NewNotFound("pods", "test-pod")
	})
	syncer.SetPodStatus(testPod, getRandomPodStatus())
	syncer.syncBatch()

	verifyActions(t, syncer.kubeClient, []testclient.Action{
		testclient.GetActionImpl{ActionImpl: testclient.ActionImpl{Verb: "get", Resource: "pods"}},
	})
	_, found := syncer.GetPodStatus(testPod.UID)
	assert.False(t, found, "Pod status should have been deleted")
}
开发者ID:robbfoster-taulia,项目名称:kubernetes,代码行数:15,代码来源:manager_test.go

示例4: TestInstall_canary

func TestInstall_canary(t *testing.T) {
	fake := testclient.Fake{}
	fake.AddReactor("create", "deployments", func(action testclient.Action) (bool, runtime.Object, error) {
		obj := action.(testclient.CreateAction).GetObject().(*extensions.Deployment)
		i := obj.Spec.Template.Spec.Containers[0].Image
		if i != "gcr.io/kubernetes-helm/tiller:canary" {
			t.Errorf("expected canary image, got '%s'", i)
		}
		return true, obj, nil
	})

	err := Install(fake.Extensions(), "default", "", true, false)
	if err != nil {
		t.Errorf("unexpected error: %#+v", err)
	}
}
开发者ID:slack,项目名称:helm,代码行数:16,代码来源:install_test.go

示例5: TestInitCmd_clientOnly

func TestInitCmd_clientOnly(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions(), clientOnly: true}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	if len(fake.Actions()) != 0 {
		t.Error("expected client call")
	}
	expected := "Not installing tiller due to 'client-only' flag having been set"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
开发者ID:slack,项目名称:helm,代码行数:21,代码来源:init_test.go

示例6: TestInitCmd_exsits

func TestInitCmd_exsits(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	fake.AddReactor("*", "*", func(action testclient.Action) (bool, runtime.Object, error) {
		return true, nil, errors.NewAlreadyExists(api.Resource("deployments"), "1")
	})
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions()}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	expected := "Warning: Tiller is already installed in the cluster. (Use --client-only to suppress this message.)"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
开发者ID:slack,项目名称:helm,代码行数:21,代码来源:init_test.go

示例7: TestInitCmd

func TestInitCmd(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions()}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	actions := fake.Actions()
	if action, ok := actions[0].(testclient.CreateAction); !ok || action.GetResource() != "deployments" {
		t.Errorf("unexpected action: %v, expected create deployment", actions[0])
	}
	expected := "Tiller (the helm server side component) has been installed into your Kubernetes Cluster."
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
开发者ID:slack,项目名称:helm,代码行数:22,代码来源:init_test.go

示例8: TestInstall

func TestInstall(t *testing.T) {
	image := "gcr.io/kubernetes-helm/tiller:v2.0.0"

	fake := testclient.Fake{}
	fake.AddReactor("create", "deployments", func(action testclient.Action) (bool, runtime.Object, error) {
		obj := action.(testclient.CreateAction).GetObject().(*extensions.Deployment)
		l := obj.GetLabels()
		if reflect.DeepEqual(l, map[string]string{"app": "helm"}) {
			t.Errorf("expected labels = '', got '%s'", l)
		}
		i := obj.Spec.Template.Spec.Containers[0].Image
		if i != image {
			t.Errorf("expected image = '%s', got '%s'", image, i)
		}
		return true, obj, nil
	})

	err := Install(fake.Extensions(), "default", image, false, false)
	if err != nil {
		t.Errorf("unexpected error: %#+v", err)
	}
}
开发者ID:slack,项目名称:helm,代码行数:22,代码来源:install_test.go


注:本文中的k8s/io/kubernetes/pkg/client/unversioned/testclient.Fake类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。