Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
637a3392
Commit
637a3392
authored
Dec 08, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18004 from jiangyaoguo/print-absolute-time-when-watch-event
Auto commit by PR queue bot
parents
a486977e
7153ff80
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
30 deletions
+43
-30
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+7
-7
delete.go
pkg/kubectl/cmd/delete.go
+1
-1
get.go
pkg/kubectl/cmd/get.go
+1
-1
label.go
pkg/kubectl/cmd/label.go
+1
-1
factory.go
pkg/kubectl/cmd/util/factory.go
+4
-4
helpers.go
pkg/kubectl/cmd/util/helpers.go
+13
-0
resource_printer.go
pkg/kubectl/resource_printer.go
+0
-0
resource_printer_test.go
pkg/kubectl/resource_printer_test.go
+16
-16
No files found.
pkg/kubectl/cmd/cmd_test.go
View file @
637a3392
...
@@ -167,7 +167,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
...
@@ -167,7 +167,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
Describer
:
func
(
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
Describer
:
func
(
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
return
t
.
Describer
,
t
.
Err
return
t
.
Describer
,
t
.
Err
},
},
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
absoluteTimestamps
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
return
t
.
Printer
,
t
.
Err
return
t
.
Printer
,
t
.
Err
},
},
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
...
@@ -224,7 +224,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
...
@@ -224,7 +224,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
Describer
:
func
(
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
Describer
:
func
(
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
return
t
.
Describer
,
t
.
Err
return
t
.
Describer
,
t
.
Err
},
},
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
absoluteTimestamps
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
return
t
.
Printer
,
t
.
Err
return
t
.
Printer
,
t
.
Err
},
},
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
Validator
:
func
(
validate
bool
,
cacheDir
string
)
(
validation
.
Schema
,
error
)
{
...
@@ -299,7 +299,7 @@ func stringBody(body string) io.ReadCloser {
...
@@ -299,7 +299,7 @@ func stringBody(body string) io.ReadCloser {
func
ExamplePrintReplicationControllerWithNamespace
()
{
func
ExamplePrintReplicationControllerWithNamespace
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
[]
string
{})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
nil
,
Client
:
nil
,
...
@@ -341,7 +341,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
...
@@ -341,7 +341,7 @@ func ExamplePrintReplicationControllerWithNamespace() {
func
ExamplePrintPodWithWideFormat
()
{
func
ExamplePrintPodWithWideFormat
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
true
,
false
,
[]
string
{})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
true
,
false
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
nil
,
Client
:
nil
,
...
@@ -468,7 +468,7 @@ func newAllPhasePodList() *api.PodList {
...
@@ -468,7 +468,7 @@ func newAllPhasePodList() *api.PodList {
func
ExamplePrintPodHideTerminated
()
{
func
ExamplePrintPodHideTerminated
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
nil
,
Client
:
nil
,
...
@@ -488,7 +488,7 @@ func ExamplePrintPodHideTerminated() {
...
@@ -488,7 +488,7 @@ func ExamplePrintPodHideTerminated() {
func
ExamplePrintPodShowAll
()
{
func
ExamplePrintPodShowAll
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
false
,
true
,
[]
string
{})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
false
,
false
,
true
,
false
,
[]
string
{})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
nil
,
Client
:
nil
,
...
@@ -510,7 +510,7 @@ func ExamplePrintPodShowAll() {
...
@@ -510,7 +510,7 @@ func ExamplePrintPodShowAll() {
func
ExamplePrintServiceWithNamespacesAndLabels
()
{
func
ExamplePrintServiceWithNamespacesAndLabels
()
{
f
,
tf
,
codec
:=
NewAPIFactory
()
f
,
tf
,
codec
:=
NewAPIFactory
()
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
[]
string
{
"l1"
})
tf
.
Printer
=
kubectl
.
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
false
,
[]
string
{
"l1"
})
tf
.
Client
=
&
fake
.
RESTClient
{
tf
.
Client
=
&
fake
.
RESTClient
{
Codec
:
codec
,
Codec
:
codec
,
Client
:
nil
,
Client
:
nil
,
...
...
pkg/kubectl/cmd/delete.go
View file @
637a3392
...
@@ -71,7 +71,7 @@ func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -71,7 +71,7 @@ func NewCmdDelete(f *cmdutil.Factory, out io.Writer) *cobra.Command {
// retrieve a list of handled resources from printer as valid args
// retrieve a list of handled resources from printer as valid args
validArgs
:=
[]
string
{}
validArgs
:=
[]
string
{}
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
[]
string
{})
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
false
,
[]
string
{})
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
if
p
!=
nil
{
if
p
!=
nil
{
validArgs
=
p
.
HandledResources
()
validArgs
=
p
.
HandledResources
()
...
...
pkg/kubectl/cmd/get.go
View file @
637a3392
...
@@ -78,7 +78,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -78,7 +78,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
// retrieve a list of handled resources from printer as valid args
// retrieve a list of handled resources from printer as valid args
validArgs
:=
[]
string
{}
validArgs
:=
[]
string
{}
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
[]
string
{})
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
false
,
[]
string
{})
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
if
p
!=
nil
{
if
p
!=
nil
{
validArgs
=
p
.
HandledResources
()
validArgs
=
p
.
HandledResources
()
...
...
pkg/kubectl/cmd/label.go
View file @
637a3392
...
@@ -71,7 +71,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -71,7 +71,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
// retrieve a list of handled resources from printer as valid args
// retrieve a list of handled resources from printer as valid args
validArgs
:=
[]
string
{}
validArgs
:=
[]
string
{}
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
[]
string
{})
p
,
err
:=
f
.
Printer
(
nil
,
false
,
false
,
false
,
false
,
false
,
[]
string
{})
cmdutil
.
CheckErr
(
err
)
cmdutil
.
CheckErr
(
err
)
if
p
!=
nil
{
if
p
!=
nil
{
validArgs
=
p
.
HandledResources
()
validArgs
=
p
.
HandledResources
()
...
...
pkg/kubectl/cmd/util/factory.go
View file @
637a3392
...
@@ -73,7 +73,7 @@ type Factory struct {
...
@@ -73,7 +73,7 @@ type Factory struct {
// Returns a Describer for displaying the specified RESTMapping type or an error.
// Returns a Describer for displaying the specified RESTMapping type or an error.
Describer
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
Describer
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
// Returns a Printer for formatting objects of the given type or an error.
// Returns a Printer for formatting objects of the given type or an error.
Printer
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
Printer
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
absoluteTimestamps
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
// Returns a Scaler for changing the size of the specified RESTMapping type or an error
// Returns a Scaler for changing the size of the specified RESTMapping type or an error
Scaler
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
Scaler
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Scaler
,
error
)
// Returns a Reaper for gracefully shutting down resources.
// Returns a Reaper for gracefully shutting down resources.
...
@@ -180,8 +180,8 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -180,8 +180,8 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
}
}
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
},
},
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
Printer
:
func
(
mapping
*
meta
.
RESTMapping
,
noHeaders
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
absoluteTimestamps
bool
,
columnLabels
[]
string
)
(
kubectl
.
ResourcePrinter
,
error
)
{
return
kubectl
.
NewHumanReadablePrinter
(
noHeaders
,
withNamespace
,
wide
,
showAll
,
columnLabels
),
nil
return
kubectl
.
NewHumanReadablePrinter
(
noHeaders
,
withNamespace
,
wide
,
showAll
,
absoluteTimestamps
,
columnLabels
),
nil
},
},
PodSelectorForObject
:
func
(
object
runtime
.
Object
)
(
string
,
error
)
{
PodSelectorForObject
:
func
(
object
runtime
.
Object
)
(
string
,
error
)
{
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
...
@@ -611,7 +611,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
...
@@ -611,7 +611,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
if
err
!=
nil
{
if
err
!=
nil
{
columnLabel
=
[]
string
{}
columnLabel
=
[]
string
{}
}
}
printer
,
err
=
f
.
Printer
(
mapping
,
GetFlagBool
(
cmd
,
"no-headers"
),
withNamespace
,
GetWideFlag
(
cmd
),
GetFlagBool
(
cmd
,
"show-all"
),
columnLabel
)
printer
,
err
=
f
.
Printer
(
mapping
,
GetFlagBool
(
cmd
,
"no-headers"
),
withNamespace
,
GetWideFlag
(
cmd
),
GetFlagBool
(
cmd
,
"show-all"
),
isWatch
(
cmd
),
columnLabel
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/kubectl/cmd/util/helpers.go
View file @
637a3392
...
@@ -214,6 +214,19 @@ func UsageError(cmd *cobra.Command, format string, args ...interface{}) error {
...
@@ -214,6 +214,19 @@ func UsageError(cmd *cobra.Command, format string, args ...interface{}) error {
return
fmt
.
Errorf
(
"%s
\n
See '%s -h' for help and examples."
,
msg
,
cmd
.
CommandPath
())
return
fmt
.
Errorf
(
"%s
\n
See '%s -h' for help and examples."
,
msg
,
cmd
.
CommandPath
())
}
}
// Whether this cmd need watching objects.
func
isWatch
(
cmd
*
cobra
.
Command
)
bool
{
if
w
,
err
:=
cmd
.
Flags
()
.
GetBool
(
"watch"
);
w
&&
err
==
nil
{
return
true
}
if
wo
,
err
:=
cmd
.
Flags
()
.
GetBool
(
"watch-only"
);
wo
&&
err
==
nil
{
return
true
}
return
false
}
func
getFlag
(
cmd
*
cobra
.
Command
,
flag
string
)
*
pflag
.
Flag
{
func
getFlag
(
cmd
*
cobra
.
Command
,
flag
string
)
*
pflag
.
Flag
{
f
:=
cmd
.
Flags
()
.
Lookup
(
flag
)
f
:=
cmd
.
Flags
()
.
Lookup
(
flag
)
if
f
==
nil
{
if
f
==
nil
{
...
...
pkg/kubectl/resource_printer.go
View file @
637a3392
This diff is collapsed.
Click to expand it.
pkg/kubectl/resource_printer_test.go
View file @
637a3392
...
@@ -213,18 +213,18 @@ func TestJSONPrinter(t *testing.T) {
...
@@ -213,18 +213,18 @@ func TestJSONPrinter(t *testing.T) {
testPrinter
(
t
,
&
JSONPrinter
{},
json
.
Unmarshal
)
testPrinter
(
t
,
&
JSONPrinter
{},
json
.
Unmarshal
)
}
}
func
PrintCustomType
(
obj
*
TestPrintType
,
w
io
.
Writer
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
error
{
func
PrintCustomType
(
obj
*
TestPrintType
,
w
io
.
Writer
,
options
printOptions
)
error
{
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s"
,
obj
.
Data
)
_
,
err
:=
fmt
.
Fprintf
(
w
,
"%s"
,
obj
.
Data
)
return
err
return
err
}
}
func
ErrorPrintHandler
(
obj
*
TestPrintType
,
w
io
.
Writer
,
withNamespace
bool
,
wide
bool
,
showAll
bool
,
columnLabels
[]
string
)
error
{
func
ErrorPrintHandler
(
obj
*
TestPrintType
,
w
io
.
Writer
,
options
printOptions
)
error
{
return
fmt
.
Errorf
(
"ErrorPrintHandler error"
)
return
fmt
.
Errorf
(
"ErrorPrintHandler error"
)
}
}
func
TestCustomTypePrinting
(
t
*
testing
.
T
)
{
func
TestCustomTypePrinting
(
t
*
testing
.
T
)
{
columns
:=
[]
string
{
"Data"
}
columns
:=
[]
string
{
"Data"
}
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{})
printer
.
Handler
(
columns
,
PrintCustomType
)
printer
.
Handler
(
columns
,
PrintCustomType
)
obj
:=
TestPrintType
{
"test object"
}
obj
:=
TestPrintType
{
"test object"
}
...
@@ -241,7 +241,7 @@ func TestCustomTypePrinting(t *testing.T) {
...
@@ -241,7 +241,7 @@ func TestCustomTypePrinting(t *testing.T) {
func
TestPrintHandlerError
(
t
*
testing
.
T
)
{
func
TestPrintHandlerError
(
t
*
testing
.
T
)
{
columns
:=
[]
string
{
"Data"
}
columns
:=
[]
string
{
"Data"
}
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{})
printer
.
Handler
(
columns
,
ErrorPrintHandler
)
printer
.
Handler
(
columns
,
ErrorPrintHandler
)
obj
:=
TestPrintType
{
"test object"
}
obj
:=
TestPrintType
{
"test object"
}
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
...
@@ -252,7 +252,7 @@ func TestPrintHandlerError(t *testing.T) {
...
@@ -252,7 +252,7 @@ func TestPrintHandlerError(t *testing.T) {
}
}
func
TestUnknownTypePrinting
(
t
*
testing
.
T
)
{
func
TestUnknownTypePrinting
(
t
*
testing
.
T
)
{
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{})
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
err
:=
printer
.
PrintObj
(
&
TestUnknownType
{},
buffer
)
err
:=
printer
.
PrintObj
(
&
TestUnknownType
{},
buffer
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -456,8 +456,8 @@ func TestPrinters(t *testing.T) {
...
@@ -456,8 +456,8 @@ func TestPrinters(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
printers
:=
map
[
string
]
ResourcePrinter
{
printers
:=
map
[
string
]
ResourcePrinter
{
"humanReadable"
:
NewHumanReadablePrinter
(
true
,
false
,
false
,
false
,
[]
string
{}),
"humanReadable"
:
NewHumanReadablePrinter
(
true
,
false
,
false
,
false
,
false
,
[]
string
{}),
"humanReadableHeaders"
:
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{}),
"humanReadableHeaders"
:
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{}),
"json"
:
&
JSONPrinter
{},
"json"
:
&
JSONPrinter
{},
"yaml"
:
&
YAMLPrinter
{},
"yaml"
:
&
YAMLPrinter
{},
"template"
:
templatePrinter
,
"template"
:
templatePrinter
,
...
@@ -497,7 +497,7 @@ func TestPrinters(t *testing.T) {
...
@@ -497,7 +497,7 @@ func TestPrinters(t *testing.T) {
func
TestPrintEventsResultSorted
(
t
*
testing
.
T
)
{
func
TestPrintEventsResultSorted
(
t
*
testing
.
T
)
{
// Arrange
// Arrange
printer
:=
NewHumanReadablePrinter
(
false
/* noHeaders */
,
false
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
/* noHeaders */
,
false
,
false
,
false
,
false
,
[]
string
{})
obj
:=
api
.
EventList
{
obj
:=
api
.
EventList
{
Items
:
[]
api
.
Event
{
Items
:
[]
api
.
Event
{
...
@@ -541,7 +541,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
...
@@ -541,7 +541,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
}
}
func
TestPrintNodeStatus
(
t
*
testing
.
T
)
{
func
TestPrintNodeStatus
(
t
*
testing
.
T
)
{
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
false
,
false
,
false
,
false
,
[]
string
{})
table
:=
[]
struct
{
table
:=
[]
struct
{
node
api
.
Node
node
api
.
Node
status
string
status
string
...
@@ -752,7 +752,7 @@ func TestPrintHumanReadableService(t *testing.T) {
...
@@ -752,7 +752,7 @@ func TestPrintHumanReadableService(t *testing.T) {
for
_
,
svc
:=
range
tests
{
for
_
,
svc
:=
range
tests
{
buff
:=
bytes
.
Buffer
{}
buff
:=
bytes
.
Buffer
{}
printService
(
&
svc
,
&
buff
,
false
,
false
,
false
,
[]
string
{
})
printService
(
&
svc
,
&
buff
,
printOptions
{
false
,
false
,
false
,
false
,
false
,
[]
string
{}
})
output
:=
string
(
buff
.
Bytes
())
output
:=
string
(
buff
.
Bytes
())
ip
:=
svc
.
Spec
.
ClusterIP
ip
:=
svc
.
Spec
.
ClusterIP
if
!
strings
.
Contains
(
output
,
ip
)
{
if
!
strings
.
Contains
(
output
,
ip
)
{
...
@@ -934,7 +934,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
...
@@ -934,7 +934,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
for
_
,
test
:=
range
table
{
for
_
,
test
:=
range
table
{
if
test
.
isNamespaced
{
if
test
.
isNamespaced
{
// Expect output to include namespace when requested.
// Expect output to include namespace when requested.
printer
:=
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
false
,
[]
string
{})
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
err
:=
printer
.
PrintObj
(
test
.
obj
,
buffer
)
err
:=
printer
.
PrintObj
(
test
.
obj
,
buffer
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -946,7 +946,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
...
@@ -946,7 +946,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
}
}
}
else
{
}
else
{
// Expect error when trying to get all namespaces for un-namespaced object.
// Expect error when trying to get all namespaces for un-namespaced object.
printer
:=
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
[]
string
{})
printer
:=
NewHumanReadablePrinter
(
false
,
true
,
false
,
false
,
false
,
[]
string
{})
buffer
:=
&
bytes
.
Buffer
{}
buffer
:=
&
bytes
.
Buffer
{}
err
:=
printer
.
PrintObj
(
test
.
obj
,
buffer
)
err
:=
printer
.
PrintObj
(
test
.
obj
,
buffer
)
if
err
==
nil
{
if
err
==
nil
{
...
@@ -1041,7 +1041,7 @@ func TestPrintPod(t *testing.T) {
...
@@ -1041,7 +1041,7 @@ func TestPrintPod(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
printPod
(
&
test
.
pod
,
buf
,
false
,
false
,
true
,
[]
string
{
})
printPod
(
&
test
.
pod
,
buf
,
printOptions
{
false
,
false
,
false
,
true
,
false
,
[]
string
{}
})
// We ignore time
// We ignore time
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
expect
)
{
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
expect
)
{
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
...
@@ -1134,7 +1134,7 @@ func TestPrintNonTerminatedPod(t *testing.T) {
...
@@ -1134,7 +1134,7 @@ func TestPrintNonTerminatedPod(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
printPod
(
&
test
.
pod
,
buf
,
false
,
false
,
false
,
[]
string
{
})
printPod
(
&
test
.
pod
,
buf
,
printOptions
{
false
,
false
,
false
,
false
,
false
,
[]
string
{}
})
// We ignore time
// We ignore time
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
expect
)
{
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
expect
)
{
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
...
@@ -1194,7 +1194,7 @@ func TestPrintPodWithLabels(t *testing.T) {
...
@@ -1194,7 +1194,7 @@ func TestPrintPodWithLabels(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
printPod
(
&
test
.
pod
,
buf
,
false
,
false
,
false
,
test
.
labelColumns
)
printPod
(
&
test
.
pod
,
buf
,
printOptions
{
false
,
false
,
false
,
false
,
false
,
test
.
labelColumns
}
)
// We ignore time
// We ignore time
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
startsWith
)
||
!
strings
.
HasSuffix
(
buf
.
String
(),
test
.
endsWith
)
{
if
!
strings
.
HasPrefix
(
buf
.
String
(),
test
.
startsWith
)
||
!
strings
.
HasSuffix
(
buf
.
String
(),
test
.
endsWith
)
{
t
.
Fatalf
(
"Expected to start with: %s and end with: %s, but got: %s"
,
test
.
startsWith
,
test
.
endsWith
,
buf
.
String
())
t
.
Fatalf
(
"Expected to start with: %s and end with: %s, but got: %s"
,
test
.
startsWith
,
test
.
endsWith
,
buf
.
String
())
...
@@ -1255,7 +1255,7 @@ func TestPrintDeployment(t *testing.T) {
...
@@ -1255,7 +1255,7 @@ func TestPrintDeployment(t *testing.T) {
buf
:=
bytes
.
NewBuffer
([]
byte
{})
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
printDeployment
(
&
test
.
deployment
,
buf
,
false
,
false
,
true
,
[]
string
{
})
printDeployment
(
&
test
.
deployment
,
buf
,
printOptions
{
false
,
false
,
false
,
true
,
false
,
[]
string
{}
})
if
buf
.
String
()
!=
test
.
expect
{
if
buf
.
String
()
!=
test
.
expect
{
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
t
.
Fatalf
(
"Expected: %s, got: %s"
,
test
.
expect
,
buf
.
String
())
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment