...

Source file src/k8s.io/kubernetes/cmd/genkubedocs/postprocessing_test.go

Documentation: k8s.io/kubernetes/cmd/genkubedocs

     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 main
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestCleanupForInclude(t *testing.T) {
    24  
    25  	var tests = []struct {
    26  		markdown, expectedMarkdown string
    27  	}{
    28  		{ // first line is removed
    29  			// Nb. first line is the title of the document, and by removing it you get
    30  			//     more flexibility for include, e.g. include in tabs
    31  			markdown: "line 1\n" +
    32  				"line 2\n" +
    33  				"line 3",
    34  			expectedMarkdown: "line 2\n" +
    35  				"line 3",
    36  		},
    37  		{ // everything after ###SEE ALSO is removed
    38  			// Nb.  see also, that assumes file will be used as a main page (does not apply to includes)
    39  			markdown: "line 1\n" +
    40  				"line 2\n" +
    41  				"### SEE ALSO\n" +
    42  				"line 3",
    43  			expectedMarkdown: "line 2\n",
    44  		},
    45  	}
    46  	for _, rt := range tests {
    47  		actual := cleanupForInclude(rt.markdown)
    48  		if actual != rt.expectedMarkdown {
    49  			t.Errorf(
    50  				"failed cleanupForInclude:\n\texpected: %s\n\t  actual: %s",
    51  				rt.expectedMarkdown,
    52  				actual,
    53  			)
    54  		}
    55  	}
    56  
    57  }
    58  

View as plain text