123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732 |
- /*
- Copyright 2014 The Kubernetes Authors.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- package kubectl
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "reflect"
- "strings"
- "testing"
- "time"
- "k8s.io/kubernetes/federation/apis/federation"
- fed_fake "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset/fake"
- "k8s.io/kubernetes/pkg/api"
- "k8s.io/kubernetes/pkg/api/resource"
- "k8s.io/kubernetes/pkg/api/unversioned"
- "k8s.io/kubernetes/pkg/apis/extensions"
- "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
- client "k8s.io/kubernetes/pkg/client/unversioned"
- "k8s.io/kubernetes/pkg/client/unversioned/testclient"
- )
- type describeClient struct {
- T *testing.T
- Namespace string
- Err error
- client.Interface
- }
- func TestDescribePod(t *testing.T) {
- fake := testclient.NewSimpleFake(&api.Pod{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- })
- c := &describeClient{T: t, Namespace: "foo", Interface: fake}
- d := PodDescriber{c}
- out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "bar") || !strings.Contains(out, "Status:") {
- t.Errorf("unexpected out: %s", out)
- }
- }
- func TestDescribePodTolerations(t *testing.T) {
- podTolerations := []api.Toleration{{Key: "key1", Value: "value1"},
- {Key: "key2", Value: "value2"}}
- pt, _ := json.Marshal(podTolerations)
- fake := testclient.NewSimpleFake(&api.Pod{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- Annotations: map[string]string{
- api.TolerationsAnnotationKey: string(pt),
- },
- },
- })
- c := &describeClient{T: t, Namespace: "foo", Interface: fake}
- d := PodDescriber{c}
- out, err := d.Describe("foo", "bar", DescriberSettings{})
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "key1=value1") || !strings.Contains(out, "key2=value2") || !strings.Contains(out, "Tolerations:") {
- t.Errorf("unexpected out: %s", out)
- }
- }
- 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", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "Labels:") || !strings.Contains(out, "bar") {
- t.Errorf("unexpected out: %s", out)
- }
- }
- func TestPodDescribeResultsSorted(t *testing.T) {
- // Arrange
- fake := testclient.NewSimpleFake(&api.EventList{
- Items: []api.Event{
- {
- Source: api.EventSource{Component: "kubelet"},
- Message: "Item 1",
- FirstTimestamp: unversioned.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
- LastTimestamp: unversioned.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
- Count: 1,
- Type: api.EventTypeNormal,
- },
- {
- Source: api.EventSource{Component: "scheduler"},
- Message: "Item 2",
- FirstTimestamp: unversioned.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
- LastTimestamp: unversioned.NewTime(time.Date(1987, time.June, 17, 0, 0, 0, 0, time.UTC)),
- Count: 1,
- Type: api.EventTypeNormal,
- },
- {
- Source: api.EventSource{Component: "kubelet"},
- Message: "Item 3",
- FirstTimestamp: unversioned.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
- LastTimestamp: unversioned.NewTime(time.Date(2002, time.December, 25, 0, 0, 0, 0, time.UTC)),
- Count: 1,
- Type: api.EventTypeNormal,
- },
- },
- })
- c := &describeClient{T: t, Namespace: "foo", Interface: fake}
- d := PodDescriber{c}
- // Act
- out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
- // Assert
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- VerifyDatesInOrder(out, "\n" /* rowDelimiter */, "\t" /* columnDelimiter */, t)
- }
- func TestDescribeContainers(t *testing.T) {
- testCases := []struct {
- container api.Container
- status api.ContainerStatus
- expectedElements []string
- }{
- // Running state.
- {
- container: api.Container{Name: "test", Image: "image"},
- status: api.ContainerStatus{
- Name: "test",
- State: api.ContainerState{
- Running: &api.ContainerStateRunning{
- StartedAt: unversioned.NewTime(time.Now()),
- },
- },
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Running", "Ready", "True", "Restart Count", "7", "Image", "image", "Started"},
- },
- // Waiting state.
- {
- container: api.Container{Name: "test", Image: "image"},
- status: api.ContainerStatus{
- Name: "test",
- State: api.ContainerState{
- Waiting: &api.ContainerStateWaiting{
- Reason: "potato",
- },
- },
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "Reason", "potato"},
- },
- // Terminated state.
- {
- container: api.Container{Name: "test", Image: "image"},
- status: api.ContainerStatus{
- Name: "test",
- State: api.ContainerState{
- Terminated: &api.ContainerStateTerminated{
- StartedAt: unversioned.NewTime(time.Now()),
- FinishedAt: unversioned.NewTime(time.Now()),
- Reason: "potato",
- ExitCode: 2,
- },
- },
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Terminated", "Ready", "True", "Restart Count", "7", "Image", "image", "Reason", "potato", "Started", "Finished", "Exit Code", "2"},
- },
- // Last Terminated
- {
- container: api.Container{Name: "test", Image: "image"},
- status: api.ContainerStatus{
- Name: "test",
- State: api.ContainerState{
- Running: &api.ContainerStateRunning{
- StartedAt: unversioned.NewTime(time.Now()),
- },
- },
- LastTerminationState: api.ContainerState{
- Terminated: &api.ContainerStateTerminated{
- StartedAt: unversioned.NewTime(time.Now().Add(time.Second * 3)),
- FinishedAt: unversioned.NewTime(time.Now()),
- Reason: "crashing",
- ExitCode: 3,
- },
- },
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Terminated", "Ready", "True", "Restart Count", "7", "Image", "image", "Started", "Finished", "Exit Code", "2", "crashing", "3"},
- },
- // No state defaults to waiting.
- {
- container: api.Container{Name: "test", Image: "image"},
- status: api.ContainerStatus{
- Name: "test",
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image"},
- },
- // Env
- {
- container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}},
- status: api.ContainerStatus{
- Name: "test",
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz"},
- },
- // Command
- {
- container: api.Container{Name: "test", Image: "image", Command: []string{"sleep", "1000"}},
- status: api.ContainerStatus{
- Name: "test",
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "sleep", "1000"},
- },
- // Args
- {
- container: api.Container{Name: "test", Image: "image", Args: []string{"time", "1000"}},
- status: api.ContainerStatus{
- Name: "test",
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "time", "1000"},
- },
- // Using limits.
- {
- container: api.Container{
- Name: "test",
- Image: "image",
- Resources: api.ResourceRequirements{
- Limits: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("1000"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("4G"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("20G"),
- },
- },
- },
- status: api.ContainerStatus{
- Name: "test",
- Ready: true,
- RestartCount: 7,
- },
- expectedElements: []string{"cpu", "1k", "memory", "4G", "storage", "20G"},
- },
- // Using requests.
- {
- container: api.Container{
- Name: "test",
- Image: "image",
- Resources: api.ResourceRequirements{
- Requests: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("1000"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("4G"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("20G"),
- },
- },
- },
- expectedElements: []string{"cpu", "1k", "memory", "4G", "storage", "20G"},
- },
- }
- for i, testCase := range testCases {
- out := new(bytes.Buffer)
- pod := api.Pod{
- Spec: api.PodSpec{
- Containers: []api.Container{testCase.container},
- },
- Status: api.PodStatus{
- ContainerStatuses: []api.ContainerStatus{testCase.status},
- },
- }
- describeContainers("Containers", pod.Spec.Containers, pod.Status.ContainerStatuses, EnvValueRetriever(&pod), out, "")
- output := out.String()
- for _, expected := range testCase.expectedElements {
- if !strings.Contains(output, expected) {
- t.Errorf("Test case %d: expected to find %q in output: %q", i, expected, output)
- }
- }
- }
- }
- func TestDescribers(t *testing.T) {
- first := &api.Event{}
- second := &api.Pod{}
- var third *api.Pod
- testErr := fmt.Errorf("test")
- d := Describers{}
- d.Add(
- func(e *api.Event, p *api.Pod) (string, error) {
- if e != first {
- t.Errorf("first argument not equal: %#v", e)
- }
- if p != second {
- t.Errorf("second argument not equal: %#v", p)
- }
- return "test", testErr
- },
- )
- if out, err := d.DescribeObject(first, second); out != "test" || err != testErr {
- t.Errorf("unexpected result: %s %v", out, err)
- }
- if out, err := d.DescribeObject(first, second, third); out != "" || err == nil {
- t.Errorf("unexpected result: %s %v", out, err)
- } else {
- if noDescriber, ok := err.(ErrNoDescriber); ok {
- if !reflect.DeepEqual(noDescriber.Types, []string{"*api.Event", "*api.Pod", "*api.Pod"}) {
- t.Errorf("unexpected describer: %v", err)
- }
- } else {
- t.Errorf("unexpected error type: %v", err)
- }
- }
- d.Add(
- func(e *api.Event) (string, error) {
- if e != first {
- t.Errorf("first argument not equal: %#v", e)
- }
- return "simpler", testErr
- },
- )
- if out, err := d.DescribeObject(first); out != "simpler" || err != testErr {
- t.Errorf("unexpected result: %s %v", out, err)
- }
- }
- func TestDefaultDescribers(t *testing.T) {
- out, err := DefaultObjectDescriber.DescribeObject(&api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}})
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "foo") {
- t.Errorf("unexpected output: %s", out)
- }
- out, err = DefaultObjectDescriber.DescribeObject(&api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}})
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "foo") {
- t.Errorf("unexpected output: %s", out)
- }
- out, err = DefaultObjectDescriber.DescribeObject(&api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "foo") {
- t.Errorf("unexpected output: %s", out)
- }
- out, err = DefaultObjectDescriber.DescribeObject(&api.Node{ObjectMeta: api.ObjectMeta{Name: "foo"}})
- if err != nil {
- t.Fatalf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "foo") {
- t.Errorf("unexpected output: %s", out)
- }
- }
- func TestGetPodsTotalRequests(t *testing.T) {
- testCases := []struct {
- pods *api.PodList
- expectedReqs, expectedLimits map[api.ResourceName]resource.Quantity
- }{
- {
- pods: &api.PodList{
- Items: []api.Pod{
- {
- Spec: api.PodSpec{
- Containers: []api.Container{
- {
- Resources: api.ResourceRequirements{
- Requests: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("1"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("300Mi"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("1G"),
- },
- },
- },
- {
- Resources: api.ResourceRequirements{
- Requests: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("90m"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("120Mi"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("200M"),
- },
- },
- },
- },
- },
- },
- {
- Spec: api.PodSpec{
- Containers: []api.Container{
- {
- Resources: api.ResourceRequirements{
- Requests: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("60m"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("43Mi"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("500M"),
- },
- },
- },
- {
- Resources: api.ResourceRequirements{
- Requests: api.ResourceList{
- api.ResourceName(api.ResourceCPU): resource.MustParse("34m"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("83Mi"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("700M"),
- },
- },
- },
- },
- },
- },
- },
- },
- expectedReqs: map[api.ResourceName]resource.Quantity{
- api.ResourceName(api.ResourceCPU): resource.MustParse("1.184"),
- api.ResourceName(api.ResourceMemory): resource.MustParse("546Mi"),
- api.ResourceName(api.ResourceStorage): resource.MustParse("2.4G"),
- },
- },
- }
- for _, testCase := range testCases {
- reqs, _, err := getPodsTotalRequestsAndLimits(testCase.pods)
- if err != nil {
- t.Errorf("Unexpected error %v", err)
- }
- if !api.Semantic.DeepEqual(reqs, testCase.expectedReqs) {
- t.Errorf("Expected %v, got %v", testCase.expectedReqs, reqs)
- }
- }
- }
- func TestPersistentVolumeDescriber(t *testing.T) {
- tests := map[string]*api.PersistentVolume{
- "hostpath": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- HostPath: &api.HostPathVolumeSource{},
- },
- },
- },
- "gce": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- GCEPersistentDisk: &api.GCEPersistentDiskVolumeSource{},
- },
- },
- },
- "ebs": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- AWSElasticBlockStore: &api.AWSElasticBlockStoreVolumeSource{},
- },
- },
- },
- "nfs": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- NFS: &api.NFSVolumeSource{},
- },
- },
- },
- "iscsi": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- ISCSI: &api.ISCSIVolumeSource{},
- },
- },
- },
- "gluster": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- Glusterfs: &api.GlusterfsVolumeSource{},
- },
- },
- },
- "rbd": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- RBD: &api.RBDVolumeSource{},
- },
- },
- },
- "quobyte": {
- Spec: api.PersistentVolumeSpec{
- PersistentVolumeSource: api.PersistentVolumeSource{
- Quobyte: &api.QuobyteVolumeSource{},
- },
- },
- },
- }
- for name, pv := range tests {
- fake := testclient.NewSimpleFake(pv)
- c := PersistentVolumeDescriber{fake}
- str, err := c.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("Unexpected error for test %s: %v", name, err)
- }
- if str == "" {
- t.Errorf("Unexpected empty string for test %s. Expected PV Describer output", name)
- }
- }
- }
- func TestDescribeDeployment(t *testing.T) {
- fake := fake.NewSimpleClientset(&extensions.Deployment{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- Spec: extensions.DeploymentSpec{
- Template: api.PodTemplateSpec{},
- },
- })
- d := DeploymentDescriber{fake}
- out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "bar") || !strings.Contains(out, "foo") {
- t.Errorf("unexpected out: %s", out)
- }
- }
- func TestDescribeCluster(t *testing.T) {
- cluster := federation.Cluster{
- ObjectMeta: api.ObjectMeta{
- Name: "foo",
- ResourceVersion: "4",
- Labels: map[string]string{
- "name": "foo",
- },
- },
- Spec: federation.ClusterSpec{
- ServerAddressByClientCIDRs: []federation.ServerAddressByClientCIDR{
- {
- ClientCIDR: "0.0.0.0/0",
- ServerAddress: "localhost:8888",
- },
- },
- },
- Status: federation.ClusterStatus{
- Conditions: []federation.ClusterCondition{
- {Type: federation.ClusterReady, Status: api.ConditionTrue},
- },
- },
- }
- fake := fed_fake.NewSimpleClientset(&cluster)
- d := ClusterDescriber{Interface: fake}
- out, err := d.Describe("any", "foo", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("unexpected error: %v", err)
- }
- if !strings.Contains(out, "foo") {
- t.Errorf("unexpected out: %s", out)
- }
- }
- func TestDescribeEvents(t *testing.T) {
- events := &api.EventList{
- Items: []api.Event{
- {
- ObjectMeta: api.ObjectMeta{
- Namespace: "foo",
- },
- Source: api.EventSource{Component: "kubelet"},
- Message: "Item 1",
- FirstTimestamp: unversioned.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
- LastTimestamp: unversioned.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
- Count: 1,
- Type: api.EventTypeNormal,
- },
- },
- }
- m := map[string]Describer{
- "DaemonSetDescriber": &DaemonSetDescriber{
- testclient.NewSimpleFake(&extensions.DaemonSet{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- "DeploymentDescriber": &DeploymentDescriber{
- fake.NewSimpleClientset(&extensions.Deployment{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- "EndpointsDescriber": &EndpointsDescriber{
- testclient.NewSimpleFake(&api.Endpoints{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- // TODO(jchaloup): add tests for:
- // - HorizontalPodAutoscalerDescriber
- // - IngressDescriber
- // - JobDescriber
- "NodeDescriber": &NodeDescriber{
- testclient.NewSimpleFake(&api.Node{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- SelfLink: "url/url/url",
- },
- }, events),
- },
- "PersistentVolumeDescriber": &PersistentVolumeDescriber{
- testclient.NewSimpleFake(&api.PersistentVolume{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- SelfLink: "url/url/url",
- },
- }, events),
- },
- "PodDescriber": &PodDescriber{
- testclient.NewSimpleFake(&api.Pod{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- SelfLink: "url/url/url",
- },
- }, events),
- },
- "ReplicaSetDescriber": &ReplicaSetDescriber{
- testclient.NewSimpleFake(&extensions.ReplicaSet{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- "ReplicationControllerDescriber": &ReplicationControllerDescriber{
- testclient.NewSimpleFake(&api.ReplicationController{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- "Service": &ServiceDescriber{
- testclient.NewSimpleFake(&api.Service{
- ObjectMeta: api.ObjectMeta{
- Name: "bar",
- Namespace: "foo",
- },
- }, events),
- },
- }
- for name, d := range m {
- out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
- if err != nil {
- t.Errorf("unexpected error for %q: %v", name, err)
- }
- if !strings.Contains(out, "bar") {
- t.Errorf("unexpected out for %q: %s", name, out)
- }
- if !strings.Contains(out, "Events:") {
- t.Errorf("events not found for %q when ShowEvents=true: %s", name, out)
- }
- out, err = d.Describe("foo", "bar", DescriberSettings{ShowEvents: false})
- if err != nil {
- t.Errorf("unexpected error for %q: %s", name, err)
- }
- if !strings.Contains(out, "bar") {
- t.Errorf("unexpected out for %q: %s", name, out)
- }
- if strings.Contains(out, "Events:") {
- t.Errorf("events found for %q when ShowEvents=false: %s", name, out)
- }
- }
- }
|