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
12a8848b
Commit
12a8848b
authored
Nov 14, 2017
by
stewart-yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add UT for testapi.go
parent
2d64ce5e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
2 deletions
+39
-2
testapi_test.go
pkg/api/testapi/testapi_test.go
+39
-2
No files found.
pkg/api/testapi/testapi_test.go
View file @
12a8848b
...
@@ -25,8 +25,6 @@ import (
...
@@ -25,8 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
)
)
// TODO these tests don't add much value for testing things that have groups
func
TestResourcePathWithPrefix
(
t
*
testing
.
T
)
{
func
TestResourcePathWithPrefix
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
prefix
string
prefix
string
...
@@ -46,6 +44,25 @@ func TestResourcePathWithPrefix(t *testing.T) {
...
@@ -46,6 +44,25 @@ func TestResourcePathWithPrefix(t *testing.T) {
t
.
Errorf
(
"Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
t
.
Errorf
(
"Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
}
testGroupCases
:=
[]
struct
{
prefix
string
resource
string
namespace
string
name
string
expected
string
}{
{
"prefix"
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/apis/"
+
Admission
.
GroupVersion
()
.
Group
+
"/"
+
Admission
.
GroupVersion
()
.
Version
+
"/prefix/namespaces/mynamespace/resource/myresource"
},
{
"prefix"
,
"resource"
,
""
,
"myresource"
,
"/apis/"
+
Admission
.
GroupVersion
()
.
Group
+
"/"
+
Admission
.
GroupVersion
()
.
Version
+
"/prefix/resource/myresource"
},
{
"prefix"
,
"resource"
,
"mynamespace"
,
""
,
"/apis/"
+
Admission
.
GroupVersion
()
.
Group
+
"/"
+
Admission
.
GroupVersion
()
.
Version
+
"/prefix/namespaces/mynamespace/resource"
},
{
"prefix"
,
"resource"
,
""
,
""
,
"/apis/"
+
Admission
.
GroupVersion
()
.
Group
+
"/"
+
Admission
.
GroupVersion
()
.
Version
+
"/prefix/resource"
},
{
""
,
"resource"
,
"mynamespace"
,
"myresource"
,
"/apis/"
+
Admission
.
GroupVersion
()
.
Group
+
"/"
+
Admission
.
GroupVersion
()
.
Version
+
"/namespaces/mynamespace/resource/myresource"
},
}
for
_
,
item
:=
range
testGroupCases
{
if
actual
:=
Admission
.
ResourcePathWithPrefix
(
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for prefix: %s, resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
prefix
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
}
func
TestResourcePath
(
t
*
testing
.
T
)
{
func
TestResourcePath
(
t
*
testing
.
T
)
{
...
@@ -67,6 +84,26 @@ func TestResourcePath(t *testing.T) {
...
@@ -67,6 +84,26 @@ func TestResourcePath(t *testing.T) {
}
}
}
}
func
TestSubResourcePath
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
resource
string
namespace
string
name
string
sub
string
expected
string
}{
{
"resource"
,
"mynamespace"
,
"myresource"
,
"mysub"
,
"/api/"
+
Default
.
GroupVersion
()
.
Version
+
"/namespaces/mynamespace/resource/myresource/mysub"
},
{
"resource"
,
""
,
"myresource"
,
"mysub"
,
"/api/"
+
Default
.
GroupVersion
()
.
Version
+
"/resource/myresource/mysub"
},
{
"resource"
,
"mynamespace"
,
""
,
"mysub"
,
"/api/"
+
Default
.
GroupVersion
()
.
Version
+
"/namespaces/mynamespace/resource/mysub"
},
{
"resource"
,
""
,
""
,
"mysub"
,
"/api/"
+
Default
.
GroupVersion
()
.
Version
+
"/resource/mysub"
},
}
for
_
,
item
:=
range
testCases
{
if
actual
:=
Default
.
SubResourcePath
(
item
.
resource
,
item
.
namespace
,
item
.
name
,
item
.
sub
);
actual
!=
item
.
expected
{
t
.
Errorf
(
"Expected: %s, got: %s for resource: %s, namespace: %s and name: %s"
,
item
.
expected
,
actual
,
item
.
resource
,
item
.
namespace
,
item
.
name
)
}
}
}
var
status
=
&
metav1
.
Status
{
var
status
=
&
metav1
.
Status
{
Status
:
metav1
.
StatusFailure
,
Status
:
metav1
.
StatusFailure
,
Code
:
200
,
Code
:
200
,
...
...
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