本文整理汇总了Golang中github.com/openshift/origin/pkg/client/testclient.Fake类的典型用法代码示例。如果您正苦于以下问题:Golang Fake类的具体用法?Golang Fake怎么用?Golang Fake使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fake类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestDeletingImagePruner
func TestDeletingImagePruner(t *testing.T) {
flag.Lookup("v").Value.Set(fmt.Sprint(*logLevel))
tests := map[string]struct {
imageDeletionError error
}{
"no error": {},
"delete error": {
imageDeletionError: fmt.Errorf("foo"),
},
}
for name, test := range tests {
imageClient := testclient.Fake{
Err: test.imageDeletionError,
}
imagePruner := NewDeletingImagePruner(imageClient.Images())
err := imagePruner.PruneImage(&imageapi.Image{ObjectMeta: kapi.ObjectMeta{Name: "id2"}})
if test.imageDeletionError != nil {
if e, a := test.imageDeletionError, err; e != a {
t.Errorf("%s: err: expected %v, got %v", name, e, a)
}
continue
}
if e, a := 1, len(imageClient.Actions); e != a {
t.Errorf("%s: expected %d actions, got %d: %#v", name, e, a, imageClient.Actions)
continue
}
if e, a := "delete-image", imageClient.Actions[0].Action; e != a {
t.Errorf("%s: expected action %q, got %q", name, e, a)
}
}
}
开发者ID:Tlacenka,项目名称:origin,代码行数:35,代码来源:imagepruner_test.go
示例2: noAction
func noAction(kubeClient *fake.Clientset, originClient *testclient.Fake) string {
if len(kubeClient.Actions()) != 0 {
return fmt.Sprintf("unexpected actions: %v", kubeClient.Actions())
}
if len(originClient.Actions()) != 0 {
return fmt.Sprintf("unexpected actions: %v", originClient.Actions())
}
return ""
}
开发者ID:mffiedler,项目名称:origin,代码行数:9,代码来源:admission_test.go
示例3: extractDeletedGroups
func extractDeletedGroups(tc *testclient.Fake) []string {
ret := []string{}
for _, genericAction := range tc.Actions() {
switch action := genericAction.(type) {
case core.DeleteAction:
ret = append(ret, action.GetName())
}
}
return ret
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:11,代码来源:grouppruner_test.go
示例4: extractActualGroups
func extractActualGroups(tc *testclient.Fake) []*userapi.Group {
ret := []*userapi.Group{}
for _, genericAction := range tc.Actions() {
switch action := genericAction.(type) {
case ktestclient.CreateAction:
ret = append(ret, action.GetObject().(*userapi.Group))
case ktestclient.UpdateAction:
ret = append(ret, action.GetObject().(*userapi.Group))
}
}
return ret
}
开发者ID:Waxolunist,项目名称:origin,代码行数:13,代码来源:groupsyncer_test.go
示例5: checkResult
func checkResult(t *testing.T, err error, c *testclient.Fake, admitter *StatusAdmitter, targetHost string, targetObjTime unversioned.Time, targetCachedTime *time.Time, ingressInd int, actionInd int) *routeapi.Route {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(c.Actions()) != actionInd+1 {
t.Fatalf("unexpected actions: %#v", c.Actions())
}
action := c.Actions()[actionInd]
if action.GetVerb() != "update" || action.GetResource() != "routes" || action.GetSubresource() != "status" {
t.Fatalf("unexpected action: %#v", action)
}
obj := c.Actions()[actionInd].(ktestclient.UpdateAction).GetObject().(*routeapi.Route)
if len(obj.Status.Ingress) != ingressInd+1 || obj.Status.Ingress[ingressInd].Host != targetHost {
t.Fatalf("expected route reset: expected %q / actual %q -- %#v", targetHost, obj.Status.Ingress[ingressInd].Host, obj)
}
condition := obj.Status.Ingress[ingressInd].Conditions[0]
if condition.LastTransitionTime == nil || *condition.LastTransitionTime != targetObjTime || condition.Status != kapi.ConditionTrue || condition.Reason != "" {
t.Fatalf("%s: unexpected condition: %#v", targetHost, condition)
}
if targetCachedTime == nil {
if v, ok := admitter.expected.Peek(types.UID("uid1")); ok {
t.Fatalf("expected empty time: %#v", v)
}
} else {
if v, ok := admitter.expected.Peek(types.UID("uid1")); !ok || !reflect.DeepEqual(v, *targetCachedTime) {
t.Fatalf("did not record last modification time: %#v %#v", admitter.expected, v)
}
}
return obj
}
开发者ID:dcbw,项目名称:origin,代码行数:32,代码来源:status_test.go
示例6: makePass
func makePass(t *testing.T, host string, admitter *StatusAdmitter, srcObj *routeapi.Route, expectUpdate bool, conflict bool) *routeapi.Route {
// initialize a new client
var c *testclient.Fake
if conflict {
c = testclient.NewSimpleFake(&(errors.NewConflict(kapi.Resource("Route"), "route1", nil).ErrStatus))
} else {
c = testclient.NewSimpleFake(&routeapi.Route{})
}
admitter.client = c
inputObjRaw, err := kapi.Scheme.DeepCopy(srcObj)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
inputObj := inputObjRaw.(*routeapi.Route)
inputObj.Spec.Host = host
err = admitter.HandleRoute(watch.Modified, inputObj)
if expectUpdate {
now := nowFn()
var nowTime *time.Time
if !conflict {
nowTime = &now.Time
}
return checkResult(t, err, c, admitter, inputObj.Spec.Host, now, nowTime, 0, 0)
} else {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// expect the last HandleRoute not to have performed any actions
if len(c.Actions()) != 0 {
t.Fatalf("unexpected actions: %#v", c)
}
return nil
}
}
开发者ID:dcbw,项目名称:origin,代码行数:41,代码来源:status_test.go
示例7: TestDeletingImagePruner
func TestDeletingImagePruner(t *testing.T) {
flag.Lookup("v").Value.Set(fmt.Sprint(*logLevel))
tests := map[string]struct {
imageDeletionError error
}{
"no error": {},
"delete error": {
imageDeletionError: fmt.Errorf("foo"),
},
}
for name, test := range tests {
imageClient := testclient.Fake{}
imageClient.AddReactor("delete", "images", func(action ktc.Action) (handled bool, ret runtime.Object, err error) {
return true, nil, test.imageDeletionError
})
imagePruner := NewDeletingImagePruner(imageClient.Images())
err := imagePruner.PruneImage(&imageapi.Image{ObjectMeta: kapi.ObjectMeta{Name: "id2"}})
if test.imageDeletionError != nil {
if e, a := test.imageDeletionError, err; e != a {
t.Errorf("%s: err: expected %v, got %v", name, e, a)
}
continue
}
if e, a := 1, len(imageClient.Actions()); e != a {
t.Errorf("%s: expected %d actions, got %d: %#v", name, e, a, imageClient.Actions())
continue
}
if !imageClient.Actions()[0].Matches("delete", "images") {
t.Errorf("%s: expected action %s, got %v", name, "delete-images", imageClient.Actions()[0])
}
}
}
开发者ID:carriercomm,项目名称:origin,代码行数:36,代码来源:imagepruner_test.go
示例8: TestCreateImageImport
//.........这里部分代码省略.........
stream: &imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Name: "testis",
Namespace: "other",
},
Spec: imageapi.ImageStreamSpec{
Tags: map[string]imageapi.TagReference{
"mytag": {
From: &kapi.ObjectReference{Kind: "ImageStreamTag", Name: "someimage:mytag"},
},
},
},
},
err: "tag \"mytag\" points to existing ImageStreamTag \"someimage:mytag\", it cannot be re-imported",
},
"use insecure annotation": {
name: "testis",
stream: &imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Name: "testis",
Namespace: "other",
Annotations: map[string]string{imageapi.InsecureRepositoryAnnotation: "true"},
},
Spec: imageapi.ImageStreamSpec{
DockerImageRepository: "repo.com/somens/someimage",
Tags: make(map[string]imageapi.TagReference),
},
},
expectedImages: []imageapi.ImageImportSpec{{
From: kapi.ObjectReference{Kind: "DockerImage", Name: "repo.com/somens/someimage"},
To: &kapi.LocalObjectReference{Name: "latest"},
ImportPolicy: imageapi.TagImportPolicy{Insecure: true},
}},
},
"insecure flag overrides insecure annotation": {
name: "testis",
insecure: newBool(false),
stream: &imageapi.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Name: "testis",
Namespace: "other",
Annotations: map[string]string{imageapi.InsecureRepositoryAnnotation: "true"},
},
Spec: imageapi.ImageStreamSpec{
DockerImageRepository: "repo.com/somens/someimage",
Tags: make(map[string]imageapi.TagReference),
},
},
expectedImages: []imageapi.ImageImportSpec{{
From: kapi.ObjectReference{Kind: "DockerImage", Name: "repo.com/somens/someimage"},
To: &kapi.LocalObjectReference{Name: "latest"},
ImportPolicy: imageapi.TagImportPolicy{Insecure: false},
}},
},
}
for name, test := range testCases {
var fake *testclient.Fake
if test.stream == nil {
fake = testclient.NewSimpleFake()
} else {
fake = testclient.NewSimpleFake(test.stream)
}
o := ImportImageOptions{
Target: test.name,
From: test.from,
All: test.all,
Insecure: test.insecure,
Confirm: test.confirm,
isClient: fake.ImageStreams(""),
}
// we need to run Validate, because it sets appropriate Name and Tag
if err := o.Validate(&cobra.Command{}); err != nil {
t.Errorf("%s: unexpected error: %v", name, err)
}
_, isi, err := o.createImageImport()
// check errors
if len(test.err) > 0 {
if err == nil || !strings.Contains(err.Error(), test.err) {
t.Errorf("%s: unexpected error: expected %s, got %v", name, test.err, err)
}
if isi != nil {
t.Errorf("%s: unexpected import spec: expected nil, got %#v", name, isi)
}
continue
}
if len(test.err) == 0 && err != nil {
t.Errorf("%s: unexpected error: %v", name, err)
continue
}
// check values
if !listEqual(isi.Spec.Images, test.expectedImages) {
t.Errorf("%s: unexpected import images, expected %#v, got %#v", name, test.expectedImages, isi.Spec.Images)
}
if !kapi.Semantic.DeepEqual(isi.Spec.Repository, test.expectedRepository) {
t.Errorf("%s: unexpected import repository, expected %#v, got %#v", name, test.expectedRepository, isi.Spec.Repository)
}
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:101,代码来源:importimage_test.go
注:本文中的github.com/openshift/origin/pkg/client/testclient.Fake类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论