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
83ff8f2d
Commit
83ff8f2d
authored
May 03, 2017
by
Phillip Wittrock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Print a newline after ginkgo tests so the test infra doesn't think that they fail
Fixes #45279
parent
f84b61b4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
106 deletions
+131
-106
BUILD
pkg/kubectl/cmd/util/openapi/BUILD
+19
-19
openapi.go
pkg/kubectl/cmd/util/openapi/openapi.go
+3
-3
openapi_cache.go
pkg/kubectl/cmd/util/openapi/openapi_cache.go
+13
-13
openapi_cache_test.go
pkg/kubectl/cmd/util/openapi/openapi_cache_test.go
+19
-17
openapi_getter.go
pkg/kubectl/cmd/util/openapi/openapi_getter.go
+3
-3
openapi_getter_test.go
pkg/kubectl/cmd/util/openapi/openapi_getter_test.go
+7
-5
openapi_suite_test.go
pkg/kubectl/cmd/util/openapi/openapi_suite_test.go
+21
-1
openapi_test.go
pkg/kubectl/cmd/util/openapi/openapi_test.go
+46
-45
No files found.
pkg/kubectl/cmd/util/openapi/BUILD
View file @
83ff8f2d
...
...
@@ -8,24 +8,6 @@ load(
"go_test",
)
go_test(
name = "go_default_test",
srcs = [
"openapi_cache_test.go",
"openapi_getter_test.go",
"openapi_test.go",
],
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//vendor/github.com/go-openapi/loads:go_default_library",
"//vendor/github.com/go-openapi/spec:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
...
...
@@ -47,11 +29,24 @@ go_library(
go_test(
name = "go_default_xtest",
srcs = ["openapi_suite_test.go"],
size = "small",
srcs = [
"openapi_cache_test.go",
"openapi_getter_test.go",
"openapi_suite_test.go",
"openapi_test.go",
],
data = ["//api/openapi-spec:swagger-spec"],
tags = ["automanaged"],
deps = [
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//vendor/github.com/go-openapi/loads:go_default_library",
"//vendor/github.com/go-openapi/spec:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/ginkgo/config:go_default_library",
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
...
...
@@ -67,3 +62,8 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)
filegroup(
name = "testdata",
srcs = glob(["testdata/*"]),
)
pkg/kubectl/cmd/util/openapi/openapi.go
View file @
83ff8f2d
...
...
@@ -133,8 +133,8 @@ type Type struct {
Extensions
spec
.
Extensions
}
//
n
ewOpenAPIData parses the resource definitions in openapi data by groupversionkind and name
func
n
ewOpenAPIData
(
s
*
spec
.
Swagger
)
(
*
Resources
,
error
)
{
//
N
ewOpenAPIData parses the resource definitions in openapi data by groupversionkind and name
func
N
ewOpenAPIData
(
s
*
spec
.
Swagger
)
(
*
Resources
,
error
)
{
o
:=
&
Resources
{
GroupVersionKindToName
:
map
[
schema
.
GroupVersionKind
]
string
{},
NameToDefinition
:
map
[
string
]
Kind
{},
...
...
@@ -338,7 +338,7 @@ func (o *Resources) nameForDefinitionField(s spec.Schema) string {
return
strings
.
Replace
(
p
,
"/definitions/"
,
""
,
-
1
)
}
// getGroupVersionKind implements
o
penAPIData
// getGroupVersionKind implements
O
penAPIData
// getGVK parses the gropuversionkind for a resource definition from the x-kubernetes
// extensions
// Expected format for s.Extensions: map[string][]map[string]string
...
...
pkg/kubectl/cmd/util/openapi/openapi_cache.go
View file @
83ff8f2d
...
...
@@ -37,31 +37,31 @@ func init() {
const
openapiFileName
=
"openapi_cache"
type
c
achingOpenAPIClient
struct
{
type
C
achingOpenAPIClient
struct
{
version
string
client
discovery
.
OpenAPISchemaInterface
cacheDirName
string
}
//
n
ewCachingOpenAPIClient returns a new discovery.OpenAPISchemaInterface
//
N
ewCachingOpenAPIClient returns a new discovery.OpenAPISchemaInterface
// that will read the openapi spec from a local cache if it exists, and
// if not will then fetch an openapi spec using a client.
// client: used to fetch a new openapi spec if a local cache is not found
// version: the server version and used as part of the cache file location
// cacheDir: the directory under which the cache file will be written
func
newCachingOpenAPIClient
(
client
discovery
.
OpenAPISchemaInterface
,
version
,
cacheDir
string
)
*
c
achingOpenAPIClient
{
return
&
c
achingOpenAPIClient
{
func
NewCachingOpenAPIClient
(
client
discovery
.
OpenAPISchemaInterface
,
version
,
cacheDir
string
)
*
C
achingOpenAPIClient
{
return
&
C
achingOpenAPIClient
{
client
:
client
,
version
:
version
,
cacheDirName
:
cacheDir
,
}
}
//
o
penAPIData returns an openapi spec.
//
O
penAPIData returns an openapi spec.
// It will first attempt to read the spec from a local cache
// If it cannot read a local cache, it will read the file
// using the client and then write the cache.
func
(
c
*
cachingOpenAPIClient
)
o
penAPIData
()
(
*
Resources
,
error
)
{
func
(
c
*
CachingOpenAPIClient
)
O
penAPIData
()
(
*
Resources
,
error
)
{
// Try to use the cached version
if
c
.
useCache
()
{
doc
,
err
:=
c
.
readOpenAPICache
()
...
...
@@ -77,7 +77,7 @@ func (c *cachingOpenAPIClient) openAPIData() (*Resources, error) {
return
nil
,
err
}
oa
,
err
:=
n
ewOpenAPIData
(
s
)
oa
,
err
:=
N
ewOpenAPIData
(
s
)
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"Failed to parse openapi data %v"
,
err
)
return
nil
,
err
...
...
@@ -97,12 +97,12 @@ func (c *cachingOpenAPIClient) openAPIData() (*Resources, error) {
}
// useCache returns true if the client should try to use the cache file
func
(
c
*
c
achingOpenAPIClient
)
useCache
()
bool
{
func
(
c
*
C
achingOpenAPIClient
)
useCache
()
bool
{
return
len
(
c
.
version
)
>
0
&&
len
(
c
.
cacheDirName
)
>
0
}
// readOpenAPICache tries to read the openapi spec from the local file cache
func
(
c
*
c
achingOpenAPIClient
)
readOpenAPICache
()
(
*
Resources
,
error
)
{
func
(
c
*
C
achingOpenAPIClient
)
readOpenAPICache
()
(
*
Resources
,
error
)
{
// Get the filename to read
filename
:=
c
.
openAPICacheFilename
()
...
...
@@ -119,7 +119,7 @@ func (c *cachingOpenAPIClient) readOpenAPICache() (*Resources, error) {
}
// decodeSpec binary decodes the openapi spec
func
(
c
*
c
achingOpenAPIClient
)
decodeSpec
(
data
[]
byte
)
(
*
Resources
,
error
)
{
func
(
c
*
C
achingOpenAPIClient
)
decodeSpec
(
data
[]
byte
)
(
*
Resources
,
error
)
{
b
:=
bytes
.
NewBuffer
(
data
)
d
:=
gob
.
NewDecoder
(
b
)
parsed
:=
&
Resources
{}
...
...
@@ -128,7 +128,7 @@ func (c *cachingOpenAPIClient) decodeSpec(data []byte) (*Resources, error) {
}
// encodeSpec binary encodes the openapi spec
func
(
c
*
c
achingOpenAPIClient
)
encodeSpec
(
parsed
*
Resources
)
([]
byte
,
error
)
{
func
(
c
*
C
achingOpenAPIClient
)
encodeSpec
(
parsed
*
Resources
)
([]
byte
,
error
)
{
b
:=
&
bytes
.
Buffer
{}
e
:=
gob
.
NewEncoder
(
b
)
err
:=
e
.
Encode
(
parsed
)
...
...
@@ -138,7 +138,7 @@ func (c *cachingOpenAPIClient) encodeSpec(parsed *Resources) ([]byte, error) {
// writeToCache tries to write the openapi spec to the local file cache.
// writes the data to a new tempfile, and then links the cache file and the tempfile
func
(
c
*
c
achingOpenAPIClient
)
writeToCache
(
parsed
*
Resources
)
error
{
func
(
c
*
C
achingOpenAPIClient
)
writeToCache
(
parsed
*
Resources
)
error
{
// Get the constant filename used to read the cache.
cacheFile
:=
c
.
openAPICacheFilename
()
...
...
@@ -168,7 +168,7 @@ func (c *cachingOpenAPIClient) writeToCache(parsed *Resources) error {
}
// openAPICacheFilename returns the filename to read the cache from
func
(
c
*
c
achingOpenAPIClient
)
openAPICacheFilename
()
string
{
func
(
c
*
C
achingOpenAPIClient
)
openAPICacheFilename
()
string
{
// Cache using the client and server versions
return
filepath
.
Join
(
c
.
cacheDirName
,
c
.
version
,
version
.
Get
()
.
GitVersion
,
openapiFileName
)
}
...
...
pkg/kubectl/cmd/util/openapi/openapi_cache_test.go
View file @
83ff8f2d
...
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
openapi
package
openapi
_test
import
(
"fmt"
...
...
@@ -27,25 +27,27 @@ import (
"github.com/go-openapi/spec"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
)
var
_
=
Describe
(
"When reading openAPIData"
,
func
()
{
var
tmpDir
string
var
err
error
var
client
*
fakeOpenAPIClient
var
instance
*
c
achingOpenAPIClient
var
expectedData
*
Resources
var
instance
*
openapi
.
C
achingOpenAPIClient
var
expectedData
*
openapi
.
Resources
BeforeEach
(
func
()
{
tmpDir
,
err
=
ioutil
.
TempDir
(
""
,
"openapi_cache_test"
)
Expect
(
err
)
.
To
(
BeNil
())
client
=
&
fakeOpenAPIClient
{}
instance
=
n
ewCachingOpenAPIClient
(
client
,
"v1.6"
,
tmpDir
)
instance
=
openapi
.
N
ewCachingOpenAPIClient
(
client
,
"v1.6"
,
tmpDir
)
d
,
err
:=
data
.
OpenAPISchema
()
Expect
(
err
)
.
To
(
BeNil
())
expectedData
,
err
=
n
ewOpenAPIData
(
d
)
expectedData
,
err
=
openapi
.
N
ewOpenAPIData
(
d
)
Expect
(
err
)
.
To
(
BeNil
())
})
...
...
@@ -55,7 +57,7 @@ var _ = Describe("When reading openAPIData", func() {
It
(
"should write to the cache"
,
func
()
{
By
(
"getting the live openapi spec from the server"
)
result
,
err
:=
instance
.
o
penAPIData
()
result
,
err
:=
instance
.
O
penAPIData
()
Expect
(
err
)
.
To
(
BeNil
())
expectEqual
(
result
,
expectedData
)
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
...
...
@@ -77,13 +79,13 @@ var _ = Describe("When reading openAPIData", func() {
It
(
"should read from the cache"
,
func
()
{
// First call should use the client
result
,
err
:=
instance
.
o
penAPIData
()
result
,
err
:=
instance
.
O
penAPIData
()
Expect
(
err
)
.
To
(
BeNil
())
expectEqual
(
result
,
expectedData
)
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
// Second call shouldn't use the client
result
,
err
=
instance
.
o
penAPIData
()
result
,
err
=
instance
.
O
penAPIData
()
Expect
(
err
)
.
To
(
BeNil
())
expectEqual
(
result
,
expectedData
)
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
...
...
@@ -96,7 +98,7 @@ var _ = Describe("When reading openAPIData", func() {
It
(
"propagate errors that are encountered"
,
func
()
{
// Expect an error
client
.
err
=
fmt
.
Errorf
(
"expected error"
)
result
,
err
:=
instance
.
o
penAPIData
()
result
,
err
:=
instance
.
O
penAPIData
()
Expect
(
err
.
Error
())
.
To
(
Equal
(
client
.
err
.
Error
()))
Expect
(
result
)
.
To
(
BeNil
())
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
...
...
@@ -107,7 +109,7 @@ var _ = Describe("When reading openAPIData", func() {
Expect
(
files
)
.
To
(
HaveLen
(
0
))
// Client error is not cached
result
,
err
=
instance
.
o
penAPIData
()
result
,
err
=
instance
.
O
penAPIData
()
Expect
(
err
.
Error
())
.
To
(
Equal
(
client
.
err
.
Error
()))
Expect
(
result
)
.
To
(
BeNil
())
Expect
(
client
.
calls
)
.
To
(
Equal
(
2
))
...
...
@@ -138,16 +140,16 @@ var _ = Describe("Reading openAPIData", func() {
It
(
"should not cache the result"
,
func
()
{
client
:=
&
fakeOpenAPIClient
{}
instance
:=
n
ewCachingOpenAPIClient
(
client
,
serverVersion
,
cacheDir
)
instance
:=
openapi
.
N
ewCachingOpenAPIClient
(
client
,
serverVersion
,
cacheDir
)
d
,
err
:=
data
.
OpenAPISchema
()
Expect
(
err
)
.
To
(
BeNil
())
expectedData
,
err
:=
n
ewOpenAPIData
(
d
)
expectedData
,
err
:=
openapi
.
N
ewOpenAPIData
(
d
)
Expect
(
err
)
.
To
(
BeNil
())
By
(
"getting the live openapi schema"
)
result
,
err
:=
instance
.
o
penAPIData
()
result
,
err
:=
instance
.
O
penAPIData
()
Expect
(
err
)
.
To
(
BeNil
())
expectEqual
(
result
,
expectedData
)
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
...
...
@@ -166,16 +168,16 @@ var _ = Describe("Reading openAPIData", func() {
It
(
"should not cache the result"
,
func
()
{
client
:=
&
fakeOpenAPIClient
{}
instance
:=
n
ewCachingOpenAPIClient
(
client
,
serverVersion
,
cacheDir
)
instance
:=
openapi
.
N
ewCachingOpenAPIClient
(
client
,
serverVersion
,
cacheDir
)
d
,
err
:=
data
.
OpenAPISchema
()
Expect
(
err
)
.
To
(
BeNil
())
expectedData
,
err
:=
n
ewOpenAPIData
(
d
)
expectedData
,
err
:=
openapi
.
N
ewOpenAPIData
(
d
)
Expect
(
err
)
.
To
(
BeNil
())
By
(
"getting the live openapi schema"
)
result
,
err
:=
instance
.
o
penAPIData
()
result
,
err
:=
instance
.
O
penAPIData
()
Expect
(
err
)
.
To
(
BeNil
())
expectEqual
(
result
,
expectedData
)
Expect
(
client
.
calls
)
.
To
(
Equal
(
1
))
...
...
@@ -200,7 +202,7 @@ func getFilenames(path string) ([]string, error) {
return
result
,
nil
}
func
expectEqual
(
a
*
Resources
,
b
*
Resources
)
{
func
expectEqual
(
a
*
openapi
.
Resources
,
b
*
openapi
.
Resources
)
{
Expect
(
a
.
NameToDefinition
)
.
To
(
HaveLen
(
len
(
b
.
NameToDefinition
)))
for
k
,
v
:=
range
a
.
NameToDefinition
{
Expect
(
v
)
.
To
(
Equal
(
b
.
NameToDefinition
[
k
]),
...
...
pkg/kubectl/cmd/util/openapi/openapi_getter.go
View file @
83ff8f2d
...
...
@@ -38,7 +38,7 @@ var _ Getter = &synchronizedOpenAPIGetter{}
// Getter is an interface for fetching openapi specs and parsing them into an Resources struct
type
Getter
interface
{
//
openAPIData returns the parsed o
penAPIData
//
OpenAPIData returns the parsed O
penAPIData
Get
()
(
*
Resources
,
error
)
}
...
...
@@ -55,8 +55,8 @@ func NewOpenAPIGetter(cacheDir, serverVersion string, openAPIClient discovery.Op
// Resources implements Getter
func
(
g
*
synchronizedOpenAPIGetter
)
Get
()
(
*
Resources
,
error
)
{
g
.
Do
(
func
()
{
client
:=
n
ewCachingOpenAPIClient
(
g
.
openAPIClient
,
g
.
serverVersion
,
g
.
cacheDir
)
result
,
err
:=
client
.
o
penAPIData
()
client
:=
N
ewCachingOpenAPIClient
(
g
.
openAPIClient
,
g
.
serverVersion
,
g
.
cacheDir
)
result
,
err
:=
client
.
O
penAPIData
()
if
err
!=
nil
{
g
.
err
=
err
return
...
...
pkg/kubectl/cmd/util/openapi/openapi_getter_test.go
View file @
83ff8f2d
...
...
@@ -14,29 +14,31 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package
openapi
package
openapi
_test
import
(
"fmt"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
)
var
_
=
Describe
(
"Getting the Resources"
,
func
()
{
var
client
*
fakeOpenAPIClient
var
expectedData
*
Resources
var
instance
Getter
var
expectedData
*
openapi
.
Resources
var
instance
openapi
.
Getter
BeforeEach
(
func
()
{
client
=
&
fakeOpenAPIClient
{}
d
,
err
:=
data
.
OpenAPISchema
()
Expect
(
err
)
.
To
(
BeNil
())
expectedData
,
err
=
n
ewOpenAPIData
(
d
)
expectedData
,
err
=
openapi
.
N
ewOpenAPIData
(
d
)
Expect
(
err
)
.
To
(
BeNil
())
instance
=
NewOpenAPIGetter
(
""
,
""
,
client
)
instance
=
openapi
.
NewOpenAPIGetter
(
""
,
""
,
client
)
})
Context
(
"when the server returns a successful result"
,
func
()
{
...
...
pkg/kubectl/cmd/util/openapi/openapi_suite_test.go
View file @
83ff8f2d
...
...
@@ -18,12 +18,32 @@ package openapi_test
import
(
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo/config"
.
"github.com/onsi/ginkgo/types"
.
"github.com/onsi/gomega"
"fmt"
"testing"
)
func
TestOpenapi
(
t
*
testing
.
T
)
{
RegisterFailHandler
(
Fail
)
RunSpecs
(
t
,
"Openapi Suite"
)
RunSpecs
WithDefaultAndCustomReporters
(
t
,
"Openapi Suite"
,
[]
Reporter
{
newlineReporter
{}}
)
}
// Print a newline after the default newlineReporter due to issue
// https://github.com/jstemmer/go-junit-report/issues/31
type
newlineReporter
struct
{}
func
(
newlineReporter
)
SpecSuiteWillBegin
(
config
GinkgoConfigType
,
summary
*
SuiteSummary
)
{}
func
(
newlineReporter
)
BeforeSuiteDidRun
(
setupSummary
*
SetupSummary
)
{}
func
(
newlineReporter
)
AfterSuiteDidRun
(
setupSummary
*
SetupSummary
)
{}
func
(
newlineReporter
)
SpecWillRun
(
specSummary
*
SpecSummary
)
{}
func
(
newlineReporter
)
SpecDidComplete
(
specSummary
*
SpecSummary
)
{}
// SpecSuiteDidEnd Prints a newline between "35 Passed | 0 Failed | 0 Pending | 0 Skipped" and "--- PASS:"
func
(
newlineReporter
)
SpecSuiteDidEnd
(
summary
*
SuiteSummary
)
{
fmt
.
Printf
(
"
\n
"
)
}
pkg/kubectl/cmd/util/openapi/openapi_test.go
View file @
83ff8f2d
This diff is collapsed.
Click to expand it.
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