mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
use subtest for table units (pkg/printers)
This commit is contained in:
parent
e24fd8efb1
commit
ae4c9d71c1
@ -47,20 +47,22 @@ func TestMassageJSONPath(t *testing.T) {
|
|||||||
{input: "{{foo.bar}", expectErr: true},
|
{input: "{{foo.bar}", expectErr: true},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.input, func(t *testing.T) {
|
||||||
output, err := printers.RelaxedJSONPathExpression(test.input)
|
output, err := printers.RelaxedJSONPathExpression(test.input)
|
||||||
if err != nil && !test.expectErr {
|
if err != nil && !test.expectErr {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("unexpected non-error")
|
t.Error("unexpected non-error")
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if output != test.expectedOutput {
|
if output != test.expectedOutput {
|
||||||
t.Errorf("input: %s, expected: %s, saw: %s", test.input, test.expectedOutput, output)
|
t.Errorf("input: %s, expected: %s, saw: %s", test.input, test.expectedOutput, output)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,16 +115,17 @@ func TestNewColumnPrinterFromSpec(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
printer, err := printers.NewCustomColumnsPrinterFromSpec(test.spec, legacyscheme.Codecs.UniversalDecoder(), test.noHeaders)
|
printer, err := printers.NewCustomColumnsPrinterFromSpec(test.spec, legacyscheme.Codecs.UniversalDecoder(), test.noHeaders)
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("[%s] unexpected non-error", test.name)
|
t.Errorf("[%s] unexpected non-error", test.name)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !test.expectErr && err != nil {
|
if !test.expectErr && err != nil {
|
||||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if test.noHeaders {
|
if test.noHeaders {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
@ -139,7 +142,7 @@ func TestNewColumnPrinterFromSpec(t *testing.T) {
|
|||||||
} else if !reflect.DeepEqual(test.expectedColumns, printer.Columns) {
|
} else if !reflect.DeepEqual(test.expectedColumns, printer.Columns) {
|
||||||
t.Errorf("[%s]\nexpected:\n%v\nsaw:\n%v\n", test.name, test.expectedColumns, printer.Columns)
|
t.Errorf("[%s]\nexpected:\n%v\nsaw:\n%v\n", test.name, test.expectedColumns, printer.Columns)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,23 +218,24 @@ func TestNewColumnPrinterFromTemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
reader := bytes.NewBufferString(test.spec)
|
reader := bytes.NewBufferString(test.spec)
|
||||||
printer, err := printers.NewCustomColumnsPrinterFromTemplate(reader, legacyscheme.Codecs.UniversalDecoder())
|
printer, err := printers.NewCustomColumnsPrinterFromTemplate(reader, legacyscheme.Codecs.UniversalDecoder())
|
||||||
if test.expectErr {
|
if test.expectErr {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("[%s] unexpected non-error", test.name)
|
t.Errorf("[%s] unexpected non-error", test.name)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if !test.expectErr && err != nil {
|
if !test.expectErr && err != nil {
|
||||||
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
t.Errorf("[%s] unexpected error: %v", test.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(test.expectedColumns, printer.Columns) {
|
if !reflect.DeepEqual(test.expectedColumns, printer.Columns) {
|
||||||
t.Errorf("[%s]\nexpected:\n%v\nsaw:\n%v\n", test.name, test.expectedColumns, printer.Columns)
|
t.Errorf("[%s]\nexpected:\n%v\nsaw:\n%v\n", test.name, test.expectedColumns, printer.Columns)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +314,7 @@ foo baz <none>
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.expectedOutput, func(t *testing.T) {
|
||||||
printer := &printers.CustomColumnsPrinter{
|
printer := &printers.CustomColumnsPrinter{
|
||||||
Columns: test.columns,
|
Columns: test.columns,
|
||||||
Decoder: legacyscheme.Codecs.UniversalDecoder(),
|
Decoder: legacyscheme.Codecs.UniversalDecoder(),
|
||||||
@ -321,6 +326,7 @@ foo baz <none>
|
|||||||
if buffer.String() != test.expectedOutput {
|
if buffer.String() != test.expectedOutput {
|
||||||
t.Errorf("\nexpected:\n'%s'\nsaw\n'%s'\n", test.expectedOutput, buffer.String())
|
t.Errorf("\nexpected:\n'%s'\nsaw\n'%s'\n", test.expectedOutput, buffer.String())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ func testPrintNamespace(obj *api.Namespace, options PrintOptions) ([]metav1beta1
|
|||||||
func TestPrintRowsForHandlerEntry(t *testing.T) {
|
func TestPrintRowsForHandlerEntry(t *testing.T) {
|
||||||
printFunc := reflect.ValueOf(testPrintNamespace)
|
printFunc := reflect.ValueOf(testPrintNamespace)
|
||||||
|
|
||||||
testCase := map[string]struct {
|
testCase := []struct {
|
||||||
|
name string
|
||||||
h *handlerEntry
|
h *handlerEntry
|
||||||
opt PrintOptions
|
opt PrintOptions
|
||||||
obj runtime.Object
|
obj runtime.Object
|
||||||
@ -56,7 +57,8 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
expectOut string
|
expectOut string
|
||||||
expectErr string
|
expectErr string
|
||||||
}{
|
}{
|
||||||
"no tablecolumndefinition and includeheader flase": {
|
{
|
||||||
|
name: "no tablecolumndefinition and includeheader flase",
|
||||||
h: &handlerEntry{
|
h: &handlerEntry{
|
||||||
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
||||||
printRows: true,
|
printRows: true,
|
||||||
@ -69,7 +71,8 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
includeHeader: false,
|
includeHeader: false,
|
||||||
expectOut: "test\t\t<unknow>\n",
|
expectOut: "test\t\t<unknow>\n",
|
||||||
},
|
},
|
||||||
"no tablecolumndefinition and includeheader true": {
|
{
|
||||||
|
name: "no tablecolumndefinition and includeheader true",
|
||||||
h: &handlerEntry{
|
h: &handlerEntry{
|
||||||
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
columnDefinitions: []metav1beta1.TableColumnDefinition{},
|
||||||
printRows: true,
|
printRows: true,
|
||||||
@ -82,7 +85,8 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
includeHeader: true,
|
includeHeader: true,
|
||||||
expectOut: "\ntest\t\t<unknow>\n",
|
expectOut: "\ntest\t\t<unknow>\n",
|
||||||
},
|
},
|
||||||
"have tablecolumndefinition and includeheader true": {
|
{
|
||||||
|
name: "have tablecolumndefinition and includeheader true",
|
||||||
h: &handlerEntry{
|
h: &handlerEntry{
|
||||||
columnDefinitions: testNamespaceColumnDefinitions,
|
columnDefinitions: testNamespaceColumnDefinitions,
|
||||||
printRows: true,
|
printRows: true,
|
||||||
@ -95,7 +99,8 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
includeHeader: true,
|
includeHeader: true,
|
||||||
expectOut: "NAME\tSTATUS\tAGE\ntest\t\t<unknow>\n",
|
expectOut: "NAME\tSTATUS\tAGE\ntest\t\t<unknow>\n",
|
||||||
},
|
},
|
||||||
"print namespace and withnamespace true, should not print header": {
|
{
|
||||||
|
name: "print namespace and withnamespace true, should not print header",
|
||||||
h: &handlerEntry{
|
h: &handlerEntry{
|
||||||
columnDefinitions: testNamespaceColumnDefinitions,
|
columnDefinitions: testNamespaceColumnDefinitions,
|
||||||
printRows: true,
|
printRows: true,
|
||||||
@ -112,16 +117,18 @@ func TestPrintRowsForHandlerEntry(t *testing.T) {
|
|||||||
expectErr: "namespace is not namespaced",
|
expectErr: "namespace is not namespaced",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for name, test := range testCase {
|
for _, test := range testCase {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
err := printRowsForHandlerEntry(buffer, test.h, test.obj, test.opt, test.includeHeader)
|
err := printRowsForHandlerEntry(buffer, test.h, test.obj, test.opt, test.includeHeader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() != test.expectErr {
|
if err.Error() != test.expectErr {
|
||||||
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", name, test.expectErr, err)
|
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", test.name, test.expectErr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if test.expectOut != buffer.String() {
|
if test.expectOut != buffer.String() {
|
||||||
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", name, test.expectOut, buffer.String())
|
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", test.name, test.expectOut, buffer.String())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,10 +282,12 @@ func getResourceList(cpu, memory string) api.ResourceList {
|
|||||||
|
|
||||||
func TestDescribeService(t *testing.T) {
|
func TestDescribeService(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
name string
|
||||||
service *api.Service
|
service *api.Service
|
||||||
expect []string
|
expect []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "test1",
|
||||||
service: &api.Service{
|
service: &api.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
@ -323,6 +325,7 @@ func TestDescribeService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test2",
|
||||||
service: &api.Service{
|
service: &api.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
@ -361,6 +364,7 @@ func TestDescribeService(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
fake := fake.NewSimpleClientset(testCase.service)
|
fake := fake.NewSimpleClientset(testCase.service)
|
||||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||||
d := ServiceDescriber{c}
|
d := ServiceDescriber{c}
|
||||||
@ -373,6 +377,7 @@ func TestDescribeService(t *testing.T) {
|
|||||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
t.Errorf("expected to find %q in output: %q", expected, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,12 +457,14 @@ func VerifyDatesInOrder(
|
|||||||
func TestDescribeContainers(t *testing.T) {
|
func TestDescribeContainers(t *testing.T) {
|
||||||
trueVal := true
|
trueVal := true
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
name string
|
||||||
container api.Container
|
container api.Container
|
||||||
status api.ContainerStatus
|
status api.ContainerStatus
|
||||||
expectedElements []string
|
expectedElements []string
|
||||||
}{
|
}{
|
||||||
// Running state.
|
// Running state.
|
||||||
{
|
{
|
||||||
|
name: "test1",
|
||||||
container: api.Container{Name: "test", Image: "image"},
|
container: api.Container{Name: "test", Image: "image"},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -473,6 +480,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Waiting state.
|
// Waiting state.
|
||||||
{
|
{
|
||||||
|
name: "test2",
|
||||||
container: api.Container{Name: "test", Image: "image"},
|
container: api.Container{Name: "test", Image: "image"},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -488,6 +496,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Terminated state.
|
// Terminated state.
|
||||||
{
|
{
|
||||||
|
name: "test3",
|
||||||
container: api.Container{Name: "test", Image: "image"},
|
container: api.Container{Name: "test", Image: "image"},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -506,6 +515,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Last Terminated
|
// Last Terminated
|
||||||
{
|
{
|
||||||
|
name: "test4",
|
||||||
container: api.Container{Name: "test", Image: "image"},
|
container: api.Container{Name: "test", Image: "image"},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -529,6 +539,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// No state defaults to waiting.
|
// No state defaults to waiting.
|
||||||
{
|
{
|
||||||
|
name: "test5",
|
||||||
container: api.Container{Name: "test", Image: "image"},
|
container: api.Container{Name: "test", Image: "image"},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -539,6 +550,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Env
|
// Env
|
||||||
{
|
{
|
||||||
|
name: "test6",
|
||||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -548,6 +560,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: false"},
|
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: false"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test7",
|
||||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", ConfigMapRef: &api.ConfigMapEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -557,6 +570,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap with prefix 'p_'\tOptional: false"},
|
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap with prefix 'p_'\tOptional: false"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test8",
|
||||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{Optional: &trueVal, LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{ConfigMapRef: &api.ConfigMapEnvSource{Optional: &trueVal, LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -566,6 +580,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: true"},
|
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tConfigMap\tOptional: true"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test9",
|
||||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}, Optional: &trueVal}}}},
|
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}, Optional: &trueVal}}}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -575,6 +590,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tSecret\tOptional: true"},
|
expectedElements: []string{"test", "State", "Waiting", "Ready", "True", "Restart Count", "7", "Image", "image", "envname", "xyz", "a123\tSecret\tOptional: true"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test10",
|
||||||
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
container: api.Container{Name: "test", Image: "image", Env: []api.EnvVar{{Name: "envname", Value: "xyz"}}, EnvFrom: []api.EnvFromSource{{Prefix: "p_", SecretRef: &api.SecretEnvSource{LocalObjectReference: api.LocalObjectReference{Name: "a123"}}}}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -585,6 +601,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Command
|
// Command
|
||||||
{
|
{
|
||||||
|
name: "test11",
|
||||||
container: api.Container{Name: "test", Image: "image", Command: []string{"sleep", "1000"}},
|
container: api.Container{Name: "test", Image: "image", Command: []string{"sleep", "1000"}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -595,6 +612,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Args
|
// Args
|
||||||
{
|
{
|
||||||
|
name: "test12",
|
||||||
container: api.Container{Name: "test", Image: "image", Args: []string{"time", "1000"}},
|
container: api.Container{Name: "test", Image: "image", Args: []string{"time", "1000"}},
|
||||||
status: api.ContainerStatus{
|
status: api.ContainerStatus{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
@ -605,6 +623,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Using limits.
|
// Using limits.
|
||||||
{
|
{
|
||||||
|
name: "test13",
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
@ -625,6 +644,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// Using requests.
|
// Using requests.
|
||||||
{
|
{
|
||||||
|
name: "test14",
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
@ -640,6 +660,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// volumeMounts read/write
|
// volumeMounts read/write
|
||||||
{
|
{
|
||||||
|
name: "test15",
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
@ -654,6 +675,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// volumeMounts readonly
|
// volumeMounts readonly
|
||||||
{
|
{
|
||||||
|
name: "test16",
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
@ -670,6 +692,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
|
|
||||||
// volumeDevices
|
// volumeDevices
|
||||||
{
|
{
|
||||||
|
name: "test17",
|
||||||
container: api.Container{
|
container: api.Container{
|
||||||
Name: "test",
|
Name: "test",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
@ -685,6 +708,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
pod := api.Pod{
|
pod := api.Pod{
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
@ -702,6 +726,7 @@ func TestDescribeContainers(t *testing.T) {
|
|||||||
t.Errorf("Test case %d: expected to find %q in output: %q", i, expected, output)
|
t.Errorf("Test case %d: expected to find %q in output: %q", i, expected, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,10 +812,12 @@ func TestDefaultDescribers(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetPodsTotalRequests(t *testing.T) {
|
func TestGetPodsTotalRequests(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
name string
|
||||||
pods *api.PodList
|
pods *api.PodList
|
||||||
expectedReqs map[api.ResourceName]resource.Quantity
|
expectedReqs map[api.ResourceName]resource.Quantity
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "test1",
|
||||||
pods: &api.PodList{
|
pods: &api.PodList{
|
||||||
Items: []api.Pod{
|
Items: []api.Pod{
|
||||||
{
|
{
|
||||||
@ -852,10 +879,12 @@ func TestGetPodsTotalRequests(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
reqs, _ := getPodsTotalRequestsAndLimits(testCase.pods)
|
reqs, _ := getPodsTotalRequestsAndLimits(testCase.pods)
|
||||||
if !apiequality.Semantic.DeepEqual(reqs, testCase.expectedReqs) {
|
if !apiequality.Semantic.DeepEqual(reqs, testCase.expectedReqs) {
|
||||||
t.Errorf("Expected %v, got %v", testCase.expectedReqs, reqs)
|
t.Errorf("Expected %v, got %v", testCase.expectedReqs, reqs)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -863,12 +892,14 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
block := api.PersistentVolumeBlock
|
block := api.PersistentVolumeBlock
|
||||||
file := api.PersistentVolumeFilesystem
|
file := api.PersistentVolumeFilesystem
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
name string
|
||||||
plugin string
|
plugin string
|
||||||
pv *api.PersistentVolume
|
pv *api.PersistentVolume
|
||||||
expectedElements []string
|
expectedElements []string
|
||||||
unexpectedElements []string
|
unexpectedElements []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "test0",
|
||||||
plugin: "hostpath",
|
plugin: "hostpath",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -881,6 +912,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test1",
|
||||||
plugin: "gce",
|
plugin: "gce",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -894,6 +926,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
expectedElements: []string{"VolumeMode", "Filesystem"},
|
expectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test2",
|
||||||
plugin: "ebs",
|
plugin: "ebs",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -906,6 +939,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test3",
|
||||||
plugin: "nfs",
|
plugin: "nfs",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -918,6 +952,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test4",
|
||||||
plugin: "iscsi",
|
plugin: "iscsi",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -931,6 +966,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
expectedElements: []string{"VolumeMode", "Block"},
|
expectedElements: []string{"VolumeMode", "Block"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test5",
|
||||||
plugin: "gluster",
|
plugin: "gluster",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -943,6 +979,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test6",
|
||||||
plugin: "rbd",
|
plugin: "rbd",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -955,6 +992,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test7",
|
||||||
plugin: "quobyte",
|
plugin: "quobyte",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -967,6 +1005,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test8",
|
||||||
plugin: "cinder",
|
plugin: "cinder",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -979,6 +1018,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
unexpectedElements: []string{"VolumeMode", "Filesystem"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test9",
|
||||||
plugin: "fc",
|
plugin: "fc",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -992,6 +1032,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
expectedElements: []string{"VolumeMode", "Block"},
|
expectedElements: []string{"VolumeMode", "Block"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test10",
|
||||||
plugin: "local",
|
plugin: "local",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -1005,6 +1046,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"Required Terms", "Term "},
|
unexpectedElements: []string{"Required Terms", "Term "},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test11",
|
||||||
plugin: "local",
|
plugin: "local",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -1019,6 +1061,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"Required Terms", "Term "},
|
unexpectedElements: []string{"Required Terms", "Term "},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test12",
|
||||||
plugin: "local",
|
plugin: "local",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -1035,6 +1078,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
unexpectedElements: []string{"Term "},
|
unexpectedElements: []string{"Term "},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test13",
|
||||||
plugin: "local",
|
plugin: "local",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -1059,6 +1103,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
expectedElements: []string{"Node Affinity", "Required Terms", "Term 0", "Term 1"},
|
expectedElements: []string{"Node Affinity", "Required Terms", "Term 0", "Term 1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
name: "test14",
|
||||||
plugin: "local",
|
plugin: "local",
|
||||||
pv: &api.PersistentVolume{
|
pv: &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
ObjectMeta: metav1.ObjectMeta{Name: "bar"},
|
||||||
@ -1094,6 +1139,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
fake := fake.NewSimpleClientset(test.pv)
|
fake := fake.NewSimpleClientset(test.pv)
|
||||||
c := PersistentVolumeDescriber{fake}
|
c := PersistentVolumeDescriber{fake}
|
||||||
str, err := c.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
str, err := c.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
||||||
@ -1113,6 +1159,7 @@ func TestPersistentVolumeDescriber(t *testing.T) {
|
|||||||
t.Errorf("unexpected to find %q in output: %q", unexpected, str)
|
t.Errorf("unexpected to find %q in output: %q", unexpected, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1271,6 +1318,7 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
fake := fake.NewSimpleClientset(test.pvc)
|
fake := fake.NewSimpleClientset(test.pvc)
|
||||||
c := PersistentVolumeClaimDescriber{fake}
|
c := PersistentVolumeClaimDescriber{fake}
|
||||||
str, err := c.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
str, err := c.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
||||||
@ -1290,6 +1338,7 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) {
|
|||||||
t.Errorf("unexpected to find %q in output: %q", unexpected, str)
|
t.Errorf("unexpected to find %q in output: %q", unexpected, str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1879,6 +1928,7 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
test.hpa.ObjectMeta = metav1.ObjectMeta{
|
test.hpa.ObjectMeta = metav1.ObjectMeta{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
Namespace: "foo",
|
Namespace: "foo",
|
||||||
@ -1893,6 +1943,7 @@ func TestDescribeHorizontalPodAutoscaler(t *testing.T) {
|
|||||||
t.Errorf("Unexpected empty string for test %s. Expected HPA Describer output", test.name)
|
t.Errorf("Unexpected empty string for test %s. Expected HPA Describer output", test.name)
|
||||||
}
|
}
|
||||||
t.Logf("Description for %q:\n%s", test.name, str)
|
t.Logf("Description for %q:\n%s", test.name, str)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2022,6 +2073,7 @@ func TestDescribeEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for name, d := range m {
|
for name, d := range m {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error for %q: %v", name, err)
|
t.Errorf("unexpected error for %q: %v", name, err)
|
||||||
@ -2043,6 +2095,7 @@ func TestDescribeEvents(t *testing.T) {
|
|||||||
if strings.Contains(out, "Events:") {
|
if strings.Contains(out, "Events:") {
|
||||||
t.Errorf("events found for %q when ShowEvents=false: %s", name, out)
|
t.Errorf("events found for %q when ShowEvents=false: %s", name, out)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2070,6 +2123,7 @@ func TestPrintLabelsMultiline(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
|
t.Run(testCase.expectPrint, func(t *testing.T) {
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
writer := NewPrefixWriter(out)
|
writer := NewPrefixWriter(out)
|
||||||
printAnnotationsMultiline(writer, "Annotations", testCase.annotations)
|
printAnnotationsMultiline(writer, "Annotations", testCase.annotations)
|
||||||
@ -2077,6 +2131,7 @@ func TestPrintLabelsMultiline(t *testing.T) {
|
|||||||
if output != testCase.expectPrint {
|
if output != testCase.expectPrint {
|
||||||
t.Errorf("Test case %d: expected to find %q in output: %q", i, testCase.expectPrint, output)
|
t.Errorf("Test case %d: expected to find %q in output: %q", i, testCase.expectPrint, output)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,13 +26,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplate(t *testing.T) {
|
func TestTemplate(t *testing.T) {
|
||||||
testCase := map[string]struct {
|
testCase := []struct {
|
||||||
|
name string
|
||||||
template string
|
template string
|
||||||
obj runtime.Object
|
obj runtime.Object
|
||||||
expectOut string
|
expectOut string
|
||||||
expectErr func(error) (string, bool)
|
expectErr func(error) (string, bool)
|
||||||
}{
|
}{
|
||||||
"support base64 decoding of secret data": {
|
{
|
||||||
|
name: "support base64 decoding of secret data",
|
||||||
template: "{{ .data.username | base64decode }}",
|
template: "{{ .data.username | base64decode }}",
|
||||||
obj: &v1.Secret{
|
obj: &v1.Secret{
|
||||||
Data: map[string][]byte{
|
Data: map[string][]byte{
|
||||||
@ -41,7 +43,8 @@ func TestTemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expectOut: "hunter",
|
expectOut: "hunter",
|
||||||
},
|
},
|
||||||
"test error path for base64 decoding": {
|
{
|
||||||
|
name: "test error path for base64 decoding",
|
||||||
template: "{{ .data.username | base64decode }}",
|
template: "{{ .data.username | base64decode }}",
|
||||||
obj: &badlyMarshaledSecret{},
|
obj: &badlyMarshaledSecret{},
|
||||||
expectErr: func(err error) (string, bool) {
|
expectErr: func(err error) (string, bool) {
|
||||||
@ -50,41 +53,43 @@ func TestTemplate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for name, test := range testCase {
|
for _, test := range testCase {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
|
|
||||||
p, err := NewGoTemplatePrinter([]byte(test.template))
|
p, err := NewGoTemplatePrinter([]byte(test.template))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if test.expectErr == nil {
|
if test.expectErr == nil {
|
||||||
t.Errorf("[%s]expected success but got:\n %v\n", name, err)
|
t.Errorf("[%s]expected success but got:\n %v\n", test.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if expected, ok := test.expectErr(err); !ok {
|
if expected, ok := test.expectErr(err); !ok {
|
||||||
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", name, expected, err)
|
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", test.name, expected, err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.PrintObj(test.obj, buffer)
|
err = p.PrintObj(test.obj, buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if test.expectErr == nil {
|
if test.expectErr == nil {
|
||||||
t.Errorf("[%s]expected success but got:\n %v\n", name, err)
|
t.Errorf("[%s]expected success but got:\n %v\n", test.name, err)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
if expected, ok := test.expectErr(err); !ok {
|
if expected, ok := test.expectErr(err); !ok {
|
||||||
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", name, expected, err)
|
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", test.name, expected, err)
|
||||||
}
|
}
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectErr != nil {
|
if test.expectErr != nil {
|
||||||
t.Errorf("[%s]expect:\n error\n but got:\n no error\n", name)
|
t.Errorf("[%s]expect:\n error\n but got:\n no error\n", test.name)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectOut != buffer.String() {
|
if test.expectOut != buffer.String() {
|
||||||
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", name, test.expectOut, buffer.String())
|
t.Errorf("[%s]expect:\n %v\n but got:\n %v\n", test.name, test.expectOut, buffer.String())
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user