Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
a1ea9678
Commit
a1ea9678
authored
Feb 06, 2019
by
Ian Howell
Committed by
Elad Iwanir
Feb 07, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for checking sort order on helm get
Signed-off-by:
Ian Howell
<
ian.howell0@gmail.com
>
parent
cbf9ad11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
1 deletion
+132
-1
client.go
pkg/kube/client.go
+1
-1
client_test.go
pkg/kube/client_test.go
+131
-0
No files found.
pkg/kube/client.go
View file @
a1ea9678
...
@@ -266,8 +266,8 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
...
@@ -266,8 +266,8 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) {
// Now that each individual resource within the specific version/kind
// Now that each individual resource within the specific version/kind
// is sorted, we print each resource using the k8s printer
// is sorted, we print each resource using the k8s printer
vk
:=
objs
[
t
]
for
_
,
resourceName
:=
range
sortedResources
{
for
_
,
resourceName
:=
range
sortedResources
{
vk
:=
objs
[
t
]
if
err
:=
typePrinter
.
PrintObj
(
vk
[
resourceName
],
buf
);
err
!=
nil
{
if
err
:=
typePrinter
.
PrintObj
(
vk
[
resourceName
],
buf
);
err
!=
nil
{
c
.
Log
(
"failed to print object type %s, object: %q :
\n
%v"
,
t
,
resourceName
,
err
)
c
.
Log
(
"failed to print object type %s, object: %q :
\n
%v"
,
t
,
resourceName
,
err
)
return
""
,
err
return
""
,
err
...
...
pkg/kube/client_test.go
View file @
a1ea9678
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"sort"
"strings"
"strings"
"testing"
"testing"
...
@@ -77,6 +78,18 @@ func newPodList(names ...string) v1.PodList {
...
@@ -77,6 +78,18 @@ func newPodList(names ...string) v1.PodList {
return
list
return
list
}
}
func
newService
(
name
string
)
v1
.
Service
{
ns
:=
v1
.
NamespaceDefault
return
v1
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
name
,
Namespace
:
ns
,
SelfLink
:
"/api/v1/namespaces/default/services/"
+
name
,
},
Spec
:
v1
.
ServiceSpec
{},
}
}
func
notFoundBody
()
*
metav1
.
Status
{
func
notFoundBody
()
*
metav1
.
Status
{
return
&
metav1
.
Status
{
return
&
metav1
.
Status
{
Code
:
http
.
StatusNotFound
,
Code
:
http
.
StatusNotFound
,
...
@@ -280,6 +293,95 @@ func TestGet(t *testing.T) {
...
@@ -280,6 +293,95 @@ func TestGet(t *testing.T) {
}
}
}
}
func
TestResourceTypeSortOrder
(
t
*
testing
.
T
)
{
pod
:=
newPod
(
"my-pod"
)
service
:=
newService
(
"my-service"
)
c
:=
newTestClient
()
defer
c
.
Cleanup
()
c
.
TestFactory
.
UnstructuredClient
=
&
fake
.
RESTClient
{
GroupVersion
:
schema
.
GroupVersion
{
Version
:
"v1"
},
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
t
.
Logf
(
"got request %s %s"
,
p
,
m
)
switch
{
case
p
==
"/namespaces/default/pods/my-pod"
&&
m
==
"GET"
:
return
newResponse
(
200
,
&
pod
)
case
p
==
"/namespaces/default/services/my-service"
&&
m
==
"GET"
:
return
newResponse
(
200
,
&
service
)
default
:
t
.
Fatalf
(
"unexpected request: %s %s"
,
req
.
Method
,
req
.
URL
.
Path
)
return
nil
,
nil
}
}),
}
// Test sorting order
data
:=
strings
.
NewReader
(
testResourceTypeSortOrder
)
o
,
err
:=
c
.
Get
(
"default"
,
data
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected missing results, got %q"
,
err
)
}
podIndex
:=
strings
.
Index
(
o
,
"my-pod"
)
serviceIndex
:=
strings
.
Index
(
o
,
"my-service"
)
if
podIndex
==
-
1
{
t
.
Errorf
(
"Expected v1/Pod my-pod, got %s"
,
o
)
}
if
serviceIndex
==
-
1
{
t
.
Errorf
(
"Expected v1/Service my-service, got %s"
,
o
)
}
if
!
sort
.
IntsAreSorted
([]
int
{
podIndex
,
serviceIndex
})
{
t
.
Errorf
(
"Expected order: [v1/Pod v1/Service], got %s"
,
o
)
}
}
func
TestResourceSortOrder
(
t
*
testing
.
T
)
{
list
:=
newPodList
(
"albacore"
,
"coral"
,
"beluga"
)
c
:=
newTestClient
()
defer
c
.
Cleanup
()
c
.
TestFactory
.
UnstructuredClient
=
&
fake
.
RESTClient
{
GroupVersion
:
schema
.
GroupVersion
{
Version
:
"v1"
},
NegotiatedSerializer
:
unstructuredSerializer
,
Client
:
fake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
p
,
m
:=
req
.
URL
.
Path
,
req
.
Method
t
.
Logf
(
"got request %s %s"
,
p
,
m
)
switch
{
case
p
==
"/namespaces/default/pods/albacore"
&&
m
==
"GET"
:
return
newResponse
(
200
,
&
list
.
Items
[
0
])
case
p
==
"/namespaces/default/pods/coral"
&&
m
==
"GET"
:
return
newResponse
(
200
,
&
list
.
Items
[
1
])
case
p
==
"/namespaces/default/pods/beluga"
&&
m
==
"GET"
:
return
newResponse
(
200
,
&
list
.
Items
[
2
])
default
:
t
.
Fatalf
(
"unexpected request: %s %s"
,
req
.
Method
,
req
.
URL
.
Path
)
return
nil
,
nil
}
}),
}
// Test sorting order
data
:=
strings
.
NewReader
(
testResourceSortOrder
)
o
,
err
:=
c
.
Get
(
"default"
,
data
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected missing results, got %q"
,
err
)
}
albacoreIndex
:=
strings
.
Index
(
o
,
"albacore"
)
belugaIndex
:=
strings
.
Index
(
o
,
"beluga"
)
coralIndex
:=
strings
.
Index
(
o
,
"coral"
)
if
albacoreIndex
==
-
1
{
t
.
Errorf
(
"Expected v1/Pod albacore, got %s"
,
o
)
}
if
belugaIndex
==
-
1
{
t
.
Errorf
(
"Expected v1/Pod beluga, got %s"
,
o
)
}
if
coralIndex
==
-
1
{
t
.
Errorf
(
"Expected v1/Pod coral, got %s"
,
o
)
}
if
!
sort
.
IntsAreSorted
([]
int
{
albacoreIndex
,
belugaIndex
,
coralIndex
})
{
t
.
Errorf
(
"Expected order: [albacore beluga coral], got %s"
,
o
)
}
}
func
TestPerform
(
t
*
testing
.
T
)
{
func
TestPerform
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
...
@@ -361,6 +463,35 @@ func TestReal(t *testing.T) {
...
@@ -361,6 +463,35 @@ func TestReal(t *testing.T) {
}
}
}
}
const
testResourceTypeSortOrder
=
`
kind: Service
apiVersion: v1
metadata:
name: my-service
---
kind: Pod
apiVersion: v1
metadata:
name: my-pod
`
const
testResourceSortOrder
=
`
kind: Pod
apiVersion: v1
metadata:
name: albacore
---
kind: Pod
apiVersion: v1
metadata:
name: beluga
---
kind: Pod
apiVersion: v1
metadata:
name: coral
`
const
testServiceManifest
=
`
const
testServiceManifest
=
`
kind: Service
kind: Service
apiVersion: v1
apiVersion: v1
...
...
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