123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- Copyright 2017 The Kubernetes Authors.
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- package explain
- import (
- "bytes"
- "testing"
- "k8s.io/apimachinery/pkg/runtime/schema"
- )
- func TestModel(t *testing.T) {
- gvk := schema.GroupVersionKind{
- Group: "",
- Version: "v1",
- Kind: "OneKind",
- }
- schema := resources.LookupResource(gvk)
- if schema == nil {
- t.Fatal("Couldn't find schema v1.OneKind")
- }
- tests := []struct {
- path []string
- want string
- }{
- {
- want: `KIND: OneKind
- VERSION: v1
- DESCRIPTION:
- OneKind has a short description
- FIELDS:
- field1 <Object> -required-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ut lacus ac
- enim vulputate imperdiet ac accumsan risus. Integer vel accumsan lectus.
- Praesent tempus nulla id tortor luctus, quis varius nulla laoreet. Ut orci
- nisi, suscipit id velit sed, blandit eleifend turpis. Curabitur tempus ante
- at lectus viverra, a mattis augue euismod. Morbi quam ligula, porttitor sit
- amet lacus non, interdum pulvinar tortor. Praesent accumsan risus et ipsum
- dictum, vel ullamcorper lorem egestas.
- field2 <[]map[string]string>
- This is an array of object of PrimitiveDef
- `,
- path: []string{},
- },
- {
- want: `KIND: OneKind
- VERSION: v1
- RESOURCE: field1 <Object>
- DESCRIPTION:
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ut lacus ac
- enim vulputate imperdiet ac accumsan risus. Integer vel accumsan lectus.
- Praesent tempus nulla id tortor luctus, quis varius nulla laoreet. Ut orci
- nisi, suscipit id velit sed, blandit eleifend turpis. Curabitur tempus ante
- at lectus viverra, a mattis augue euismod. Morbi quam ligula, porttitor sit
- amet lacus non, interdum pulvinar tortor. Praesent accumsan risus et ipsum
- dictum, vel ullamcorper lorem egestas.
- This is another kind of Kind
- FIELDS:
- array <[]integer>
- This array must be an array of int
- int <integer>
- This int must be an int
- object <map[string]string>
- This is an object of string
- primitive <string>
- string <string> -required-
- This string must be a string
- `,
- path: []string{"field1"},
- },
- {
- want: `KIND: OneKind
- VERSION: v1
- FIELD: string <string>
- DESCRIPTION:
- This string must be a string
- `,
- path: []string{"field1", "string"},
- },
- {
- want: `KIND: OneKind
- VERSION: v1
- FIELD: array <[]integer>
- DESCRIPTION:
- This array must be an array of int
- This is an int in an array
- `,
- path: []string{"field1", "array"},
- },
- }
- for _, test := range tests {
- buf := bytes.Buffer{}
- if err := PrintModelDescription(test.path, &buf, schema, gvk, false); err != nil {
- t.Fatalf("Failed to PrintModelDescription for path %v: %v", test.path, err)
- }
- got := buf.String()
- if got != test.want {
- t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), test.want)
- }
- }
- }
- func TestCRDModel(t *testing.T) {
- gvk := schema.GroupVersionKind{
- Group: "",
- Version: "v1",
- Kind: "CrdKind",
- }
- schema := resources.LookupResource(gvk)
- if schema == nil {
- t.Fatal("Couldn't find schema v1.CrdKind")
- }
- tests := []struct {
- path []string
- want string
- }{
- {
- path: []string{},
- want: `KIND: CrdKind
- VERSION: v1
- DESCRIPTION:
- <empty>
- `,
- },
- }
- for _, test := range tests {
- buf := bytes.Buffer{}
- if err := PrintModelDescription(test.path, &buf, schema, gvk, false); err != nil {
- t.Fatalf("Failed to PrintModelDescription for path %v: %v", test.path, err)
- }
- got := buf.String()
- if got != test.want {
- t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), test.want)
- }
- }
- }
|