Fresh dep ensure

This commit is contained in:
Mike Cronce
2018-11-26 13:23:56 -05:00
parent 93cb8a04d7
commit 407478ab9a
9016 changed files with 551394 additions and 279685 deletions

View File

@ -15,8 +15,8 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/kubectl/explain",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/util/proto:go_default_library",
],
)
@ -46,12 +46,15 @@ go_test(
"recursive_fields_printer_test.go",
"typename_test.go",
],
data = ["test-swagger.json"],
data = [
"test-recursive-swagger.json",
"test-swagger.json",
],
embed = [":go_default_library"],
deps = [
"//pkg/kubectl/cmd/util/openapi/testing:go_default_library",
"//pkg/kubectl/scheme:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta/testrestmapper:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)

View File

@ -58,18 +58,20 @@ func TestSplitAndParseResourceRequest(t *testing.T) {
}
mapper := testrestmapper.TestOnlyStaticRESTMapper(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...)
for _, test := range tests {
gotInResource, gotFieldsPath, err := SplitAndParseResourceRequest(test.inresource, mapper)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotInResource, gotFieldsPath, err := SplitAndParseResourceRequest(tt.inresource, mapper)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !reflect.DeepEqual(test.expectedInResource, gotInResource) && !test.expectedErr {
t.Errorf("%s: expected inresource: %s, got: %s", test.name, test.expectedInResource, gotInResource)
}
if !reflect.DeepEqual(tt.expectedInResource, gotInResource) && !tt.expectedErr {
t.Errorf("%s: expected inresource: %s, got: %s", tt.name, tt.expectedInResource, gotInResource)
}
if !reflect.DeepEqual(test.expectedFieldsPath, gotFieldsPath) && !test.expectedErr {
t.Errorf("%s: expected fieldsPath: %s, got: %s", test.name, test.expectedFieldsPath, gotFieldsPath)
}
if !reflect.DeepEqual(tt.expectedFieldsPath, gotFieldsPath) && !tt.expectedErr {
t.Errorf("%s: expected fieldsPath: %s, got: %s", tt.name, tt.expectedFieldsPath, gotFieldsPath)
}
})
}
}

View File

@ -33,49 +33,57 @@ func TestFindField(t *testing.T) {
}
tests := []struct {
name string
path []string
err string
expectedPath string
}{
{
name: "test1",
path: []string{},
expectedPath: "OneKind",
},
{
name: "test2",
path: []string{"field1"},
expectedPath: "OneKind.field1",
},
{
name: "test3",
path: []string{"field1", "array"},
expectedPath: "OtherKind.array",
},
{
name: "test4",
path: []string{"field1", "what?"},
err: `field "what?" does not exist`,
},
{
name: "test5",
path: []string{"field1", ""},
err: `field "" does not exist`,
},
}
for _, test := range tests {
path, err := LookupSchemaForField(schema, test.path)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path, err := LookupSchemaForField(schema, tt.path)
gotErr := ""
if err != nil {
gotErr = err.Error()
}
gotErr := ""
if err != nil {
gotErr = err.Error()
}
gotPath := ""
if path != nil {
gotPath = path.GetPath().String()
}
gotPath := ""
if path != nil {
gotPath = path.GetPath().String()
}
if gotErr != test.err || gotPath != test.expectedPath {
t.Errorf("LookupSchemaForField(schema, %v) = (path: %q, err: %q), expected (path: %q, err: %q)",
test.path, gotPath, gotErr, test.expectedPath, test.err)
}
if gotErr != tt.err || gotPath != tt.expectedPath {
t.Errorf("LookupSchemaForField(schema, %v) = (path: %q, err: %q), expected (path: %q, err: %q)",
tt.path, gotPath, gotErr, tt.expectedPath, tt.err)
}
})
}
}

View File

