Debian Codegraph @

api/krusty/stringquoteblank_test.go

raw
1 // Copyright 2022 The Kubernetes Authors.
2 // SPDX-License-Identifier: Apache-2.0
3
4 package krusty_test
5
6 import (
7 "testing"
8
9 kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
10 )
11
12 // This test is for output string style.
13 // Currently all quotes will be removed if the string is valid as plain (unquoted) style.
14 // If a string cannot be unquoted, it will be put into a pair of single quotes.
15 // See https://yaml.org/spec/1.2/spec.html#id2788859 for more details about what kind of string
16 // is invalid as plain style.
17 func TestLongLineBreaks(t *testing.T) {
18 th := kusttest_test.MakeHarness(t)
19 th.WriteF("deployment.yaml", `
20 apiVersion: extensions/v1beta1
21 kind: Deployment
22 metadata:
23 name: test
24 spec:
25 template:
26 spec:
27 containers:
28 - name: mariadb
29 image: test
30 env:
31 - name: SHORT_STRING
32 value: short_string
33 - name: SHORT_STRING_WITH_SINGLE_QUOTE
34 value: 'short_string'
35 - name: SHORT_STRING_WITH_DOUBLE_QUOTE
36 value: "short_string"
37 - name: SHORT_STRING_BLANK
38 value: short string
39 - name: LONG_STRING_BLANK
40 value: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas suscipit ex non molestie varius.
41 - name: LONG_STRING_BLANK_WITH_SINGLE_QUOTE
42 value: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas suscipit ex non molestie varius.'
43 - name: LONG_STRING_BLANK_WITH_DOUBLE_QUOTE
44 value: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas suscipit ex non molestie varius."
45 - name: INVALID_PLAIN_STYLE_STRING
46 value: ': test'
47 `)
48 th.WriteK(".", `
49 resources:
50 - deployment.yaml
51 `)
52 m := th.Run(".", th.MakeDefaultOptions())
53 th.AssertActualEqualsExpected(m, `
54 apiVersion: extensions/v1beta1
55 kind: Deployment
56 metadata:
57 name: test
58 spec:
59 template:
60 spec:
61 containers:
62 - env:
63 - name: SHORT_STRING
64 value: short_string
65 - name: SHORT_STRING_WITH_SINGLE_QUOTE
66 value: short_string
67 - name: SHORT_STRING_WITH_DOUBLE_QUOTE
68 value: short_string
69 - name: SHORT_STRING_BLANK
70 value: short string
71 - name: LONG_STRING_BLANK
72 value: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas
73 suscipit ex non molestie varius.
74 - name: LONG_STRING_BLANK_WITH_SINGLE_QUOTE
75 value: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas
76 suscipit ex non molestie varius.
77 - name: LONG_STRING_BLANK_WITH_DOUBLE_QUOTE
78 value: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas
79 suscipit ex non molestie varius.
80 - name: INVALID_PLAIN_STYLE_STRING
81 value: ': test'
82 image: test
83 name: mariadb
84 `)
85 }