本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/testclient.NewSimpleFake函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSimpleFake函数的具体用法?Golang NewSimpleFake怎么用?Golang NewSimpleFake使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSimpleFake函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestIncrementUsageReplicationControllers
func TestIncrementUsageReplicationControllers(t *testing.T) {
namespace := "default"
client := testclient.NewSimpleFake(&api.ReplicationControllerList{
Items: []api.ReplicationController{
{
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: namespace},
},
},
})
status := &api.ResourceQuotaStatus{
Hard: api.ResourceList{},
Used: api.ResourceList{},
}
r := api.ResourceReplicationControllers
status.Hard[r] = resource.MustParse("2")
status.Used[r] = resource.MustParse("1")
dirty, err := IncrementUsage(admission.NewAttributesRecord(&api.ReplicationController{}, "ReplicationController", namespace, "name", "replicationcontrollers", "", admission.Create, nil), status, client)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !dirty {
t.Errorf("Expected the status to get incremented, therefore should have been dirty")
}
quantity := status.Used[r]
if quantity.Value() != int64(2) {
t.Errorf("Expected new item count to be 2, but was %s", quantity.String())
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:28,代码来源:admission_test.go
示例2: TestServiceResolverCacheEmpty
func TestServiceResolverCacheEmpty(t *testing.T) {
fakeClient := testclient.NewSimpleFake(&api.Service{
ObjectMeta: api.ObjectMeta{
Name: "foo",
},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{{Port: 80}},
},
})
cache := NewServiceResolverCache(fakeClient.Services("default").Get)
if v, ok := cache.resolve("FOO_SERVICE_HOST"); v != "" || !ok {
t.Errorf("unexpected cache item")
}
if len(fakeClient.Actions()) != 1 {
t.Errorf("unexpected client actions: %#v", fakeClient.Actions())
}
cache.resolve("FOO_SERVICE_HOST")
if len(fakeClient.Actions()) != 1 {
t.Errorf("unexpected cache miss: %#v", fakeClient.Actions())
}
cache.resolve("FOO_SERVICE_PORT")
if len(fakeClient.Actions()) != 1 {
t.Errorf("unexpected cache miss: %#v", fakeClient.Actions())
}
}
开发者ID:jhadvig,项目名称:origin,代码行数:25,代码来源:environmentresolvercache_test.go
示例3: TestRolling_deployInitial
func TestRolling_deployInitial(t *testing.T) {
initialStrategyInvoked := false
strategy := &RollingDeploymentStrategy{
codec: api.Codec,
client: ktestclient.NewSimpleFake(),
initialStrategy: &testStrategy{
deployFn: func(from *kapi.ReplicationController, to *kapi.ReplicationController, desiredReplicas int, updateAcceptor strat.UpdateAcceptor) error {
initialStrategyInvoked = true
return nil
},
},
rollingUpdate: func(config *kubectl.RollingUpdaterConfig) error {
t.Fatalf("unexpected call to rollingUpdate")
return nil
},
getUpdateAcceptor: getUpdateAcceptor,
apiRetryPeriod: 1 * time.Millisecond,
apiRetryTimeout: 10 * time.Millisecond,
}
config := deploytest.OkDeploymentConfig(1)
config.Template.Strategy = deploytest.OkRollingStrategy()
deployment, _ := deployutil.MakeDeployment(config, kapi.Codec)
err := strategy.Deploy(nil, deployment, 2)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !initialStrategyInvoked {
t.Fatalf("expected initial strategy to be invoked")
}
}
开发者ID:nitintutlani,项目名称:origin,代码行数:32,代码来源:rolling_test.go
示例4: TestUnboundedMemory
func TestUnboundedMemory(t *testing.T) {
namespace := "default"
client := testclient.NewSimpleFake(&api.PodList{
Items: []api.Pod{
{
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: namespace},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol"}},
Containers: []api.Container{{Name: "ctr", Image: "image", Resources: getResourceRequirements("100m", "1Gi")}},
},
},
},
})
status := &api.ResourceQuotaStatus{
Hard: api.ResourceList{},
Used: api.ResourceList{},
}
r := api.ResourceMemory
status.Hard[r] = resource.MustParse("10Gi")
status.Used[r] = resource.MustParse("1Gi")
newPod := &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: namespace},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol"}},
Containers: []api.Container{{Name: "ctr", Image: "image", Resources: getResourceRequirements("250m", "0")}},
}}
_, err := IncrementUsage(admission.NewAttributesRecord(newPod, "Pod", namespace, "name", "pods", "", admission.Create, nil), status, client)
if err == nil {
t.Errorf("Expected memory unbounded usage error")
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:32,代码来源:admission_test.go
示例5: TestLimitRangerIgnoresSubresource
func TestLimitRangerIgnoresSubresource(t *testing.T) {
client := testclient.NewSimpleFake()
indexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{"namespace": cache.MetaNamespaceIndexFunc})
handler := &limitRanger{
Handler: admission.NewHandler(admission.Create, admission.Update),
client: client,
limitFunc: Limit,
indexer: indexer,
}
limitRange := validLimitRangeNoDefaults()
testPod := validPod("testPod", 1, api.ResourceRequirements{})
indexer.Add(&limitRange)
err := handler.Admit(admission.NewAttributesRecord(&testPod, "Pod", limitRange.Namespace, "testPod", "pods", "", admission.Update, nil))
if err == nil {
t.Errorf("Expected an error since the pod did not specify resource limits in its update call")
}
err = handler.Admit(admission.NewAttributesRecord(&testPod, "Pod", limitRange.Namespace, "testPod", "pods", "status", admission.Update, nil))
if err != nil {
t.Errorf("Should have ignored calls to any subresource of pod %v", err)
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:25,代码来源:admission_test.go
示例6: TestListProjects
func TestListProjects(t *testing.T) {
namespaceList := kapi.NamespaceList{
Items: []kapi.Namespace{
{
ObjectMeta: kapi.ObjectMeta{Name: "foo"},
},
},
}
mockClient := testclient.NewSimpleFake(&namespaceList)
storage := REST{
client: mockClient.Namespaces(),
lister: &mockLister{&namespaceList},
}
user := &user.DefaultInfo{
Name: "test-user",
UID: "test-uid",
Groups: []string{"test-groups"},
}
ctx := kapi.WithUser(kapi.NewContext(), user)
response, err := storage.List(ctx, labels.Everything(), fields.Everything())
if err != nil {
t.Errorf("%#v should be nil.", err)
}
projects := response.(*api.ProjectList)
if len(projects.Items) != 1 {
t.Errorf("%#v projects.Items should have len 1.", projects.Items)
}
responseProject := projects.Items[0]
if e, r := responseProject.Name, "foo"; e != r {
t.Errorf("%#v != %#v.", e, r)
}
}
开发者ID:Tlacenka,项目名称:origin,代码行数:32,代码来源:proxy_test.go
示例7: TestIncrementUsagePods
func TestIncrementUsagePods(t *testing.T) {
namespace := "default"
client := testclient.NewSimpleFake(&api.PodList{
Items: []api.Pod{
{
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: namespace},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol"}},
Containers: []api.Container{{Name: "ctr", Image: "image", Resources: getResourceRequirements("100m", "1Gi")}},
},
},
},
})
status := &api.ResourceQuotaStatus{
Hard: api.ResourceList{},
Used: api.ResourceList{},
}
r := api.ResourcePods
status.Hard[r] = resource.MustParse("2")
status.Used[r] = resource.MustParse("1")
dirty, err := IncrementUsage(admission.NewAttributesRecord(&api.Pod{}, "Pod", namespace, "name", "pods", "", admission.Create, nil), status, client)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !dirty {
t.Errorf("Expected the status to get incremented, therefore should have been dirty")
}
quantity := status.Used[r]
if quantity.Value() != int64(2) {
t.Errorf("Expected new item count to be 2, but was %s", quantity.String())
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:32,代码来源:admission_test.go
示例8: TestName
func TestName(t *testing.T) {
var (
testPodUID = types.UID("test_pod_uid")
testVolumeName = "test_name"
testNamespace = "test_metadata_namespace"
testName = "test_metadata_name"
)
volumeSpec := &api.Volume{
Name: testVolumeName,
VolumeSource: api.VolumeSource{
Metadata: &api.MetadataVolumeSource{
Items: []api.MetadataFile{
{Name: "name_file_name", FieldRef: api.ObjectFieldSelector{
FieldPath: "metadata.name"}}}},
},
}
fake := testclient.NewSimpleFake(&api.Pod{
ObjectMeta: api.ObjectMeta{
Name: testName,
Namespace: testNamespace,
},
})
pluginMgr := volume.VolumePluginMgr{}
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
plugin, err := pluginMgr.FindPluginByName(metadataPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
}
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: testPodUID, Name: testName}}
builder, err := plugin.NewBuilder(volume.NewSpecFromVolume(volumeSpec), pod, volume.VolumeOptions{}, &mount.FakeMounter{})
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
volumePath := builder.GetPath()
err = builder.SetUp()
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
var data []byte
data, err = ioutil.ReadFile(path.Join(volumePath, "name_file_name"))
if err != nil {
t.Errorf(err.Error())
}
if string(data) != testName {
t.Errorf("Found `%s` expected %s", string(data), testName)
}
CleanEverything(plugin, testVolumeName, volumePath, testPodUID, t)
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:60,代码来源:metadata_test.go
示例9: TestReplicationControllerStop
func TestReplicationControllerStop(t *testing.T) {
name := "foo"
ns := "default"
fake := testclient.NewSimpleFake(&api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: name,
Namespace: ns,
},
Spec: api.ReplicationControllerSpec{
Replicas: 0,
},
})
reaper := ReplicationControllerReaper{fake, time.Millisecond, time.Millisecond}
s, err := reaper.Stop(ns, name, 0, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
expected := "foo stopped"
if s != expected {
t.Errorf("expected %s, got %s", expected, s)
}
actions := fake.Actions()
if len(actions) != 7 {
t.Errorf("unexpected actions: %v, expected 6 actions (get, list, get, update, get, get, delete)", fake.Actions)
}
for i, verb := range []string{"get", "list", "get", "update", "get", "get", "delete"} {
if actions[i].GetResource() != "replicationcontrollers" {
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
continue
}
if actions[i].GetVerb() != verb {
t.Errorf("unexpected action: %+v, expected %s-replicationController", actions[i], verb)
}
}
}
开发者ID:gogogocheng,项目名称:kubernetes,代码行数:35,代码来源:stop_test.go
示例10: TestSyncResourceQuotaNoChange
func TestSyncResourceQuotaNoChange(t *testing.T) {
quota := api.ResourceQuota{
Spec: api.ResourceQuotaSpec{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("4"),
},
},
Status: api.ResourceQuotaStatus{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("4"),
},
Used: api.ResourceList{
api.ResourceCPU: resource.MustParse("0"),
},
},
}
kubeClient := testclient.NewSimpleFake(&api.PodList{}, "a)
ResourceQuotaController := NewResourceQuotaController(kubeClient)
err := ResourceQuotaController.syncResourceQuota(quota)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
actions := kubeClient.Actions()
if len(actions) != 1 && !actions[0].Matches("list", "pods") {
t.Errorf("SyncResourceQuota made an unexpected client action when state was not dirty: %v", kubeClient.Actions)
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:30,代码来源:resource_quota_controller_test.go
示例11: TestExceedUsagePods
func TestExceedUsagePods(t *testing.T) {
namespace := "default"
client := testclient.NewSimpleFake(&api.PodList{
Items: []api.Pod{
{
ObjectMeta: api.ObjectMeta{Name: "123", Namespace: namespace},
Spec: api.PodSpec{
Volumes: []api.Volume{{Name: "vol"}},
Containers: []api.Container{{Name: "ctr", Image: "image", Resources: getResourceRequirements("100m", "1Gi")}},
},
},
},
})
status := &api.ResourceQuotaStatus{
Hard: api.ResourceList{},
Used: api.ResourceList{},
}
r := api.ResourcePods
status.Hard[r] = resource.MustParse("1")
status.Used[r] = resource.MustParse("1")
_, err := IncrementUsage(admission.NewAttributesRecord(&api.Pod{}, "Pod", namespace, "name", "pods", "", admission.Create, nil), status, client)
if err == nil {
t.Errorf("Expected error because this would exceed your quota")
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:25,代码来源:admission_test.go
示例12: TestSyncResourceQuotaSpecChange
func TestSyncResourceQuotaSpecChange(t *testing.T) {
quota := api.ResourceQuota{
Spec: api.ResourceQuotaSpec{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("4"),
},
},
Status: api.ResourceQuotaStatus{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("3"),
},
Used: api.ResourceList{
api.ResourceCPU: resource.MustParse("0"),
},
},
}
expectedUsage := api.ResourceQuota{
Status: api.ResourceQuotaStatus{
Hard: api.ResourceList{
api.ResourceCPU: resource.MustParse("4"),
},
Used: api.ResourceList{
api.ResourceCPU: resource.MustParse("0"),
},
},
}
kubeClient := testclient.NewSimpleFake("a)
ResourceQuotaController := NewResourceQuotaController(kubeClient)
err := ResourceQuotaController.syncResourceQuota(quota)
if err != nil {
t.Fatalf("Unexpected error %v", err)
}
usage := kubeClient.Actions()[1].(testclient.UpdateAction).GetObject().(*api.ResourceQuota)
// ensure hard and used limits are what we expected
for k, v := range expectedUsage.Status.Hard {
actual := usage.Status.Hard[k]
actualValue := actual.String()
expectedValue := v.String()
if expectedValue != actualValue {
t.Errorf("Usage Hard: Key: %v, Expected: %v, Actual: %v", k, expectedValue, actualValue)
}
}
for k, v := range expectedUsage.Status.Used {
actual := usage.Status.Used[k]
actualValue := actual.String()
expectedValue := v.String()
if expectedValue != actualValue {
t.Errorf("Usage Used: Key: %v, Expected: %v, Actual: %v", k, expectedValue, actualValue)
}
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:57,代码来源:resource_quota_controller_test.go
示例13: TestPluginIdempotent
// Test the case where the 'ready' file has been created and the pod volume dir
// is a mountpoint. Mount should not be called.
func TestPluginIdempotent(t *testing.T) {
var (
testPodUID = types.UID("test_pod_uid2")
testVolumeName = "test_volume_name"
testNamespace = "test_secret_namespace"
testName = "test_secret_name"
volumeSpec = volumeSpec(testVolumeName, testName)
secret = secret(testNamespace, testName)
client = testclient.NewSimpleFake(&secret)
pluginMgr = volume.VolumePluginMgr{}
rootDir, host = newTestHost(t, client)
)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
}
podVolumeDir := fmt.Sprintf("%v/pods/test_pod_uid2/volumes/kubernetes.io~secret/test_volume_name", rootDir)
podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid2/plugins/kubernetes.io~secret/test_volume_name", rootDir)
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: testPodUID}}
mounter := &mount.FakeMounter{}
mounter.MountPoints = []mount.MountPoint{
{
Path: podVolumeDir,
},
}
util.SetReady(podMetadataDir)
builder, err := plugin.NewBuilder(volume.NewSpecFromVolume(volumeSpec), pod, volume.VolumeOptions{}, mounter)
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
volumePath := builder.GetPath()
err = builder.SetUp()
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
if len(mounter.Log) != 0 {
t.Errorf("Unexpected calls made to mounter: %v", mounter.Log)
}
if _, err := os.Stat(volumePath); err != nil {
if !os.IsNotExist(err) {
t.Errorf("SetUp() failed unexpectedly: %v", err)
}
} else {
t.Errorf("volume path should not exist: %v", volumePath)
}
}
开发者ID:nitintutlani,项目名称:origin,代码行数:59,代码来源:secret_test.go
示例14: TestRolling_deployInitialHooks
// TestRolling_deployInitialHooks can go away once the rolling strategy
// supports initial deployments.
func TestRolling_deployInitialHooks(t *testing.T) {
var hookError error
strategy := &RollingDeploymentStrategy{
codec: api.Codec,
client: ktestclient.NewSimpleFake(),
initialStrategy: &testStrategy{
deployFn: func(from *kapi.ReplicationController, to *kapi.ReplicationController, desiredReplicas int, updateAcceptor strat.UpdateAcceptor) error {
return nil
},
},
rollingUpdate: func(config *kubectl.RollingUpdaterConfig) error {
return nil
},
hookExecutor: &hookExecutorImpl{
executeFunc: func(hook *deployapi.LifecycleHook, deployment *kapi.ReplicationController, label string) error {
return hookError
},
},
getUpdateAcceptor: getUpdateAcceptor,
apiRetryPeriod: 1 * time.Millisecond,
apiRetryTimeout: 10 * time.Millisecond,
}
cases := []struct {
params *deployapi.RollingDeploymentStrategyParams
hookShouldFail bool
deploymentShouldFail bool
}{
{rollingParams(deployapi.LifecycleHookFailurePolicyAbort, ""), true, true},
{rollingParams(deployapi.LifecycleHookFailurePolicyAbort, ""), false, false},
{rollingParams("", deployapi.LifecycleHookFailurePolicyAbort), true, false},
{rollingParams("", deployapi.LifecycleHookFailurePolicyAbort), false, false},
}
for _, tc := range cases {
config := deploytest.OkDeploymentConfig(2)
config.Template.Strategy.RollingParams = tc.params
deployment, _ := deployutil.MakeDeployment(config, kapi.Codec)
hookError = nil
if tc.hookShouldFail {
hookError = fmt.Errorf("hook failure")
}
err := strategy.Deploy(nil, deployment, 2)
if err != nil && tc.deploymentShouldFail {
t.Logf("got expected error: %v", err)
}
if err == nil && tc.deploymentShouldFail {
t.Errorf("expected an error for case: %v", tc)
}
if err != nil && !tc.deploymentShouldFail {
t.Errorf("unexpected error for case: %v: %v", tc, err)
}
}
}
开发者ID:nitintutlani,项目名称:origin,代码行数:57,代码来源:rolling_test.go
示例15: TestPluginReboot
// Test the case where the plugin's ready file exists, but the volume dir is not a
// mountpoint, which is the state the system will be in after reboot. The dir
// should be mounter and the secret data written to it.
func TestPluginReboot(t *testing.T) {
var (
testPodUID = types.UID("test_pod_uid3")
testVolumeName = "test_volume_name"
testNamespace = "test_secret_namespace"
testName = "test_secret_name"
volumeSpec = volumeSpec(testVolumeName, testName)
secret = secret(testNamespace, testName)
client = testclient.NewSimpleFake(&secret)
pluginMgr = volume.VolumePluginMgr{}
rootDir, host = newTestHost(t, client)
)
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
plugin, err := pluginMgr.FindPluginByName(secretPluginName)
if err != nil {
t.Errorf("Can't find the plugin by name")
}
pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: testPodUID}}
builder, err := plugin.NewBuilder(volume.NewSpecFromVolume(volumeSpec), pod, volume.VolumeOptions{}, &mount.FakeMounter{})
if err != nil {
t.Errorf("Failed to make a new Builder: %v", err)
}
if builder == nil {
t.Errorf("Got a nil Builder")
}
podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid3/plugins/kubernetes.io~secret/test_volume_name", rootDir)
util.SetReady(podMetadataDir)
volumePath := builder.GetPath()
if !strings.HasSuffix(volumePath, fmt.Sprintf("pods/test_pod_uid3/volumes/kubernetes.io~secret/test_volume_name")) {
t.Errorf("Got unexpected path: %s", volumePath)
}
err = builder.SetUp()
if err != nil {
t.Errorf("Failed to setup volume: %v", err)
}
if _, err := os.Stat(volumePath); err != nil {
if os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %s", volumePath)
} else {
t.Errorf("SetUp() failed: %v", err)
}
}
doTestSecretDataInVolume(volumePath, secret, t)
doTestCleanAndTeardown(plugin, testPodUID, testVolumeName, volumePath, t)
}
开发者ID:nitintutlani,项目名称:origin,代码行数:55,代码来源:secret_test.go
示例16: TestGetProjectOK
func TestGetProjectOK(t *testing.T) {
mockClient := testclient.NewSimpleFake(&kapi.Namespace{ObjectMeta: kapi.ObjectMeta{Name: "foo"}})
storage := NewREST(mockClient.Namespaces(), &mockLister{})
project, err := storage.Get(kapi.NewContext(), "foo")
if project == nil {
t.Error("Unexpected nil project")
}
if err != nil {
t.Errorf("Unexpected non-nil error: %v", err)
}
if project.(*api.Project).Name != "foo" {
t.Errorf("Unexpected project: %#v", project)
}
}
开发者ID:Tlacenka,项目名称:origin,代码行数:14,代码来源:proxy_test.go
示例17: mockBuildConfigInstantiator
func mockBuildConfigInstantiator(buildcfg *buildapi.BuildConfig, imageStream *imageapi.ImageStream, image *imageapi.Image) *buildConfigInstantiator {
builderAccount := kapi.ServiceAccount{
ObjectMeta: kapi.ObjectMeta{Name: bootstrappolicy.BuilderServiceAccountName},
Secrets: []kapi.ObjectReference{},
}
instantiator := &buildConfigInstantiator{}
instantiator.buildConfigUpdater = &mockBuildConfigUpdater{}
generator := buildgenerator.BuildGenerator{
Secrets: testclient.NewSimpleFake(),
ServiceAccounts: testclient.NewSimpleFake(&builderAccount),
Client: buildgenerator.Client{
GetBuildConfigFunc: func(ctx kapi.Context, name string) (*buildapi.BuildConfig, error) {
return buildcfg, nil
},
UpdateBuildConfigFunc: func(ctx kapi.Context, buildConfig *buildapi.BuildConfig) error {
return instantiator.buildConfigUpdater.Update(buildConfig)
},
CreateBuildFunc: func(ctx kapi.Context, build *buildapi.Build) error {
instantiator.newBuild = build
return instantiator.err
},
GetBuildFunc: func(ctx kapi.Context, name string) (*buildapi.Build, error) {
return instantiator.newBuild, nil
},
GetImageStreamFunc: func(ctx kapi.Context, name string) (*imageapi.ImageStream, error) {
return imageStream, nil
},
GetImageStreamTagFunc: func(ctx kapi.Context, name string) (*imageapi.ImageStreamTag, error) {
return &imageapi.ImageStreamTag{Image: *image}, nil
},
GetImageStreamImageFunc: func(ctx kapi.Context, name string) (*imageapi.ImageStreamImage, error) {
return &imageapi.ImageStreamImage{Image: *image}, nil
},
}}
instantiator.generator = generator
return instantiator
}
开发者ID:jhadvig,项目名称:origin,代码行数:37,代码来源:image_change_controller_test.go
示例18: MockBuilderServiceAccount
func MockBuilderServiceAccount(secrets []*kapi.Secret) kclient.ServiceAccountsNamespacer {
var (
secretRefs []kapi.ObjectReference
fakeObjects []runtime.Object
)
for _, secret := range secrets {
secretRefs = append(secretRefs, kapi.ObjectReference{Name: secret.Name, Kind: "Secret"})
fakeObjects = append(fakeObjects, secret)
}
fakeObjects = append(fakeObjects, &kapi.ServiceAccount{
ObjectMeta: kapi.ObjectMeta{Name: bootstrappolicy.BuilderServiceAccountName},
Secrets: secretRefs,
})
return testclient.NewSimpleFake(fakeObjects...)
}
开发者ID:jhadvig,项目名称:origin,代码行数:15,代码来源:mocks.go
示例19: TestDeniesInvalidServiceAccount
func TestDeniesInvalidServiceAccount(t *testing.T) {
ns := "myns"
// Build a test client that the admission plugin can use to look up the service account missing from its cache
client := testclient.NewSimpleFake()
admit := NewServiceAccount(client)
pod := &api.Pod{}
attrs := admission.NewAttributesRecord(pod, "Pod", ns, "myname", string(api.ResourcePods), "", admission.Create, nil)
err := admit.Admit(attrs)
if err == nil {
t.Errorf("Expected error for missing service account, got none")
}
}
开发者ID:MarWestermann,项目名称:gofabric8,代码行数:15,代码来源:admission_test.go
示例20: TestDescribeService
func TestDescribeService(t *testing.T) {
fake := testclient.NewSimpleFake(&api.Service{
ObjectMeta: api.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
})
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
d := ServiceDescriber{c}
out, err := d.Describe("foo", "bar")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !strings.Contains(out, "Labels:") || !strings.Contains(out, "bar") {
t.Errorf("unexpected out: %s", out)
}
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:17,代码来源:describe_test.go
注:本文中的k8s/io/kubernetes/pkg/client/testclient.NewSimpleFake函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论