...

Source file src/k8s.io/kubectl/pkg/explain/fields_printer_test.go

Documentation: k8s.io/kubectl/pkg/explain

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package explain
    18  
    19  import (
    20  	"bytes"
    21  	"testing"
    22  
    23  	"k8s.io/apimachinery/pkg/runtime/schema"
    24  )
    25  
    26  func TestFields(t *testing.T) {
    27  	schema := resources.LookupResource(schema.GroupVersionKind{
    28  		Group:   "",
    29  		Version: "v1",
    30  		Kind:    "OneKind",
    31  	})
    32  	if schema == nil {
    33  		t.Fatal("Couldn't find schema v1.OneKind")
    34  	}
    35  
    36  	want := `field1	<Object> -required-
    37    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ut lacus ac
    38    enim vulputate imperdiet ac accumsan risus. Integer vel accumsan lectus.
    39    Praesent tempus nulla id tortor luctus, quis varius nulla laoreet. Ut orci
    40    nisi, suscipit id velit sed, blandit eleifend turpis. Curabitur tempus ante at
    41    lectus viverra, a mattis augue euismod. Morbi quam ligula, porttitor sit amet
    42    lacus non, interdum pulvinar tortor. Praesent accumsan risus et ipsum dictum,
    43    vel ullamcorper lorem egestas.
    44  
    45  field2	<[]map[string]string>
    46    This is an array of object of PrimitiveDef
    47  
    48  `
    49  
    50  	buf := bytes.Buffer{}
    51  	f := Formatter{
    52  		Writer: &buf,
    53  		Wrap:   80,
    54  	}
    55  	s, err := LookupSchemaForField(schema, []string{})
    56  	if err != nil {
    57  		t.Fatalf("Invalid path %v: %v", []string{}, err)
    58  	}
    59  	if err := (fieldsPrinterBuilder{Recursive: false}).BuildFieldsPrinter(&f).PrintFields(s); err != nil {
    60  		t.Fatalf("Failed to print fields: %v", err)
    61  	}
    62  	got := buf.String()
    63  	if got != want {
    64  		t.Errorf("Got:\n%v\nWant:\n%v\n", buf.String(), want)
    65  	}
    66  }
    67  

View as plain text