@ -30,6 +30,7 @@ type recursiveFieldsPrinter struct {
var _ proto.SchemaVisitor = &recursiveFieldsPrinter{}
var _ fieldsPrinter = &recursiveFieldsPrinter{}
var visitedReferences = map[string]struct{}{}
// VisitArray is just a passthrough.
func (f *recursiveFieldsPrinter) VisitArray(a *proto.Array) {
@ -64,7 +65,12 @@ func (f *recursiveFieldsPrinter) VisitPrimitive(p *proto.Primitive) {
// VisitReference is just a passthrough.
func (f *recursiveFieldsPrinter) VisitReference(r proto.Reference) {
if _, ok := visitedReferences[r.Reference()]; ok {
return
}
visitedReferences[r.Reference()] = struct{}{}
r.SubSchema().Accept(f)
delete(visitedReferences, r.Reference())
}
// PrintFields will recursively print all the fields for the given

View File

@ -21,6 +21,7 @@ import (
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
tst "k8s.io/kubernetes/pkg/kubectl/cmd/util/openapi/testing"
)
func TestRecursiveFields(t *testing.T) {
@ -59,3 +60,42 @@ field2 <[]map[string]string>
t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), want)
}
}
func TestRecursiveFieldsWithSelfReferenceObjects(t *testing.T) {
var resources = tst.NewFakeResources("test-recursive-swagger.json")
schema := resources.LookupResource(schema.GroupVersionKind{
Group: "",
Version: "v2",
Kind: "OneKind",
})
if schema == nil {
t.Fatal("Couldn't find schema v2.OneKind")
}
want := `field1 <Object>
referencefield <Object>
referencesarray <[]Object>
field2 <Object>
reference <Object>
referencefield <Object>
referencesarray <[]Object>
string <string>
`
buf := bytes.Buffer{}
f := Formatter{
Writer: &buf,
Wrap: 80,
}
s, err := LookupSchemaForField(schema, []string{})
if err != nil {
t.Fatalf("Invalid path %v: %v", []string{}, err)
}
if err := (fieldsPrinterBuilder{Recursive: true}).BuildFieldsPrinter(&f).PrintFields(s); err != nil {
t.Fatalf("Failed to print fields: %v", err)
}
got := buf.String()
if got != want {
t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), want)
}
}

View File

@ -0,0 +1,63 @@
{
"swagger": "2.0",
"info": {
"title": "Kubernetes",
"version": "v1.9.0"
},
"paths": {},
"definitions": {
"OneKind": {
"description": "OneKind has a short description",
"required": [
"field1"
],
"properties": {
"field1": {
"description": "This is first reference field",
"$ref": "#/definitions/ReferenceKind"
},
"field2": {
"description": "This is other kind field with string and reference",
"$ref": "#/definitions/OtherKind"
}
},
"x-kubernetes-group-version-kind": [
{
"group": "",
"kind": "OneKind",
"version": "v2"
}
]
},
"ReferenceKind": {
"description": "This is reference Kind",
"properties": {
"referencefield": {
"description": "This is reference to itself.",
"$ref": "#/definitions/ReferenceKind"
},
"referencesarray": {
"description": "This is an array of references",
"type": "array",
"items": {
"description": "This is reference object",
"$ref": "#/definitions/ReferenceKind"
}
}
}
},
"OtherKind": {
"description": "This is other kind with string and reference fields",
"properties": {
"string": {
"description": "This string must be a string",
"type": "string"
},
"reference": {
"description": "This is reference field.",
"$ref": "#/definitions/ReferenceKind"
}
}
}
}
}

View File

@ -36,45 +36,53 @@ func TestReferenceTypename(t *testing.T) {
}
tests := []struct {
name string
path []string
expected string
}{
{
// Kind is "Object"
name: "test1",
path: []string{},
expected: "Object",
},
{
// Reference is equal to pointed type "Object"
name: "test2",
path: []string{"field1"},
expected: "Object",
},
{
// Reference is equal to pointed type "string"
name: "test3",
path: []string{"field1", "primitive"},
expected: "string",
},
{
// Array of object of reference to string
name: "test4",
path: []string{"field2"},
expected: "[]map[string]string",
},
{
// Array of integer
name: "test5",
path: []string{"field1", "array"},
expected: "[]integer",
},
}
for _, test := range tests {
s, err := LookupSchemaForField(schema, test.path)
if err != nil {
t.Fatalf("Invalid test.path %v: %v", test.path, err)
}
got := GetTypeName(s)
if got != test.expected {
t.Errorf("Got %q, expected %q", got, test.expected)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := LookupSchemaForField(schema, tt.path)
if err != nil {
t.Fatalf("Invalid tt.path %v: %v", tt.path, err)
}
got := GetTypeName(s)
if got != tt.expected {
t.Errorf("Got %q, expected %q", got, tt.expected)
}
})
}
}