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


Golang Fake.ImageStreams方法代碼示例

本文整理匯總了Golang中github.com/openshift/origin/pkg/client/testclient.Fake.ImageStreams方法的典型用法代碼示例。如果您正苦於以下問題:Golang Fake.ImageStreams方法的具體用法?Golang Fake.ImageStreams怎麽用?Golang Fake.ImageStreams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/openshift/origin/pkg/client/testclient.Fake的用法示例。


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

示例1: 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.ImageStreams方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。