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
178a8f87
Commit
178a8f87
authored
May 31, 2018
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openapi: Remove FakeClient from testing library
And make a simplified version of it where needed.
parent
a1c8d3f5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
37 deletions
+20
-37
BUILD
pkg/kubectl/cmd/util/openapi/BUILD
+1
-0
openapi_getter_test.go
pkg/kubectl/cmd/util/openapi/openapi_getter_test.go
+19
-10
openapi.go
pkg/kubectl/cmd/util/openapi/testing/openapi.go
+0
-27
No files found.
pkg/kubectl/cmd/util/openapi/BUILD
View file @
178a8f87
...
@@ -36,6 +36,7 @@ go_test(
...
@@ -36,6 +36,7 @@ go_test(
deps = [
deps = [
":go_default_library",
":go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library",
"//vendor/github.com/onsi/ginkgo: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/config:go_default_library",
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
...
...
pkg/kubectl/cmd/util/openapi/openapi_getter_test.go
View file @
178a8f87
...
@@ -19,27 +19,36 @@ package openapi_test
...
@@ -19,27 +19,36 @@ package openapi_test
import
(
import
(
"fmt"
"fmt"
openapi_v2
"github.com/googleapis/gnostic/OpenAPIv2"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
tst
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
)
)
// FakeCounter returns a "null" document and the specified error. It
// also counts how many times the OpenAPISchema method has been called.
type
FakeCounter
struct
{
Calls
int
Err
error
}
func
(
f
*
FakeCounter
)
OpenAPISchema
()
(
*
openapi_v2
.
Document
,
error
)
{
f
.
Calls
=
f
.
Calls
+
1
return
nil
,
f
.
Err
}
var
_
=
Describe
(
"Getting the Resources"
,
func
()
{
var
_
=
Describe
(
"Getting the Resources"
,
func
()
{
var
client
*
tst
.
FakeClient
var
client
FakeCounter
var
expectedData
openapi
.
Resources
var
instance
openapi
.
Getter
var
instance
openapi
.
Getter
var
expectedData
openapi
.
Resources
BeforeEach
(
func
()
{
BeforeEach
(
func
()
{
client
=
tst
.
NewFakeClient
(
&
fakeSchema
)
client
=
FakeCounter
{}
d
,
err
:=
fakeSchema
.
OpenAPISchema
()
instance
=
openapi
.
NewOpenAPIGetter
(
&
client
)
var
err
error
expectedData
,
err
=
openapi
.
NewOpenAPIData
(
nil
)
Expect
(
err
)
.
To
(
BeNil
())
Expect
(
err
)
.
To
(
BeNil
())
expectedData
,
err
=
openapi
.
NewOpenAPIData
(
d
)
Expect
(
err
)
.
To
(
BeNil
())
instance
=
openapi
.
NewOpenAPIGetter
(
client
)
})
})
Context
(
"when the server returns a successful result"
,
func
()
{
Context
(
"when the server returns a successful result"
,
func
()
{
...
...
pkg/kubectl/cmd/util/openapi/testing/openapi.go
View file @
178a8f87
...
@@ -65,33 +65,6 @@ func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) {
...
@@ -65,33 +65,6 @@ func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) {
return
f
.
document
,
f
.
err
return
f
.
document
,
f
.
err
}
}
// FakeClient implements a dummy OpenAPISchemaInterface that uses the
// fake OpenAPI schema given as a parameter, and count the number of
// call to the function.
type
FakeClient
struct
{
Calls
int
Err
error
fake
*
Fake
}
// NewFakeClient creates a new FakeClient from the given Fake.
func
NewFakeClient
(
f
*
Fake
)
*
FakeClient
{
return
&
FakeClient
{
fake
:
f
}
}
// OpenAPISchema returns a OpenAPI Document as returned by the fake, but
// it also counts the number of calls.
func
(
f
*
FakeClient
)
OpenAPISchema
()
(
*
openapi_v2
.
Document
,
error
)
{
f
.
Calls
=
f
.
Calls
+
1
if
f
.
Err
!=
nil
{
return
nil
,
f
.
Err
}
return
f
.
fake
.
OpenAPISchema
()
}
// FakeResources is a wrapper to directly load the openapi schema from a
// FakeResources is a wrapper to directly load the openapi schema from a
// file, and get the schema for given GVK. This is only for test since
// file, and get the schema for given GVK. This is only for test since
// it's assuming that the file is there and everything will go fine.
// it's assuming that the file is there and everything will go fine.
...
...
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