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
891bd3e5
Commit
891bd3e5
authored
Jul 07, 2016
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a test
parent
cf5010ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
2 deletions
+86
-2
registered.go
pkg/apimachinery/registered/registered.go
+14
-2
registered_test.go
pkg/apimachinery/registered/registered_test.go
+72
-0
No files found.
pkg/apimachinery/registered/registered.go
View file @
891bd3e5
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"os"
"os"
"sort"
"sort"
"strings"
"strings"
"sync"
"github.com/golang/glog"
"github.com/golang/glog"
...
@@ -56,6 +55,10 @@ var (
...
@@ -56,6 +55,10 @@ var (
)
)
func
init
()
{
func
init
()
{
loadKubeAPIVersions
()
}
func
loadKubeAPIVersions
()
{
// Env var KUBE_API_VERSIONS is a comma separated list of API versions that
// Env var KUBE_API_VERSIONS is a comma separated list of API versions that
// should be registered in the scheme.
// should be registered in the scheme.
kubeAPIVersions
:=
os
.
Getenv
(
"KUBE_API_VERSIONS"
)
kubeAPIVersions
:=
os
.
Getenv
(
"KUBE_API_VERSIONS"
)
...
@@ -71,6 +74,16 @@ func init() {
...
@@ -71,6 +74,16 @@ func init() {
}
}
}
}
// Resets everything to clean room for the start of a test
func
clearForTesting
()
{
registeredVersions
=
map
[
unversioned
.
GroupVersion
]
struct
{}{}
thirdPartyGroupVersions
=
[]
unversioned
.
GroupVersion
{}
enabledVersions
=
map
[
unversioned
.
GroupVersion
]
struct
{}{}
groupMetaMap
=
map
[
string
]
*
apimachinery
.
GroupMeta
{}
envRequestedVersions
=
[]
unversioned
.
GroupVersion
{}
loadKubeAPIVersions
()
}
// RegisterVersions adds the given group versions to the list of registered group versions.
// RegisterVersions adds the given group versions to the list of registered group versions.
func
RegisterVersions
(
availableVersions
[]
unversioned
.
GroupVersion
)
{
func
RegisterVersions
(
availableVersions
[]
unversioned
.
GroupVersion
)
{
for
_
,
v
:=
range
availableVersions
{
for
_
,
v
:=
range
availableVersions
{
...
@@ -209,7 +222,6 @@ func AddThirdPartyAPIGroupVersions(gvs ...unversioned.GroupVersion) []unversione
...
@@ -209,7 +222,6 @@ func AddThirdPartyAPIGroupVersions(gvs ...unversioned.GroupVersion) []unversione
RegisterVersions
(
filteredGVs
)
RegisterVersions
(
filteredGVs
)
EnableVersions
(
filteredGVs
...
)
EnableVersions
(
filteredGVs
...
)
thirdPartyGroupVersions
=
append
(
thirdPartyGroupVersions
,
filteredGVs
...
)
thirdPartyGroupVersions
=
append
(
thirdPartyGroupVersions
,
filteredGVs
...
)
return
skippedGVs
return
skippedGVs
}
}
...
...
pkg/apimachinery/registered/registered_test.go
View file @
891bd3e5
...
@@ -23,6 +23,78 @@ import (
...
@@ -23,6 +23,78 @@ import (
"k8s.io/kubernetes/pkg/apimachinery"
"k8s.io/kubernetes/pkg/apimachinery"
)
)
func
TestAddThirdPartyVersionsBasic
(
t
*
testing
.
T
)
{
clearForTesting
()
registered
:=
[]
unversioned
.
GroupVersion
{
{
Group
:
""
,
Version
:
"v1"
,
},
}
skipped
:=
registered
thirdParty
:=
[]
unversioned
.
GroupVersion
{
{
Group
:
"company.com"
,
Version
:
"v1"
,
},
{
Group
:
"company.com"
,
Version
:
"v2"
,
},
}
gvs
:=
append
(
registered
,
thirdParty
...
)
RegisterVersions
(
registered
)
wasSkipped
:=
AddThirdPartyAPIGroupVersions
(
gvs
...
)
if
len
(
wasSkipped
)
!=
len
(
skipped
)
{
t
.
Errorf
(
"Expected %v, found %v"
,
skipped
,
wasSkipped
)
}
for
ix
:=
range
wasSkipped
{
found
:=
false
for
_
,
gv
:=
range
skipped
{
if
gv
.
String
()
==
wasSkipped
[
ix
]
.
String
()
{
found
=
true
break
}
}
if
!
found
{
t
.
Errorf
(
"Couldn't find %v in %v"
,
wasSkipped
[
ix
],
skipped
)
}
}
for
_
,
gv
:=
range
thirdParty
{
if
!
IsThirdPartyAPIGroupVersion
(
gv
)
{
t
.
Errorf
(
"Expected %v to be third party."
,
gv
)
}
}
}
func
TestAddThirdPartyVersionsMultiple
(
t
*
testing
.
T
)
{
clearForTesting
()
thirdParty
:=
[]
unversioned
.
GroupVersion
{
{
Group
:
"company.com"
,
Version
:
"v1"
,
},
{
Group
:
"company.com"
,
Version
:
"v2"
,
},
}
for
_
,
gv
:=
range
thirdParty
{
wasSkipped
:=
AddThirdPartyAPIGroupVersions
(
gv
)
if
len
(
wasSkipped
)
!=
0
{
t
.
Errorf
(
"Expected length 0, found %v"
,
wasSkipped
)
}
}
for
_
,
gv
:=
range
thirdParty
{
if
!
IsThirdPartyAPIGroupVersion
(
gv
)
{
t
.
Errorf
(
"Expected %v to be third party."
,
gv
)
}
}
}
func
TestAllPreferredGroupVersions
(
t
*
testing
.
T
)
{
func
TestAllPreferredGroupVersions
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
groupMetas
[]
apimachinery
.
GroupMeta
groupMetas
[]
apimachinery
.
GroupMeta
...
...
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