mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Suggested changes
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
. "sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
|
||||
)
|
||||
|
||||
func TestByteReader(t *testing.T) {
|
||||
@@ -807,15 +808,13 @@ items:
|
||||
}
|
||||
|
||||
// TestByteReader_AddSeqIndentAnnotation tests if the internal.config.kubernetes.io/seqindent
|
||||
// annotation is added to resources appropriately, the expectedOutput indentation may not
|
||||
// match with the annotation as it is not using byteio_writer, this test will only verify
|
||||
// byteio_reader behavior to add annotation
|
||||
// annotation is added to resources appropriately
|
||||
func TestByteReader_AddSeqIndentAnnotation(t *testing.T) {
|
||||
type testCase struct {
|
||||
name string
|
||||
err string
|
||||
input string
|
||||
expectedOutput string
|
||||
expectedAnnoValue string
|
||||
OmitReaderAnnotations bool
|
||||
}
|
||||
|
||||
@@ -829,17 +828,7 @@ spec:
|
||||
- bar
|
||||
- baz
|
||||
`,
|
||||
expectedOutput: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
internal.config.kubernetes.io/seqindent: 'wide'
|
||||
`,
|
||||
expectedAnnoValue: "wide",
|
||||
},
|
||||
{
|
||||
name: "read with compact indentation",
|
||||
@@ -850,17 +839,7 @@ spec:
|
||||
- bar
|
||||
- baz
|
||||
`,
|
||||
expectedOutput: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
internal.config.kubernetes.io/seqindent: 'compact'
|
||||
`,
|
||||
expectedAnnoValue: "compact",
|
||||
},
|
||||
{
|
||||
name: "read with mixed indentation, wide wins",
|
||||
@@ -874,20 +853,7 @@ env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
expectedOutput: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
internal.config.kubernetes.io/seqindent: 'wide'
|
||||
`,
|
||||
expectedAnnoValue: "wide",
|
||||
},
|
||||
{
|
||||
name: "read with mixed indentation, compact wins",
|
||||
@@ -901,20 +867,7 @@ env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
expectedOutput: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
metadata:
|
||||
annotations:
|
||||
config.kubernetes.io/index: '0'
|
||||
internal.config.kubernetes.io/seqindent: 'compact'
|
||||
`,
|
||||
expectedAnnoValue: "compact",
|
||||
},
|
||||
{
|
||||
name: "error if conflicting options",
|
||||
@@ -924,16 +877,6 @@ spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
expectedOutput: `apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
@@ -957,9 +900,8 @@ env:
|
||||
return
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
actual, err := rNodes[0].String()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedOutput, actual)
|
||||
actual := rNodes[0].GetAnnotations()[kioutil.SeqIndentAnnotation]
|
||||
assert.Equal(t, tc.expectedAnnoValue, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,14 +425,12 @@ spec:
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "round_trip with mixed indentations in same resource, wide wins",
|
||||
name: "round_trip with mixed indentations in same resource, wide wins as it is first",
|
||||
input: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
@@ -442,22 +440,18 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "round_trip with mixed indentations in same resource, compact wins",
|
||||
name: "round_trip with mixed indentations in same resource, compact wins as it is first",
|
||||
input: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
@@ -467,31 +461,6 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
- baz
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "round_trip with mixed indentations in same resource, compact in case of a tie",
|
||||
input: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
`,
|
||||
expectedOutput: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
spec:
|
||||
- foo
|
||||
- bar
|
||||
env:
|
||||
- foo
|
||||
- bar
|
||||
|
||||
@@ -108,7 +108,7 @@ func (w ByteWriter) Write(inputNodes []*yaml.RNode) error {
|
||||
// don't wrap the elements
|
||||
if w.WrappingKind == "" {
|
||||
for i := range nodes {
|
||||
if seqIndentsForNodes[i] == string(yaml.WideSeqIndent) {
|
||||
if seqIndentsForNodes[i] == string(yaml.WideSequenceStyle) {
|
||||
encoder.DefaultSeqIndent()
|
||||
} else {
|
||||
encoder.CompactSeqIndent()
|
||||
|
||||
Reference in New Issue
Block a user