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
6d117383
Commit
6d117383
authored
May 24, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix describer tests
parent
cf29a302
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
31 deletions
+60
-31
cmd_test.go
pkg/kubectl/cmd/cmd_test.go
+0
-14
describe_test.go
pkg/kubectl/cmd/describe_test.go
+60
-10
BUILD
pkg/kubectl/cmd/testing/BUILD
+0
-1
fake.go
pkg/kubectl/cmd/testing/fake.go
+0
-6
No files found.
pkg/kubectl/cmd/cmd_test.go
View file @
6d117383
...
...
@@ -39,7 +39,6 @@ import (
api
"k8s.io/kubernetes/pkg/apis/core"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/printers"
)
// This init should be removed after switching this command and its tests to user external types.
...
...
@@ -116,19 +115,6 @@ func testData() (*api.PodList, *api.ServiceList, *api.ReplicationControllerList)
return
pods
,
svc
,
rc
}
type
testDescriber
struct
{
Name
,
Namespace
string
Settings
printers
.
DescriberSettings
Output
string
Err
error
}
func
(
t
*
testDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
output
string
,
err
error
)
{
t
.
Namespace
,
t
.
Name
=
namespace
,
name
t
.
Settings
=
describerSettings
return
t
.
Output
,
t
.
Err
}
func
objBody
(
codec
runtime
.
Codec
,
obj
runtime
.
Object
)
io
.
ReadCloser
{
return
ioutil
.
NopCloser
(
bytes
.
NewReader
([]
byte
(
runtime
.
EncodeOrDie
(
codec
,
obj
))))
}
...
...
pkg/kubectl/cmd/describe_test.go
View file @
6d117383
...
...
@@ -22,20 +22,29 @@ import (
"strings"
"testing"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/client-go/rest/fake"
"k8s.io/kubernetes/pkg/api/legacyscheme"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/scheme"
"k8s.io/kubernetes/pkg/printers"
)
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func
TestDescribeUnknownSchemaObject
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
_
,
_
,
codec
:=
cmdtesting
.
NewExternalScheme
()
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalType
(
""
,
""
,
"foo"
))},
...
...
@@ -59,11 +68,16 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
func
TestDescribeUnknownNamespacedSchemaObject
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
_
,
_
,
codec
:=
cmdtesting
.
NewExternalScheme
()
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
cmdtesting
.
NewInternalNamespacedType
(
""
,
""
,
"foo"
,
"non-default"
))},
...
...
@@ -85,13 +99,18 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
}
func
TestDescribeObject
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
_
,
_
,
rc
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
d
:=
&
testDescriber
{
Output
:
"test output"
}
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
...
...
@@ -122,13 +141,18 @@ func TestDescribeObject(t *testing.T) {
}
func
TestDescribeListObjects
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
pods
,
_
,
_
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
d
:=
&
testDescriber
{
Output
:
"test output"
}
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
pods
)},
...
...
@@ -145,13 +169,18 @@ func TestDescribeListObjects(t *testing.T) {
}
func
TestDescribeObjectShowEvents
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
pods
,
_
,
_
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
d
:=
&
testDescriber
{
Output
:
"test output"
}
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
pods
)},
...
...
@@ -167,13 +196,18 @@ func TestDescribeObjectShowEvents(t *testing.T) {
}
func
TestDescribeObjectSkipEvents
(
t
*
testing
.
T
)
{
d
:=
&
testDescriber
{
Output
:
"test output"
}
oldFn
:=
cmdutil
.
DescriberFn
defer
func
()
{
cmdutil
.
DescriberFn
=
oldFn
}()
cmdutil
.
DescriberFn
=
d
.
describerFor
pods
,
_
,
_
:=
testData
()
tf
:=
cmdtesting
.
NewTestFactory
()
defer
tf
.
Cleanup
()
codec
:=
legacyscheme
.
Codecs
.
LegacyCodec
(
scheme
.
Scheme
.
PrioritizedVersionsAllGroups
()
...
)
d
:=
&
testDescriber
{
Output
:
"test output"
}
tf
.
DescriberVal
=
d
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
NegotiatedSerializer
:
unstructuredSerializer
,
Resp
:
&
http
.
Response
{
StatusCode
:
200
,
Header
:
defaultHeader
(),
Body
:
objBody
(
codec
,
pods
)},
...
...
@@ -215,3 +249,19 @@ func TestDescribeHelpMessage(t *testing.T) {
t
.
Errorf
(
"Expected not to contain:
\n
%v
\n
Got:
\n
%v
\n
"
,
unexpected
,
got
)
}
}
type
testDescriber
struct
{
Name
,
Namespace
string
Settings
printers
.
DescriberSettings
Output
string
Err
error
}
func
(
t
*
testDescriber
)
Describe
(
namespace
,
name
string
,
describerSettings
printers
.
DescriberSettings
)
(
output
string
,
err
error
)
{
t
.
Namespace
,
t
.
Name
=
namespace
,
name
t
.
Settings
=
describerSettings
return
t
.
Output
,
t
.
Err
}
func
(
t
*
testDescriber
)
describerFor
(
restClientGetter
genericclioptions
.
RESTClientGetter
,
mapping
*
meta
.
RESTMapping
)
(
printers
.
Describer
,
error
)
{
return
t
,
nil
}
pkg/kubectl/cmd/testing/BUILD
View file @
6d117383
...
...
@@ -18,7 +18,6 @@ go_library(
"//pkg/kubectl/genericclioptions:go_default_library",
"//pkg/kubectl/genericclioptions/resource:go_default_library",
"//pkg/kubectl/validation:go_default_library",
"//pkg/printers:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library",
...
...
pkg/kubectl/cmd/testing/fake.go
View file @
6d117383
...
...
@@ -52,7 +52,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/validation"
"k8s.io/kubernetes/pkg/printers"
)
// +k8s:deepcopy-gen=true
...
...
@@ -238,7 +237,6 @@ type TestFactory struct {
Client
kubectl
.
RESTClient
ScaleGetter
scaleclient
.
ScalesGetter
UnstructuredClient
kubectl
.
RESTClient
DescriberVal
printers
.
Describer
Namespace
string
ClientConfigVal
*
restclient
.
Config
CommandVal
string
...
...
@@ -312,10 +310,6 @@ func (f *TestFactory) UnstructuredClientForMapping(mapping *meta.RESTMapping) (r
return
f
.
UnstructuredClient
,
nil
}
func
(
f
*
TestFactory
)
Describer
(
*
meta
.
RESTMapping
)
(
printers
.
Describer
,
error
)
{
return
f
.
DescriberVal
,
nil
}
func
(
f
*
TestFactory
)
Validator
(
validate
bool
)
(
validation
.
Schema
,
error
)
{
return
validation
.
NullSchema
{},
nil
}
...
...
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