...

Source file src/k8s.io/kubernetes/cmd/yamlfmt/yamlfmt_test.go

Documentation: k8s.io/kubernetes/cmd/yamlfmt

     1  /*
     2  Copyright 2021 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  	"bufio"
    21  	"bytes"
    22  	"github.com/stretchr/testify/assert"
    23  	"testing"
    24  )
    25  
    26  func TestFetchYaml(t *testing.T) {
    27  	sourceYaml := ` # See the OWNERS docs at https://go.k8s.io/owners
    28  approvers:
    29  - dep-approvers
    30  - thockin         # Network
    31  - liggitt
    32  
    33  labels:
    34  - sig/architecture
    35  `
    36  
    37  	outputYaml := `# See the OWNERS docs at https://go.k8s.io/owners
    38  approvers:
    39    - dep-approvers
    40    - thockin # Network
    41    - liggitt
    42  labels:
    43    - sig/architecture
    44  `
    45  	node, _ := fetchYaml([]byte(sourceYaml))
    46  	var output bytes.Buffer
    47  	indent := 2
    48  	writer := bufio.NewWriter(&output)
    49  	_ = streamYaml(writer, &indent, node)
    50  	_ = writer.Flush()
    51  	assert.Equal(t, outputYaml, string(output.Bytes()), "yaml was not formatted correctly")
    52  }
    53  

View as plain text