本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned/testclient.AddObjectsFromPath函数的典型用法代码示例。如果您正苦于以下问题:Golang AddObjectsFromPath函数的具体用法?Golang AddObjectsFromPath怎么用?Golang AddObjectsFromPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddObjectsFromPath函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNewClient
func TestNewClient(t *testing.T) {
o := testclient.NewObjects(kapi.Scheme, kapi.Codecs.UniversalDecoder())
if err := testclient.AddObjectsFromPath("../../../test/integration/testdata/test-deployment-config.yaml", o, kapi.Codecs.UniversalDecoder()); err != nil {
t.Fatal(err)
}
oc, _ := NewFixtureClients(o)
list, err := oc.DeploymentConfigs("test").List(kapi.ListOptions{})
if err != nil {
t.Fatal(err)
}
if len(list.Items) != 1 {
t.Fatalf("unexpected list %#v", list)
}
// same result
list, err = oc.DeploymentConfigs("test").List(kapi.ListOptions{})
if err != nil {
t.Fatal(err)
}
if len(list.Items) != 1 {
t.Fatalf("unexpected list %#v", list)
}
t.Logf("list: %#v", list)
}
示例2: TestNewClient
func TestNewClient(t *testing.T) {
o := testclient.NewObjects(kapi.Scheme, kapi.Scheme)
if err := testclient.AddObjectsFromPath("../../../test/integration/fixtures/test-deployment-config.json", o, kapi.Scheme); err != nil {
t.Fatal(err)
}
oc, _ := NewFixtureClients(o)
list, err := oc.DeploymentConfigs("test").List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatal(err)
}
if len(list.Items) != 1 {
t.Fatalf("unexpected list %#v", list)
}
// same result
list, err = oc.DeploymentConfigs("test").List(labels.Everything(), fields.Everything())
if err != nil {
t.Fatal(err)
}
if len(list.Items) != 1 {
t.Fatalf("unexpected list %#v", list)
}
t.Logf("list: %#v", list)
}
示例3: TestChainDescriber
//.........这里部分代码省略.........
"}",
},
expectedErr: nil,
},
{
testName: "human readable - multiple triggers - triggeronly",
name: "ruby-20-centos7",
defaultNamespace: "test",
tag: "latest",
path: "../../../../pkg/cmd/experimental/buildchain/test/multiple-trigger-bcs.yaml",
namespaces: sets.NewString("test"),
humanReadable: map[string]int{
"imagestreamtag/ruby-20-centos7:latest": 1,
"\tbc/parent1": 1,
"\t\timagestreamtag/parent1img:latest": 1,
"\t\t\tbc/child2": 2,
"\t\t\t\timagestreamtag/child2img:latest": 2,
"\tbc/parent2": 1,
"\t\timagestreamtag/parent2img:latest": 1,
"\t\t\tbc/child3": 2,
"\t\t\t\timagestreamtag/child3img:latest": 2,
"\t\t\tbc/child1": 1,
"\t\t\t\timagestreamtag/child1img:latest": 1,
"\tbc/parent3": 1,
"\t\timagestreamtag/parent3img:latest": 1,
},
},
{
testName: "human readable - multiple triggers - trigger+input",
name: "ruby-20-centos7",
defaultNamespace: "test",
tag: "latest",
path: "../../../../pkg/cmd/experimental/buildchain/test/multiple-trigger-bcs.yaml",
namespaces: sets.NewString("test"),
includeInputImg: true,
humanReadable: map[string]int{
"imagestreamtag/ruby-20-centos7:latest": 1,
"\tbc/parent1": 1,
"\t\timagestreamtag/parent1img:latest": 1,
"\t\t\tbc/child1": 2,
"\t\t\t\timagestreamtag/child1img:latest": 2,
"\t\t\tbc/child2": 2,
"\t\t\t\timagestreamtag/child2img:latest": 2,
"\t\t\tbc/child3": 3,
"\t\t\t\timagestreamtag/child3img:latest": 3,
"\tbc/parent2": 1,
"\t\timagestreamtag/parent2img:latest": 1,
"\tbc/parent3": 1,
"\t\timagestreamtag/parent3img:latest": 1,
},
},
}
for _, test := range tests {
o := ktestclient.NewObjects(kapi.Scheme, kapi.Scheme)
if len(test.path) > 0 {
if err := ktestclient.AddObjectsFromPath(test.path, o, kapi.Scheme); err != nil {
t.Fatal(err)
}
}
oc, _ := testclient.NewFixtureClients(o)
ist := imagegraph.MakeImageStreamTagObjectMeta(test.defaultNamespace, test.name, test.tag)
desc, err := NewChainDescriber(oc, test.namespaces, test.output).Describe(ist, test.includeInputImg)
t.Logf("%s: output:\n%s\n\n", test.testName, desc)
if err != test.expectedErr {
t.Fatalf("%s: error mismatch: expected %v, got %v", test.testName, test.expectedErr, err)
}
got := strings.Split(desc, "\n")
switch test.output {
case "dot":
if len(test.dot) != len(got) {
t.Fatalf("%s: expected %d lines, got %d:\n%s", test.testName, len(test.dot), len(got), desc)
}
for _, expected := range test.dot {
if !strings.Contains(desc, expected) {
t.Errorf("%s: unexpected description:\n%s\nexpected line in it:\n%s", test.testName, desc, expected)
}
}
case "":
if lenReadable(test.humanReadable) != len(got) {
t.Fatalf("%s: expected %d lines, got %d:\n%s", test.testName, lenReadable(test.humanReadable), len(got), desc)
}
for _, line := range got {
if _, ok := test.humanReadable[line]; !ok {
t.Errorf("%s: unexpected line: %s", test.testName, line)
}
test.humanReadable[line]--
}
for line, cnt := range test.humanReadable {
if cnt != 0 {
t.Errorf("%s: unexpected number of lines for [%s]: %d", test.testName, line, cnt)
}
}
}
}
}
示例4: TestProjectStatus
//.........这里部分代码省略.........
"build #1 running for about a minute",
"- 7a4f354: Prepare v1beta3 Template types (Roy Programmer <[email protected]>)",
"View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.",
},
Time: mustParseTime("2015-04-06T21:20:03Z"),
},
"with real deployments": {
Path: "../../../../test/fixtures/app-scenarios/new-project-deployed-app.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
"In project example on server https://example.com:8443\n",
"svc/database - 172.30.17.240:5434 -> 3306",
"https://www.test.com (redirects) to pod port 8080 (svc/frontend)",
"http://frontend-example.router.default.svc.cluster.local to pod port 8080 (!)",
"svc/database-external (all nodes):31000 -> 3306",
"database test deploys",
"frontend deploys",
"with docker.io/centos/ruby-22-centos7:latest",
"deployment #3 pending on image",
"deployment #2 failed less than a second ago: unable to contact server - 0/1 pods",
"deployment #1 deployed less than a second ago",
"test deployment #2 running for 7 seconds - 2/1 pods",
"test deployment #1 deployed 8 seconds ago",
"* bc/ruby-sample-build is pushing to istag/origin-ruby-sample:latest, but the image stream for that tag does not exist.",
"* The image trigger for dc/frontend will have no effect because is/origin-ruby-sample does not exist",
"* route/frontend was not accepted by router \"other\": (HostAlreadyClaimed)",
"* dc/database has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful.",
"View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.",
},
Time: mustParseTime("2015-04-07T04:12:25Z"),
},
"restarting pod": {
Path: "../../../api/graph/test/restarting-pod.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
`container "ruby-helloworld" in pod/frontend-app-1-bjwh8 has restarted 8 times`,
`container "gitlab-ce" in pod/gitlab-ce-1-lc411 is crash-looping`,
`oc logs -p gitlab-ce-1-lc411 -c gitlab-ce`, // verifies we print the log command
`policycommand example default`, // verifies that we print the help command
},
},
"cross namespace reference": {
Path: "../../../api/graph/test/different-project-image-deployment.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
// If there was a warning we wouldn't get the following message. Since we ignore cross-namespace
// links by default, there should be no warning here.
`View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.`,
},
},
}
oldTimeFn := timeNowFn
defer func() { timeNowFn = oldTimeFn }()
for k, test := range testCases {
timeNowFn = func() time.Time {
if !test.Time.IsZero() {
return test.Time
}
return time.Now()
}
o := ktestclient.NewObjects(kapi.Scheme, kapi.Codecs.UniversalDecoder())
if len(test.Path) > 0 {
if err := ktestclient.AddObjectsFromPath(test.Path, o, kapi.Codecs.UniversalDecoder()); err != nil {
t.Fatal(err)
}
}
for _, obj := range test.Extra {
o.Add(obj)
}
oc, kc := testclient.NewFixtureClients(o)
d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443", Suggest: true, LogsCommandName: "oc logs -p", SecurityPolicyCommandFormat: "policycommand %s %s"}
out, err := d.Describe("example", "")
if !test.ErrFn(err) {
t.Errorf("%s: unexpected error: %v", k, err)
}
if err != nil {
continue
}
for _, s := range test.Contains {
if !strings.Contains(out, s) {
t.Errorf("%s: did not have %q:\n%s\n---", k, s, out)
}
}
}
}
示例5: TestExampleObjects
func TestExampleObjects(t *testing.T) {
scenarios := map[string]struct {
expected interface{}
}{
"claims/claim-01.yaml": {
expected: &api.PersistentVolumeClaim{
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("3Gi"),
},
},
},
},
},
"claims/claim-02.yaml": {
expected: &api.PersistentVolumeClaim{
Spec: api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Resources: api.ResourceRequirements{
Requests: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("8Gi"),
},
},
},
},
},
"volumes/local-01.yaml": {
expected: &api.PersistentVolume{
Spec: api.PersistentVolumeSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("10Gi"),
},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{
Path: "/tmp/data01",
},
},
},
},
},
"volumes/local-02.yaml": {
expected: &api.PersistentVolume{
Spec: api.PersistentVolumeSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce},
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse("8Gi"),
},
PersistentVolumeSource: api.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{
Path: "/tmp/data02",
},
},
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
},
},
},
}
for name, scenario := range scenarios {
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/"+name, o, api.Scheme); err != nil {
t.Fatal(err)
}
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, api.RESTMapper)}
if reflect.TypeOf(scenario.expected) == reflect.TypeOf(&api.PersistentVolumeClaim{}) {
pvc, err := client.PersistentVolumeClaims("ns").Get("doesntmatter")
if err != nil {
t.Errorf("Error retrieving object: %v", err)
}
expected := scenario.expected.(*api.PersistentVolumeClaim)
if pvc.Spec.AccessModes[0] != expected.Spec.AccessModes[0] {
t.Errorf("Unexpected mismatch. Got %v wanted %v", pvc.Spec.AccessModes[0], expected.Spec.AccessModes[0])
}
aQty := pvc.Spec.Resources.Requests[api.ResourceStorage]
bQty := expected.Spec.Resources.Requests[api.ResourceStorage]
aSize := aQty.Value()
bSize := bQty.Value()
if aSize != bSize {
t.Errorf("Unexpected mismatch. Got %v wanted %v", aSize, bSize)
}
}
if reflect.TypeOf(scenario.expected) == reflect.TypeOf(&api.PersistentVolume{}) {
pv, err := client.PersistentVolumes().Get("doesntmatter")
if err != nil {
t.Errorf("Error retrieving object: %v", err)
}
expected := scenario.expected.(*api.PersistentVolume)
if pv.Spec.AccessModes[0] != expected.Spec.AccessModes[0] {
t.Errorf("Unexpected mismatch. Got %v wanted %v", pv.Spec.AccessModes[0], expected.Spec.AccessModes[0])
}
//.........这里部分代码省略.........
示例6: TestMissingFromIndex
func TestMissingFromIndex(t *testing.T) {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/volumes/local-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, api.RESTMapper)}
pv, err := client.PersistentVolumes().Get("any")
if err != nil {
t.Errorf("Unexpected error getting PV from client: %v", err)
}
claim, error := client.PersistentVolumeClaims("ns").Get("any")
if error != nil {
t.Errorf("Unexpected error getting PVC from client: %v", err)
}
volumeIndex := NewPersistentVolumeOrderedIndex()
mockClient := &mockBinderClient{
volume: pv,
claim: claim,
}
// the default value of the PV is Pending.
// if has previously been processed by the binder, it's status in etcd would be Available.
// Only Pending volumes were being indexed and made ready for claims.
pv.Status.Phase = api.VolumeAvailable
// adds the volume to the index, making the volume available
syncVolume(volumeIndex, mockClient, pv)
if pv.Status.Phase != api.VolumeAvailable {
t.Errorf("Expected phase %s but got %s", api.VolumeBound, pv.Status.Phase)
}
// an initial sync for a claim will bind it to an unbound volume, triggers state change
err = syncClaim(volumeIndex, mockClient, claim)
if err != nil {
t.Fatalf("Expected Clam to be bound, instead got an error: %+v\n", err)
}
// state change causes another syncClaim to update statuses
syncClaim(volumeIndex, mockClient, claim)
// claim updated volume's status, causing an update and syncVolume call
syncVolume(volumeIndex, mockClient, pv)
if pv.Spec.ClaimRef == nil {
t.Errorf("Expected ClaimRef but got nil for pv.Status.ClaimRef: %+v\n", pv)
}
if pv.Status.Phase != api.VolumeBound {
t.Errorf("Expected phase %s but got %s", api.VolumeBound, pv.Status.Phase)
}
if claim.Status.Phase != api.ClaimBound {
t.Errorf("Expected phase %s but got %s", api.ClaimBound, claim.Status.Phase)
}
if len(claim.Status.AccessModes) != len(pv.Spec.AccessModes) {
t.Errorf("Expected phase %s but got %s", api.ClaimBound, claim.Status.Phase)
}
if claim.Status.AccessModes[0] != pv.Spec.AccessModes[0] {
t.Errorf("Expected access mode %s but got %s", claim.Status.AccessModes[0], pv.Spec.AccessModes[0])
}
// pretend the user deleted their claim
mockClient.claim = nil
syncVolume(volumeIndex, mockClient, pv)
if pv.Status.Phase != api.VolumeReleased {
t.Errorf("Expected phase %s but got %s", api.VolumeReleased, pv.Status.Phase)
}
}
示例7: TestBindingWithExamples
func TestBindingWithExamples(t *testing.T) {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/volumes/local-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
client := &testclient.Fake{ReactFn: testclient.ObjectReaction(o, api.RESTMapper)}
pv, err := client.PersistentVolumes().Get("any")
pv.Spec.PersistentVolumeReclaimPolicy = api.PersistentVolumeReclaimRecycle
if err != nil {
t.Errorf("Unexpected error getting PV from client: %v", err)
}
claim, error := client.PersistentVolumeClaims("ns").Get("any")
if error != nil {
t.Errorf("Unexpected error getting PVC from client: %v", err)
}
volumeIndex := NewPersistentVolumeOrderedIndex()
mockClient := &mockBinderClient{
volume: pv,
claim: claim,
}
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
recycler := &PersistentVolumeRecycler{
kubeClient: client,
client: mockClient,
pluginMgr: plugMgr,
}
// adds the volume to the index, making the volume available
syncVolume(volumeIndex, mockClient, pv)
if pv.Status.Phase != api.VolumeAvailable {
t.Errorf("Expected phase %s but got %s", api.VolumeBound, pv.Status.Phase)
}
// an initial sync for a claim will bind it to an unbound volume, triggers state change
syncClaim(volumeIndex, mockClient, claim)
// state change causes another syncClaim to update statuses
syncClaim(volumeIndex, mockClient, claim)
// claim updated volume's status, causing an update and syncVolume call
syncVolume(volumeIndex, mockClient, pv)
if pv.Spec.ClaimRef == nil {
t.Errorf("Expected ClaimRef but got nil for pv.Status.ClaimRef: %+v\n", pv)
}
if pv.Status.Phase != api.VolumeBound {
t.Errorf("Expected phase %s but got %s", api.VolumeBound, pv.Status.Phase)
}
if claim.Status.Phase != api.ClaimBound {
t.Errorf("Expected phase %s but got %s", api.ClaimBound, claim.Status.Phase)
}
if len(claim.Status.AccessModes) != len(pv.Spec.AccessModes) {
t.Errorf("Expected phase %s but got %s", api.ClaimBound, claim.Status.Phase)
}
if claim.Status.AccessModes[0] != pv.Spec.AccessModes[0] {
t.Errorf("Expected access mode %s but got %s", claim.Status.AccessModes[0], pv.Spec.AccessModes[0])
}
// pretend the user deleted their claim
mockClient.claim = nil
syncVolume(volumeIndex, mockClient, pv)
if pv.Status.Phase != api.VolumeReleased {
t.Errorf("Expected phase %s but got %s", api.VolumeReleased, pv.Status.Phase)
}
if pv.Spec.ClaimRef == nil {
t.Errorf("Expected non-nil ClaimRef: %+v", pv.Spec)
}
mockClient.volume = pv
// released volumes with a PersistentVolumeReclaimPolicy (recycle/delete) can have further processing
err = recycler.reclaimVolume(pv)
if err != nil {
t.Errorf("Unexpected error reclaiming volume: %+v", err)
}
if pv.Status.Phase != api.VolumePending {
t.Errorf("Expected phase %s but got %s", api.VolumePending, pv.Status.Phase)
}
// after the recycling changes the phase to Pending, the binder picks up again
// to remove any vestiges of binding and make the volume Available again
syncVolume(volumeIndex, mockClient, pv)
if pv.Status.Phase != api.VolumeAvailable {
t.Errorf("Expected phase %s but got %s", api.VolumeAvailable, pv.Status.Phase)
}
if pv.Spec.ClaimRef != nil {
t.Errorf("Expected nil ClaimRef: %+v", pv.Spec)
//.........这里部分代码省略.........
示例8: TestBindingWithExamples
func TestBindingWithExamples(t *testing.T) {
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/volumes/local-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
}
client := &testclient.Fake{}
client.AddReactor("*", "*", testclient.ObjectReaction(o, api.RESTMapper))
pv, err := client.PersistentVolumes().Get("any")
pv.Spec.PersistentVolumeReclaimPolicy = api.PersistentVolumeReclaimRecycle
if err != nil {
t.Errorf("Unexpected error getting PV from client: %v", err)
}
pv.ObjectMeta.SelfLink = testapi.Default.SelfLink("pv", "")
// the default value of the PV is Pending. if processed at least once, its status in etcd is Available.
// There was a bug where only Pending volumes were being indexed and made ready for claims.
// Test that !Pending gets correctly added
pv.Status.Phase = api.VolumeAvailable
claim, error := client.PersistentVolumeClaims("ns").Get("any")
if error != nil {
t.Errorf("Unexpected error getting PVC from client: %v", err)
}
claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", "")
volumeIndex := NewPersistentVolumeOrderedIndex()
mockClient := &mockBinderClient{
volume: pv,
claim: claim,
}
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
recycler := &PersistentVolumeRecycler{
kubeClient: client,
client: mockClient,
pluginMgr: plugMgr,
}
// adds the volume to the index, making the volume available
syncVolume(volumeIndex, mockClient, pv)
if mockClient.volume.Status.Phase != api.VolumeAvailable {
t.Errorf("Expected phase %s but got %s", api.VolumeAvailable, mockClient.volume.Status.Phase)
}
// an initial sync for a claim will bind it to an unbound volume
syncClaim(volumeIndex, mockClient, claim)
// bind expected on pv.Spec but status update hasn't happened yet
if mockClient.volume.Spec.ClaimRef == nil {
t.Errorf("Expected ClaimRef but got nil for pv.Status.ClaimRef\n")
}
if mockClient.volume.Status.Phase != api.VolumeAvailable {
t.Errorf("Expected phase %s but got %s", api.VolumeAvailable, mockClient.volume.Status.Phase)
}
if mockClient.claim.Spec.VolumeName != pv.Name {
t.Errorf("Expected claim.Spec.VolumeName %s but got %s", mockClient.claim.Spec.VolumeName, pv.Name)
}
if mockClient.claim.Status.Phase != api.ClaimBound {
t.Errorf("Expected phase %s but got %s", api.ClaimBound, claim.Status.Phase)
}
// state changes in pvc triggers sync that sets pv attributes to pvc.Status
syncClaim(volumeIndex, mockClient, claim)
if len(mockClient.claim.Status.AccessModes) == 0 {
t.Errorf("Expected %d access modes but got 0", len(pv.Spec.AccessModes))
}
// persisting the bind to pv.Spec.ClaimRef triggers a sync
syncVolume(volumeIndex, mockClient, mockClient.volume)
if mockClient.volume.Status.Phase != api.VolumeBound {
t.Errorf("Expected phase %s but got %s", api.VolumeBound, mockClient.volume.Status.Phase)
}
// pretend the user deleted their claim. periodic resync picks it up.
mockClient.claim = nil
syncVolume(volumeIndex, mockClient, mockClient.volume)
if mockClient.volume.Status.Phase != api.VolumeReleased {
t.Errorf("Expected phase %s but got %s", api.VolumeReleased, mockClient.volume.Status.Phase)
}
// released volumes with a PersistentVolumeReclaimPolicy (recycle/delete) can have further processing
err = recycler.reclaimVolume(mockClient.volume)
if err != nil {
t.Errorf("Unexpected error reclaiming volume: %+v", err)
}
if mockClient.volume.Status.Phase != api.VolumePending {
t.Errorf("Expected phase %s but got %s", api.VolumePending, mockClient.volume.Status.Phase)
}
// after the recycling changes the phase to Pending, the binder picks up again
// to remove any vestiges of binding and make the volume Available again
syncVolume(volumeIndex, mockClient, mockClient.volume)
//.........这里部分代码省略.........
示例9: TestProjectStatus
//.........这里部分代码省略.........
"svc/sinatra-example-1 - 172.30.17.47:8080",
"builds git://github.com",
"with docker.io/centos/ruby-22-centos7:latest",
"#1 build running for about a minute",
"#1 deployment waiting on image or update",
"To see more, use",
},
Time: mustParseTime("2015-04-06T21:20:03Z"),
},
"a/b test DeploymentConfig": {
Path: "../../../../test/fixtures/app-scenarios/new-project-two-deployment-configs.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
"In project example on server https://example.com:8443\n",
"svc/sinatra-app-example - 172.30.17.49:8080",
"sinatra-app-example-a deploys",
"sinatra-app-example-b deploys",
"with docker.io/centos/ruby-22-centos7:latest",
"#1 build running for about a minute",
"- 7a4f354: Prepare v1beta3 Template types (Roy Programmer <[email protected]>)",
"To see more, use",
},
Time: mustParseTime("2015-04-06T21:20:03Z"),
},
"with real deployments": {
Path: "../../../../test/fixtures/app-scenarios/new-project-deployed-app.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
"In project example on server https://example.com:8443\n",
"svc/database - 172.30.17.240:5434 -> 3306",
"exposed by route/frontend on pod port 8080",
"svc/frontend - 172.30.17.154:5432 -> 8080",
"database deploys",
"frontend deploys",
"with docker.io/centos/ruby-22-centos7:latest",
"#2 deployment failed less than a second ago: unable to contact server - 0/1 pods",
"#2 deployment running for 7 seconds - 2/1 pods",
"#1 deployed 8 seconds ago",
"#1 deployed less than a second ago",
"To see more, use",
},
Time: mustParseTime("2015-04-07T04:12:25Z"),
},
"restarting pod": {
Path: "../../../api/graph/test/restarting-pod.yaml",
Extra: []runtime.Object{
&projectapi.Project{
ObjectMeta: kapi.ObjectMeta{Name: "example", Namespace: ""},
},
},
ErrFn: func(err error) bool { return err == nil },
Contains: []string{
`container "ruby-helloworld" in pod/frontend-app-1-bjwh8 has restarted 8 times`,
},
},
}
oldTimeFn := timeNowFn
defer func() { timeNowFn = oldTimeFn }()
for k, test := range testCases {
timeNowFn = func() time.Time {
if !test.Time.IsZero() {
return test.Time
}
return time.Now()
}
o := ktestclient.NewObjects(kapi.Scheme, kapi.Scheme)
if len(test.Path) > 0 {
if err := ktestclient.AddObjectsFromPath(test.Path, o, kapi.Scheme); err != nil {
t.Fatal(err)
}
}
for _, obj := range test.Extra {
o.Add(obj)
}
oc, kc := testclient.NewFixtureClients(o)
d := ProjectStatusDescriber{C: oc, K: kc, Server: "https://example.com:8443"}
out, err := d.Describe("example", "")
if !test.ErrFn(err) {
t.Errorf("%s: unexpected error: %v", k, err)
}
if err != nil {
continue
}
for _, s := range test.Contains {
if !strings.Contains(out, s) {
t.Errorf("%s: did not have %q:\n%s\n---", k, s, out)
}
}
}
}