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
996bc521
Commit
996bc521
authored
Sep 28, 2017
by
Antoine Pelisse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
openapi: Add fake resource to simplify tests
parent
249caa95
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
BUILD
pkg/kubectl/cmd/util/openapi/testing/BUILD
+2
-0
openapi.go
pkg/kubectl/cmd/util/openapi/testing/openapi.go
+33
-0
No files found.
pkg/kubectl/cmd/util/openapi/testing/BUILD
View file @
996bc521
...
@@ -9,9 +9,11 @@ go_library(
...
@@ -9,9 +9,11 @@ go_library(
name = "go_default_library",
name = "go_default_library",
srcs = ["openapi.go"],
srcs = ["openapi.go"],
deps = [
deps = [
"//pkg/kubectl/cmd/util/openapi:go_default_library",
"//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library",
"//vendor/github.com/googleapis/gnostic/OpenAPIv2:go_default_library",
"//vendor/github.com/googleapis/gnostic/compiler:go_default_library",
"//vendor/github.com/googleapis/gnostic/compiler:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
"//vendor/gopkg.in/yaml.v2:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
],
)
)
...
...
pkg/kubectl/cmd/util/openapi/testing/openapi.go
View file @
996bc521
...
@@ -21,6 +21,9 @@ import (
...
@@ -21,6 +21,9 @@ import (
"os"
"os"
"sync"
"sync"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi"
yaml
"gopkg.in/yaml.v2"
yaml
"gopkg.in/yaml.v2"
"github.com/googleapis/gnostic/OpenAPIv2"
"github.com/googleapis/gnostic/OpenAPIv2"
...
@@ -87,3 +90,33 @@ func (f *FakeClient) OpenAPISchema() (*openapi_v2.Document, error) {
...
@@ -87,3 +90,33 @@ func (f *FakeClient) OpenAPISchema() (*openapi_v2.Document, error) {
return
f
.
fake
.
OpenAPISchema
()
return
f
.
fake
.
OpenAPISchema
()
}
}
// 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
// it's assuming that the file is there and everything will go fine.
type
FakeResources
struct
{
fake
Fake
}
var
_
openapi
.
Resources
=
&
FakeResources
{}
// NewFakeResources creates a new FakeResources.
func
NewFakeResources
(
path
string
)
*
FakeResources
{
return
&
FakeResources
{
fake
:
Fake
{
Path
:
path
},
}
}
// LookupResource will read the schema, parse it and return the
// resources. It doesn't return errors and will panic instead.
func
(
f
*
FakeResources
)
LookupResource
(
gvk
schema
.
GroupVersionKind
)
openapi
.
Schema
{
s
,
err
:=
f
.
fake
.
OpenAPISchema
()
if
err
!=
nil
{
panic
(
err
)
}
resources
,
err
:=
openapi
.
NewOpenAPIData
(
s
)
if
err
!=
nil
{
panic
(
err
)
}
return
resources
.
LookupResource
(
gvk
)
}
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