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
b518a80c
Commit
b518a80c
authored
Nov 01, 2017
by
Mengqi Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for convert
parent
44aa7116
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
0 deletions
+182
-0
BUILD
pkg/kubectl/cmd/BUILD
+1
-0
convert_test.go
pkg/kubectl/cmd/convert_test.go
+127
-0
appsdeployment.yaml
test/fixtures/pkg/kubectl/cmd/convert/appsdeployment.yaml
+13
-0
extensionsdeployment.yaml
...ixtures/pkg/kubectl/cmd/convert/extensionsdeployment.yaml
+13
-0
v1HPA.yaml
test/fixtures/pkg/kubectl/cmd/convert/v1HPA.yaml
+12
-0
v2beta1HPA.yaml
test/fixtures/pkg/kubectl/cmd/convert/v2beta1HPA.yaml
+16
-0
No files found.
pkg/kubectl/cmd/BUILD
View file @
b518a80c
...
...
@@ -157,6 +157,7 @@ go_test(
"attach_test.go",
"clusterinfo_dump_test.go",
"cmd_test.go",
"convert_test.go",
"cp_test.go",
"create_clusterrole_test.go",
"create_clusterrolebinding_test.go",
...
...
pkg/kubectl/cmd/convert_test.go
0 → 100644
View file @
b518a80c
/*
Copyright 2017 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
cmd
import
(
"bytes"
"net/http"
"testing"
"k8s.io/client-go/rest/fake"
cmdtesting
"k8s.io/kubernetes/pkg/kubectl/cmd/testing"
"k8s.io/kubernetes/pkg/printers"
)
type
testcase
struct
{
name
string
file
string
outputVersion
string
fields
[]
checkField
}
type
checkField
struct
{
template
string
expected
string
}
func
TestConvertObject
(
t
*
testing
.
T
)
{
testcases
:=
[]
testcase
{
{
name
:
"apps deployment to extensions deployment"
,
file
:
"../../../test/fixtures/pkg/kubectl/cmd/convert/appsdeployment.yaml"
,
outputVersion
:
"extensions/v1beta1"
,
fields
:
[]
checkField
{
{
template
:
"{{.apiVersion}}"
,
expected
:
"extensions/v1beta1"
,
},
},
},
{
name
:
"extensions deployment to apps deployment"
,
file
:
"../../../test/fixtures/pkg/kubectl/cmd/convert/extensionsdeployment.yaml"
,
outputVersion
:
"apps/v1beta2"
,
fields
:
[]
checkField
{
{
template
:
"{{.apiVersion}}"
,
expected
:
"apps/v1beta2"
,
},
},
},
{
name
:
"v1 HPA to v2beta1 HPA"
,
file
:
"../../../test/fixtures/pkg/kubectl/cmd/convert/v1HPA.yaml"
,
outputVersion
:
"autoscaling/v2beta1"
,
fields
:
[]
checkField
{
{
template
:
"{{.apiVersion}}"
,
expected
:
"autoscaling/v2beta1"
,
},
{
template
:
"{{(index .spec.metrics 0).resource.name}}"
,
expected
:
"cpu"
,
},
{
template
:
"{{(index .spec.metrics 0).resource.targetAverageUtilization}}"
,
expected
:
"50"
,
},
},
},
{
name
:
"v2beta1 HPA to v1 HPA"
,
file
:
"../../../test/fixtures/pkg/kubectl/cmd/convert/v2beta1HPA.yaml"
,
outputVersion
:
"autoscaling/v1"
,
fields
:
[]
checkField
{
{
template
:
"{{.apiVersion}}"
,
expected
:
"autoscaling/v1"
,
},
{
template
:
"{{.spec.targetCPUUtilizationPercentage}}"
,
expected
:
"50"
,
},
},
},
}
f
,
tf
,
_
,
_
:=
cmdtesting
.
NewAPIFactory
()
tf
.
UnstructuredClient
=
&
fake
.
RESTClient
{
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
t
.
Fatalf
(
"unexpected request: %#v
\n
%#v"
,
req
.
URL
,
req
)
return
nil
,
nil
}),
}
tf
.
Namespace
=
"test"
buf
:=
bytes
.
NewBuffer
([]
byte
{})
for
_
,
tc
:=
range
testcases
{
cmd
:=
NewCmdConvert
(
f
,
buf
)
cmd
.
Flags
()
.
Set
(
"filename"
,
tc
.
file
)
cmd
.
Flags
()
.
Set
(
"output-version"
,
tc
.
outputVersion
)
cmd
.
Flags
()
.
Set
(
"local"
,
"true"
)
cmd
.
Flags
()
.
Set
(
"output"
,
"go-template"
)
for
_
,
field
:=
range
tc
.
fields
{
buf
.
Reset
()
tf
.
Printer
,
_
=
printers
.
NewTemplatePrinter
([]
byte
(
field
.
template
))
cmd
.
Run
(
cmd
,
[]
string
{})
if
buf
.
String
()
!=
field
.
expected
{
t
.
Errorf
(
"unexpected output when converting %s to %q, expected: %q, but got %q"
,
tc
.
file
,
tc
.
outputVersion
,
field
.
expected
,
buf
.
String
())
}
}
}
}
test/fixtures/pkg/kubectl/cmd/convert/appsdeployment.yaml
0 → 100644
View file @
b518a80c
apiVersion
:
apps/v1beta2
kind
:
Deployment
metadata
:
name
:
nginx-deployment
spec
:
template
:
metadata
:
labels
:
name
:
nginx
spec
:
containers
:
-
name
:
nginx
image
:
nginx
test/fixtures/pkg/kubectl/cmd/convert/extensionsdeployment.yaml
0 → 100644
View file @
b518a80c
apiVersion
:
extensions/v1beta1
kind
:
Deployment
metadata
:
name
:
nginx-deployment
spec
:
template
:
metadata
:
labels
:
name
:
nginx
spec
:
containers
:
-
name
:
nginx
image
:
nginx
test/fixtures/pkg/kubectl/cmd/convert/v1HPA.yaml
0 → 100644
View file @
b518a80c
apiVersion
:
autoscaling/v1
kind
:
HorizontalPodAutoscaler
metadata
:
name
:
php-apache
spec
:
scaleTargetRef
:
apiVersion
:
apps/v1beta1
kind
:
Deployment
name
:
php-apache
minReplicas
:
1
maxReplicas
:
10
targetCPUUtilizationPercentage
:
50
test/fixtures/pkg/kubectl/cmd/convert/v2beta1HPA.yaml
0 → 100644
View file @
b518a80c
apiVersion
:
autoscaling/v2beta1
kind
:
HorizontalPodAutoscaler
metadata
:
name
:
php-apache
spec
:
scaleTargetRef
:
apiVersion
:
apps/v1beta1
kind
:
Deployment
name
:
php-apache
minReplicas
:
1
maxReplicas
:
10
metrics
:
-
type
:
Resource
resource
:
name
:
cpu
targetAverageUtilization
:
50
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