2014-10-27 19:56:34 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-10-27 19:56:34 +00:00
|
|
|
|
|
|
|
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 (
|
2015-04-02 15:42:19 +00:00
|
|
|
"bytes"
|
2015-02-26 18:50:12 +00:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2014-10-27 19:56:34 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2014-12-16 22:20:51 +00:00
|
|
|
"time"
|
2014-10-27 19:56:34 +00:00
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2015-09-17 22:21:55 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-10-09 22:04:41 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2015-08-13 19:01:50 +00:00
|
|
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
|
|
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
2014-10-27 19:56:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type describeClient struct {
|
|
|
|
T *testing.T
|
|
|
|
Namespace string
|
|
|
|
Err error
|
2015-04-06 23:27:53 +00:00
|
|
|
client.Interface
|
2014-10-27 19:56:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 22:20:51 +00:00
|
|
|
func init() {
|
|
|
|
api.ForTesting_ReferencesAllowBlankSelfLinks = true
|
|
|
|
}
|
|
|
|
|
2014-10-27 19:56:34 +00:00
|
|
|
func TestDescribePod(t *testing.T) {
|
2015-04-06 23:27:53 +00:00
|
|
|
fake := testclient.NewSimpleFake(&api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "bar",
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
2014-11-14 01:42:50 +00:00
|
|
|
d := PodDescriber{c}
|
2014-10-27 19:56:34 +00:00
|
|
|
out, err := d.Describe("foo", "bar")
|
|
|
|
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 TestDescribeService(t *testing.T) {
|
2015-04-06 23:27:53 +00:00
|
|
|
fake := testclient.NewSimpleFake(&api.Service{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "bar",
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
2014-11-14 01:42:50 +00:00
|
|
|
d := ServiceDescriber{c}
|
2014-10-27 19:56:34 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2014-12-16 22:20:51 +00:00
|
|
|
|
|
|
|
func TestPodDescribeResultsSorted(t *testing.T) {
|
|
|
|
// Arrange
|
2015-04-06 23:27:53 +00:00
|
|
|
fake := testclient.NewSimpleFake(&api.EventList{
|
|
|
|
Items: []api.Event{
|
|
|
|
{
|
|
|
|
Source: api.EventSource{Component: "kubelet"},
|
|
|
|
Message: "Item 1",
|
2015-09-17 22:21:55 +00:00
|
|
|
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)),
|
2015-04-06 23:27:53 +00:00
|
|
|
Count: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: api.EventSource{Component: "scheduler"},
|
|
|
|
Message: "Item 2",
|
2015-09-17 22:21:55 +00:00
|
|
|
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)),
|
2015-04-06 23:27:53 +00:00
|
|
|
Count: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Source: api.EventSource{Component: "kubelet"},
|
|
|
|
Message: "Item 3",
|
2015-09-17 22:21:55 +00:00
|
|
|
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)),
|
2015-04-06 23:27:53 +00:00
|
|
|
Count: 1,
|
2014-12-16 22:20:51 +00:00
|
|
|
},
|
|
|
|
},
|
2015-04-06 23:27:53 +00:00
|
|
|
})
|
|
|
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
2014-12-16 22:20:51 +00:00
|
|
|
d := PodDescriber{c}
|
|
|
|
|
|
|
|
// Act
|
|
|
|
out, err := d.Describe("foo", "bar")
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
VerifyDatesInOrder(out, "\n" /* rowDelimiter */, "\t" /* columnDelimiter */, t)
|
|
|
|
}
|
2015-02-26 18:50:12 +00:00
|
|
|
|
2015-04-02 15:42:19 +00:00
|
|
|
func TestDescribeContainers(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2015-06-05 04:49:01 +00:00
|
|
|
container api.Container
|
|
|
|
status api.ContainerStatus
|
2015-04-02 15:42:19 +00:00
|
|
|
expectedElements []string
|
|
|
|
}{
|
|
|
|
// Running state.
|
|
|
|
{
|
2015-06-05 04:49:01 +00:00
|
|
|
container: api.Container{Name: "test", Image: "image"},
|
|
|
|
status: api.ContainerStatus{
|
2015-04-02 15:42:19 +00:00
|
|
|
Name: "test",
|
|
|
|
State: api.ContainerState{
|
|
|
|
Running: &api.ContainerStateRunning{
|
2015-09-17 22:21:55 +00:00
|
|
|
StartedAt: unversioned.NewTime(time.Now()),
|
2015-04-02 15:42:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Ready: true,
|
|
|
|
RestartCount: 7,
|
|
|
|
},
|
|
|
|
expectedElements: []string{"test", "State", "Running", "Ready", "True", "Restart Count", "7", "Image", "image", "Started"},
|
|
|
|
},
|
|
|
|
// Waiting state.
|
|
|
|
{
|
2015-06-05 04:49:01 +00:00
|
|
|
container: api.Container{Name: "test", Image: "image"},
|
|
|
|
status: api.ContainerStatus{
|
2015-04-02 15:42:19 +00:00
|
|
|
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.
|
|
|
|
{
|
2015-06-05 04:49:01 +00:00
|
|
|
container: api.Container{Name: "test", Image: "image"},
|
|
|
|
status: api.ContainerStatus{
|
2015-04-02 15:42:19 +00:00
|
|
|
Name: "test",
|
|
|
|
State: api.ContainerState{
|
2015-05-27 22:02:11 +00:00
|
|
|
Terminated: &api.ContainerStateTerminated{
|
2015-09-17 22:21:55 +00:00
|
|
|
StartedAt: unversioned.NewTime(time.Now()),
|
|
|
|
FinishedAt: unversioned.NewTime(time.Now()),
|
2015-04-02 15:42:19 +00:00
|
|
|
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"},
|
|
|
|
},
|
2015-08-07 01:45:20 +00:00
|
|
|
// Last Terminated
|
|
|
|
{
|
|
|
|
container: api.Container{Name: "test", Image: "image"},
|
|
|
|
status: api.ContainerStatus{
|
|
|
|
Name: "test",
|
|
|
|
State: api.ContainerState{
|
|
|
|
Running: &api.ContainerStateRunning{
|
2015-09-17 22:21:55 +00:00
|
|
|
StartedAt: unversioned.NewTime(time.Now()),
|
2015-08-07 01:45:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
LastTerminationState: api.ContainerState{
|
|
|
|
Terminated: &api.ContainerStateTerminated{
|
2015-09-17 22:21:55 +00:00
|
|
|
StartedAt: unversioned.NewTime(time.Now().Add(time.Second * 3)),
|
|
|
|
FinishedAt: unversioned.NewTime(time.Now()),
|
2015-08-07 01:45:20 +00:00
|
|
|
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"},
|
|
|
|
},
|
2015-04-02 15:42:19 +00:00
|
|
|
// No state defaults to waiting.
|
|
|
|
{
|
2015-06-05 04:49:01 +00:00
|
|
|
container: api.Container{Name: "test", Image: "image"},
|
|
|
|
status: api.ContainerStatus{
|
2015-04-02 15:42:19 +00:00
|
|
|
Name: "test",
|
|
|
|
Ready: true,
|
|
|
|
RestartCount: 7,
|
|
|
|
},
|
|
|
|
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image"},
|
|
|
|
},
|
2015-07-04 14:31:15 +00:00
|
|
|
//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"},
|
|
|
|
},
|
2015-06-05 04:49:01 +00:00
|
|
|
// 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"},
|
|
|
|
},
|
2015-04-02 15:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
out := new(bytes.Buffer)
|
2015-06-05 04:49:01 +00:00
|
|
|
pod := api.Pod{
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{testCase.container},
|
|
|
|
},
|
|
|
|
Status: api.PodStatus{
|
|
|
|
ContainerStatuses: []api.ContainerStatus{testCase.status},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
describeContainers(&pod, out)
|
2015-04-02 15:42:19 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 18:50:12 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2015-07-30 02:19:17 +00:00
|
|
|
|
|
|
|
func TestGetPodsTotalRequests(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2015-09-10 00:20:31 +00:00
|
|
|
pods []*api.Pod
|
|
|
|
expectedReqs, expectedLimits map[api.ResourceName]resource.Quantity
|
2015-07-30 02:19:17 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
pods: []*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 {
|
2015-09-10 00:20:31 +00:00
|
|
|
reqs, _, err := getPodsTotalRequestsAndLimits(testCase.pods)
|
2015-07-30 02:19:17 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(reqs, testCase.expectedReqs) {
|
|
|
|
t.Errorf("Expected %v, got %v", testCase.expectedReqs, reqs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 15:28:16 +00:00
|
|
|
|
|
|
|
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{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, pv := range tests {
|
|
|
|
fake := testclient.NewSimpleFake(pv)
|
|
|
|
c := PersistentVolumeDescriber{fake}
|
|
|
|
str, err := c.Describe("foo", "bar")
|
|
|
|
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)
|
|
|
|
}
|
2015-09-18 20:35:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 15:28:16 +00:00
|
|
|
|
2015-09-18 20:35:56 +00:00
|
|
|
func TestDescribeDeployment(t *testing.T) {
|
2015-10-09 22:49:10 +00:00
|
|
|
fake := testclient.NewSimpleFake(&extensions.Deployment{
|
2015-09-18 20:35:56 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: "bar",
|
|
|
|
Namespace: "foo",
|
|
|
|
},
|
2015-10-09 22:49:10 +00:00
|
|
|
Spec: extensions.DeploymentSpec{
|
2015-09-18 20:35:56 +00:00
|
|
|
Template: &api.PodTemplateSpec{},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
|
|
|
d := DeploymentDescriber{c}
|
|
|
|
out, err := d.Describe("foo", "bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
if !strings.Contains(out, "bar") || !strings.Contains(out, "foo") {
|
|
|
|
t.Errorf("unexpected out: %s", out)
|
2015-08-14 15:28:16 +00:00
|
|
|
}
|
|
|
|
}
|