From 2029c662782922c6c2a2f54c945191371da064c9 Mon Sep 17 00:00:00 2001 From: John Ryan Date: Sat, 12 Mar 2022 15:38:36 -0800 Subject: [PATCH] Render YAML with yaml.v3 - yaml.v3 author refuses to support special indentation for sequences; adjust tests containing arrays to indent. (see also: https://github.com/go-yaml/yaml/issues/661) --- examples/concourse-overlay/expected.txt | 16 ++-- .../data-values-multiple-envs/expected.txt | 8 +- examples/data-values-required/expected.txt | 2 +- examples/eirini/config-result.yml | 38 ++++---- examples/k8s-config-map-files/expected.txt | 6 +- .../k8s-overlay-all-containers/expected.txt | 92 +++++++++--------- .../k8s-overlay-remove-resources/expected.txt | 62 ++++++------- .../k8s-relative-rolling-update/expected.txt | 8 +- examples/k8s-update-env-var/expected.txt | 16 ++-- examples/schema-arrays/expected.txt | 42 ++++----- go.mod | 2 +- pkg/cmd/template/cmd_data_values_file_test.go | 2 +- pkg/cmd/template/cmd_library_module_test.go | 6 +- pkg/cmd/template/cmd_overlays_test.go | 16 ++-- pkg/cmd/template/cmd_test.go | 93 +++++++++---------- pkg/cmd/template/regular_input.go | 1 + pkg/cmd/template/schema_author_test.go | 20 ++-- pkg/cmd/template/schema_consumer_test.go | 84 ++++++++--------- pkg/cmd/template/schema_inspect_test.go | 68 +++++++------- pkg/yamlmeta/convert.go | 72 ++++++++++++++ pkg/yamlmeta/document.go | 21 ++++- .../filetests/annotation-for.tpltest | 18 ++-- pkg/yamltemplate/filetests/datatypes.tpltest | 6 +- .../filetests/def-across-docs.tpltest | 4 +- .../filetests/def-recursive.tpltest | 12 +-- pkg/yamltemplate/filetests/def-return.tpltest | 10 +- pkg/yamltemplate/filetests/def.tpltest | 8 +- pkg/yamltemplate/filetests/for-break.tpltest | 6 +- .../filetests/for-continue.tpltest | 4 +- pkg/yamltemplate/filetests/for.tpltest | 12 +-- .../filetests/fragment/array.tpltest | 24 ++--- .../filetests/fragment/docset.tpltest | 18 ++-- .../filetests/fragment/map.tpltest | 32 +++---- pkg/yamltemplate/filetests/if.tpltest | 6 +- .../node-sugar/node-for-nested.tpltest | 50 +++++----- .../filetests/node-sugar/node-for.tpltest | 6 +- .../yaml-map-item-in-array-item.tpltest | 20 ++-- .../ytt-library/assert/assert-try-to.tpltest | 8 +- .../ytt-library/data-values-struct.tpltest | 42 ++++----- .../filetests/ytt-library/data-values.tpltest | 12 +-- .../filetests/ytt-library/json.tpltest | 8 +- .../overlay/append-to-array.tpltest | 10 +- .../ytt-library/overlay/array-by-key.tpltest | 16 ++-- .../ytt-library/overlay/assert-nested.tpltest | 8 +- .../ytt-library/overlay/assert.tpltest | 8 +- .../ytt-library/overlay/doc-subset.tpltest | 16 ++-- .../overlay/insert-into-array.tpltest | 30 +++--- .../ytt-library/overlay/logical-ops.tpltest | 56 +++++------ .../overlay/match-child-defaults.tpltest | 16 ++-- .../overlay/merge-over-nil.tpltest | 2 +- .../ytt-library/overlay/overlay.tpltest | 20 ++-- .../ytt-library/overlay/replace-func.tpltest | 4 +- .../overlay/replace-or-add.tpltest | 10 +- .../overlay/required-nested.tpltest | 4 +- .../ytt-library/overlay/when.tpltest | 6 +- .../overlay/yaml-array-over-yaml-map.tpltest | 4 +- .../ytt-library/overlay/yaml-over-map.tpltest | 6 +- .../filetests/ytt-library/struct-sort.tpltest | 6 +- .../filetests/ytt-library/struct.tpltest | 32 +++---- .../filetests/ytt-library/toml.tpltest | 8 +- .../filetests/ytt-library/url/url.tpltest | 10 +- .../filetests/ytt-library/yaml.tpltest | 34 +++---- .../filetests/ytt-replace/array-item.tpltest | 42 ++++----- test/e2e/e2e_test.go | 32 +++---- 64 files changed, 725 insertions(+), 636 deletions(-) diff --git a/examples/concourse-overlay/expected.txt b/examples/concourse-overlay/expected.txt index 3753215c4..c8a879e71 100644 --- a/examples/concourse-overlay/expected.txt +++ b/examples/concourse-overlay/expected.txt @@ -1,10 +1,10 @@ resources: -- name: booklit - type: git - source: - uri: https://github.com/vito/booklit + - name: booklit + type: git + source: + uri: https://github.com/vito/booklit jobs: -- name: unit - plan: - - get: booklit - trigger: true + - name: unit + plan: + - get: booklit + trigger: true diff --git a/examples/data-values-multiple-envs/expected.txt b/examples/data-values-multiple-envs/expected.txt index 07281c416..f8d1a8a53 100644 --- a/examples/data-values-multiple-envs/expected.txt +++ b/examples/data-values-multiple-envs/expected.txt @@ -1,19 +1,19 @@ app_config: version: "123" ports: - - 8080 + - 8080 *** app_config: version: v1alpha1 ports: - - 8080 + - 8080 *** app_config: version: v1beta1 ports: - - 8081 + - 8081 *** app_config: version: v1 ports: - - 80 + - 80 diff --git a/examples/data-values-required/expected.txt b/examples/data-values-required/expected.txt index b461dcb95..e2bc1db9b 100644 --- a/examples/data-values-required/expected.txt +++ b/examples/data-values-required/expected.txt @@ -1,4 +1,4 @@ app_config: version: "123" ports: - - 8080 + - 8080 diff --git a/examples/eirini/config-result.yml b/examples/eirini/config-result.yml index 44bb7246e..f1c1e8703 100644 --- a/examples/eirini/config-result.yml +++ b/examples/eirini/config-result.yml @@ -11,8 +11,8 @@ metadata: app.kubernetes.io/version: chart-appver helm.sh/chart: chart-name-chart-ver subjects: -- kind: ServiceAccount - name: secret-generator + - kind: ServiceAccount + name: secret-generator roleRef: kind: Role name: configgin-role @@ -31,8 +31,8 @@ metadata: app.kubernetes.io/version: chart-appver helm.sh/chart: chart-name-chart-ver subjects: -- kind: ServiceAccount - name: secret-generator + - kind: ServiceAccount + name: secret-generator roleRef: kind: Role name: secrets-role @@ -51,9 +51,9 @@ metadata: app.kubernetes.io/version: chart-appver helm.sh/chart: chart-name-chart-ver subjects: -- kind: ServiceAccount - name: secret-generator - namespace: release-ns + - kind: ServiceAccount + name: secret-generator + namespace: release-ns roleRef: kind: ClusterRole name: release-ns-psp-role-nonprivileged @@ -72,15 +72,15 @@ metadata: app.kubernetes.io/version: chart-appver helm.sh/chart: chart-name-chart-ver rules: -- apiGroups: - - "" - resources: - - configmaps - - secrets - verbs: - - create - - get - - list - - patch - - update - - delete + - apiGroups: + - "" + resources: + - configmaps + - secrets + verbs: + - create + - get + - list + - patch + - update + - delete diff --git a/examples/k8s-config-map-files/expected.txt b/examples/k8s-config-map-files/expected.txt index 45e5cce1d..415a1c883 100644 --- a/examples/k8s-config-map-files/expected.txt +++ b/examples/k8s-config-map-files/expected.txt @@ -11,9 +11,9 @@ data: config2.yml: | rules2a: 123 rules2b: - - a - - b - - c + - a + - b + - c config2.json: '{"rules2a":123,"rules2b":["a","b","c"]}' config3.yml: | config3a: config3a diff --git a/examples/k8s-overlay-all-containers/expected.txt b/examples/k8s-overlay-all-containers/expected.txt index efdde1d71..40ef4db94 100644 --- a/examples/k8s-overlay-all-containers/expected.txt +++ b/examples/k8s-overlay-all-containers/expected.txt @@ -6,34 +6,34 @@ spec: template: spec: volumes: - - name: shared-data - emptyDir: {} - containers: - - name: nginx-container - image: nginx - volumeMounts: - - name: shared-data - mountPath: /usr/share/nginx/html - resources: - limits: - cpu: 100m - requests: - cpu: 100m - - name: debian-container - image: debian - volumeMounts: - name: shared-data - mountPath: /pod-data - command: - - /bin/sh - args: - - -c - - echo Hello > /pod-data/index.html - resources: - limits: - cpu: 100m - requests: - cpu: 100m + emptyDir: {} + containers: + - name: nginx-container + image: nginx + volumeMounts: + - name: shared-data + mountPath: /usr/share/nginx/html + resources: + limits: + cpu: 100m + requests: + cpu: 100m + - name: debian-container + image: debian + volumeMounts: + - name: shared-data + mountPath: /pod-data + command: + - /bin/sh + args: + - -c + - echo Hello > /pod-data/index.html + resources: + limits: + cpu: 100m + requests: + cpu: 100m --- apiVersion: apps/v1 kind: Deployment @@ -43,22 +43,22 @@ spec: template: spec: containers: - - name: nginx-container - image: nginx - resources: - limits: - cpu: 100m - requests: - cpu: 100m - - name: debian-container - image: debian - command: - - /bin/sh - args: - - -c - - echo Hello - resources: - limits: - cpu: 100m - requests: - cpu: 100m + - name: nginx-container + image: nginx + resources: + limits: + cpu: 100m + requests: + cpu: 100m + - name: debian-container + image: debian + command: + - /bin/sh + args: + - -c + - echo Hello + resources: + limits: + cpu: 100m + requests: + cpu: 100m diff --git a/examples/k8s-overlay-remove-resources/expected.txt b/examples/k8s-overlay-remove-resources/expected.txt index 5cfbecd36..488a80e1e 100644 --- a/examples/k8s-overlay-remove-resources/expected.txt +++ b/examples/k8s-overlay-remove-resources/expected.txt @@ -16,10 +16,10 @@ spec: sidecar.istio.io/proxyMemory: 0M spec: containers: - - name: nginx - image: nginx:1.14.2 - ports: - - containerPort: 80 + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 --- apiVersion: apps/v1 kind: Deployment @@ -39,17 +39,17 @@ spec: sidecar.istio.io/proxyMemory: 0M spec: initContainers: - - name: setup - image: ubuntu - command: - - /bin/bash - - -c - - echo 1 + - name: setup + image: ubuntu + command: + - /bin/bash + - -c + - echo 1 containers: - - name: nginx - image: nginx:1.14.2 - ports: - - containerPort: 80 + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 --- apiVersion: apps/v1 kind: StatefulSet @@ -70,21 +70,21 @@ spec: spec: terminationGracePeriodSeconds: 10 containers: - - name: nginx - image: k8s.gcr.io/nginx-slim:0.8 - ports: - - containerPort: 80 - name: web - volumeMounts: - - name: www - mountPath: /usr/share/nginx/html + - name: nginx + image: k8s.gcr.io/nginx-slim:0.8 + ports: + - containerPort: 80 + name: web + volumeMounts: + - name: www + mountPath: /usr/share/nginx/html volumeClaimTemplates: - - metadata: - name: www - spec: - accessModes: - - ReadWriteOnce - storageClassName: my-storage-class - resources: - requests: - storage: 1Gi + - metadata: + name: www + spec: + accessModes: + - ReadWriteOnce + storageClassName: my-storage-class + resources: + requests: + storage: 1Gi diff --git a/examples/k8s-relative-rolling-update/expected.txt b/examples/k8s-relative-rolling-update/expected.txt index 0353e0912..797d2de0b 100644 --- a/examples/k8s-relative-rolling-update/expected.txt +++ b/examples/k8s-relative-rolling-update/expected.txt @@ -18,7 +18,7 @@ spec: app: nginx spec: containers: - - name: nginx - image: nginx:1.7.9 - ports: - - containerPort: 80 + - name: nginx + image: nginx:1.7.9 + ports: + - containerPort: 80 diff --git a/examples/k8s-update-env-var/expected.txt b/examples/k8s-update-env-var/expected.txt index 8a917a264..29882c20b 100644 --- a/examples/k8s-update-env-var/expected.txt +++ b/examples/k8s-update-env-var/expected.txt @@ -6,11 +6,11 @@ spec: template: spec: containers: - - name: app - env: - - name: STRIMZI_RESOURCE_LABELS - value: strimzi.io/cluster=my-cluster - - name: STRIMZI_KAFKA_BOOTSTRAP_SERVERS - value: NEW-my-cluster-kafka-bootstrap:9092 - - name: STRIMZI_ZOOKEEPER_CONNECT - value: my-cluster-zookeeper-client:2181 + - name: app + env: + - name: STRIMZI_RESOURCE_LABELS + value: strimzi.io/cluster=my-cluster + - name: STRIMZI_KAFKA_BOOTSTRAP_SERVERS + value: NEW-my-cluster-kafka-bootstrap:9092 + - name: STRIMZI_ZOOKEEPER_CONNECT + value: my-cluster-zookeeper-client:2181 diff --git a/examples/schema-arrays/expected.txt b/examples/schema-arrays/expected.txt index 979a2dbe6..76d89b8af 100644 --- a/examples/schema-arrays/expected.txt +++ b/examples/schema-arrays/expected.txt @@ -1,22 +1,22 @@ resources: -- name: cf-for-k8s-develop - source: - private_key: ((cf_for_k8s_readwrite_deploy_key.private_key)) - branch: develop - uri: git@github.com:cloudfoundry/cf-for-k8s - type: git - icon: github -- name: cf-for-k8s-ci - type: git - icon: github - source: - branch: develop - uri: git@github.com:cloudfoundry/cf-for-k8s - private_key: ((cf_for_k8s_readonly_deploy_key.private_key)) -- name: cf-acceptance-tests - source: - uri: git@github.com:cloudfoundry/cf-acceptance-tests - branch: develop - private_key: ((cf_for_k8s_readonly_deploy_key.private_key)) - type: git - icon: github + - name: cf-for-k8s-develop + source: + private_key: ((cf_for_k8s_readwrite_deploy_key.private_key)) + branch: develop + uri: git@github.com:cloudfoundry/cf-for-k8s + type: git + icon: github + - name: cf-for-k8s-ci + type: git + icon: github + source: + branch: develop + uri: git@github.com:cloudfoundry/cf-for-k8s + private_key: ((cf_for_k8s_readonly_deploy_key.private_key)) + - name: cf-acceptance-tests + source: + uri: git@github.com:cloudfoundry/cf-acceptance-tests + branch: develop + private_key: ((cf_for_k8s_readonly_deploy_key.private_key)) + type: git + icon: github diff --git a/go.mod b/go.mod index 7fc129615..f1f335804 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.7.1 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( @@ -23,5 +24,4 @@ require ( github.com/kr/text v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/pkg/cmd/template/cmd_data_values_file_test.go b/pkg/cmd/template/cmd_data_values_file_test.go index 9ab260b9c..c6456272b 100644 --- a/pkg/cmd/template/cmd_data_values_file_test.go +++ b/pkg/cmd/template/cmd_data_values_file_test.go @@ -81,7 +81,7 @@ array: map: a: 123 array: - - str + - str ` filesToProcess := files.NewSortedFiles([]*files.File{ diff --git a/pkg/cmd/template/cmd_library_module_test.go b/pkg/cmd/template/cmd_library_module_test.go index cf71e3c82..b5982e5b1 100644 --- a/pkg/cmd/template/cmd_library_module_test.go +++ b/pkg/cmd/template/cmd_library_module_test.go @@ -367,9 +367,9 @@ int: 100`) #@ def vals(arg1): return [arg1, data.values]`) expectedYAMLTplData := `vals: -- arg1 -- int: 124 - str: string + - arg1 + - int: 124 + str: string ` filesToProcess := files.NewSortedFiles([]*files.File{ diff --git a/pkg/cmd/template/cmd_overlays_test.go b/pkg/cmd/template/cmd_overlays_test.go index 16d74d20f..4038de4be 100644 --- a/pkg/cmd/template/cmd_overlays_test.go +++ b/pkg/cmd/template/cmd_overlays_test.go @@ -35,11 +35,11 @@ array: `) expectedYAMLTplData := `array: -- name: item1 - subarray: - - item1 - subarray2: - - yamlfunc: yamlfunc + - name: item1 + subarray: + - item1 + subarray2: + - yamlfunc: yamlfunc ` yamlFuncsData := []byte(` @@ -100,9 +100,9 @@ array: // subarray2 is not present because it was removed // by overlay1 that comes after overlay2 expectedYAMLTplData := `array: -- name: item1 - subarray: - - item1 + - name: item1 + subarray: + - item1 ` yamlFuncsData := []byte(` diff --git a/pkg/cmd/template/cmd_test.go b/pkg/cmd/template/cmd_test.go index 42539140c..13a2f0f3f 100644 --- a/pkg/cmd/template/cmd_test.go +++ b/pkg/cmd/template/cmd_test.go @@ -42,15 +42,14 @@ loaddata: #@ data.read("funcs/funcs.star")`) yamlfunc: yamlfunc textfunc: textfunc starfunc: -- 1 -- 2 + - 1 + - 2 listdata: -- tpl.yml -- funcs/funcs.lib.yml -- funcs/funcs.lib.txt -- funcs/funcs.star + - tpl.yml + - funcs/funcs.lib.yml + - funcs/funcs.lib.txt + - funcs/funcs.star loaddata: |2- - def starfunc(): return [1,2] end @@ -100,16 +99,16 @@ nestedlist: #@ nested_data_list() nesteddata: #@ nested_data_read()`) expectedYAMLTplData := `rootlist: -- tpl.yml -- funcs/funcs.lib.yml -- funcs/data + - tpl.yml + - funcs/funcs.lib.yml + - funcs/data rootdata: |- data data nestedlist: list: - - funcs.lib.yml - - data + - funcs.lib.yml + - data nesteddata: data: |- data @@ -169,19 +168,19 @@ nesteddata: #@ nested_data_read() `) expectedYAMLTplData := `rootlist: -- /tpl.yml -- /funcs/funcs.lib.yml -- /funcs/tpl.yml -- /funcs/data + - /tpl.yml + - /funcs/funcs.lib.yml + - /funcs/tpl.yml + - /funcs/data rootdata: |- data data nestedlist: list: - - /tpl.yml - - /funcs/funcs.lib.yml - - /funcs/tpl.yml - - /funcs/data + - /tpl.yml + - /funcs/funcs.lib.yml + - /funcs/tpl.yml + - /funcs/data nesteddata: data: |- data @@ -231,10 +230,10 @@ libdata: #@ lib_data_read()`) expectedYAMLTplData := `liblist: liblist1: - - funcs.lib.yml + - funcs.lib.yml liblist2: - - /other - - /funcs/funcs.lib.yml + - /other + - /funcs/funcs.lib.yml libdata: libdata2: |- lib1 @@ -347,11 +346,11 @@ localstarfunc: #@ localstarfunc()`) yamlfunc: textfunc textfunc: textfunc starfunc: -- 1 -- 2 + - 1 + - 2 localstarfunc: -- 3 -- 4 + - 3 + - 4 ` yamlFuncsData := []byte(` @@ -402,8 +401,8 @@ end`) func TestRelativeLoadInLibrariesForNonRootTemplates(t *testing.T) { expectedYAMLTplData := `libstarfunc: -- 1 -- 2 + - 1 + - 2 ` nonTopLevelYmlTplData := []byte(` @@ -543,29 +542,29 @@ func TestPlainYAMLNoTemplateProcessing(t *testing.T) { annotation: 5 #@ 1 + 2 text_template: (@= "string" @) versions: -- &version - name: v1alpha1 - served: true -- << : *version - name: v1beta1 -- << : *version - name: v1 - storage: true -- << : *version + - &version + name: v1alpha1 + served: true + - << : *version + name: v1beta1 + - << : *version + name: v1 + storage: true + - << : *version `) expectedYAMLTplData := `annotation: 5 text_template: (@= "string" @) versions: -- name: v1alpha1 - served: true -- name: v1beta1 - served: true -- name: v1 - served: true - storage: true -- name: v1alpha1 - served: true + - name: v1alpha1 + served: true + - name: v1beta1 + served: true + - name: v1 + served: true + storage: true + - name: v1alpha1 + served: true ` filesToProcess := []*files.File{ diff --git a/pkg/cmd/template/regular_input.go b/pkg/cmd/template/regular_input.go index 37df22572..28e5fccee 100644 --- a/pkg/cmd/template/regular_input.go +++ b/pkg/cmd/template/regular_input.go @@ -110,6 +110,7 @@ func (s *RegularFilesSource) Output(out Output) error { } } + // out.DocSet.Items[1].Comments = []*yamlmeta.Comment{{Data: "@ load(\"@ytt:overlay\", \"overlay\")"}, {Data: "@overlay/match by=overlay.all"}} combinedDocBytes, err := out.DocSet.AsBytesWithPrinter(printerFunc) if err != nil { return fmt.Errorf("Marshaling combined template result: %s", err) diff --git a/pkg/cmd/template/schema_author_test.go b/pkg/cmd/template/schema_author_test.go index 1b698b98b..b263c2010 100644 --- a/pkg/cmd/template/schema_author_test.go +++ b/pkg/cmd/template/schema_author_test.go @@ -1157,13 +1157,13 @@ foo: #@ data.values.foo bar: #@ data.values.bar ` expected := `foo: -- new -- array -- strings + - new + - array + - strings bar: -- 1 -- 2 -- 3 + - 1 + - 2 + - 3 ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1193,8 +1193,8 @@ databases: #@ data.values.databases users: #@ data.values.users ` expected := `databases: -- name: null_db - host: "" + - name: null_db + host: "" users: admin: admin user: [] @@ -1221,8 +1221,8 @@ databases: databases: #@ data.values.databases ` expected := `databases: -- name: default - host: localhost + - name: default + host: localhost ` filesToProcess := files.NewSortedFiles([]*files.File{ diff --git a/pkg/cmd/template/schema_consumer_test.go b/pkg/cmd/template/schema_consumer_test.go index 66eab9971..caeb73b15 100644 --- a/pkg/cmd/template/schema_consumer_test.go +++ b/pkg/cmd/template/schema_consumer_test.go @@ -57,14 +57,14 @@ rendered: #@ data.values expected := `rendered: db_conn: - - hostname: server.example.com - port: 5432 - username: sa - password: changeme - metadata: - run: ./build.sh - timeout: 7.5 - ttl: 1 + - hostname: server.example.com + port: 5432 + username: sa + password: changeme + metadata: + run: ./build.sh + timeout: 7.5 + ttl: 1 top_level: key ` @@ -91,8 +91,8 @@ rendered: #@ data.values rendered: #@ data.values ` expected := `rendered: -- first -- second + - first + - second ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -212,9 +212,9 @@ rendered: #@ data.values expected := `rendered: db_conn: - - hostname: server.example.com - metadata: - run: ./build.sh + - hostname: server.example.com + metadata: + run: ./build.sh top_level: key ` @@ -952,12 +952,12 @@ vpc: #@ data.values.vpc expected := `vpc: name: name value subnet_config: - - id: 2 - mask: 255.255.0.0 - private: true - - id: 3 - mask: 255.255.255.0 - private: true + - id: 2 + mask: 255.255.0.0 + private: true + - id: 3 + mask: 255.255.255.0 + private: true ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -985,7 +985,7 @@ clients: dataValuesYAML := `#@data/values --- clients: -- name: foo + - name: foo ` templateYAML := `#@ load("@ytt:data", "data") --- @@ -994,10 +994,10 @@ rendered: #@ data.values expected := `rendered: clients: - - name: foo - config: - args: [] - options: null + - name: foo + config: + args: [] + options: null ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1162,8 +1162,8 @@ overriden: #@ data.values.overriden contains_array: null overriden: contains_array: - - a: 20 - b: 0 + - a: 20 + b: 0 ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1194,10 +1194,10 @@ array: array: #@ data.values.array ` expected := `array: -- one -- null -- two -- null + - one + - null + - two + - null ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1349,9 +1349,9 @@ foo: ["bar", 7, ~] foo: #@ data.values.foo ` expected := `foo: -- bar -- 7 -- null + - bar + - 7 + - null ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1376,9 +1376,9 @@ foo: foo: #@ data.values.foo ` expected := `foo: -- bar: - - 1 - - baz + - bar: + - 1 + - baz ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1454,11 +1454,11 @@ baz: #@ data.values.baz expected := `foo: ball: red bar: -- newMap: - - "" - - 8 + - newMap: + - "" + - 8 baz: -- newArray: foobar + - newArray: foobar ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -1756,8 +1756,8 @@ bar: from_library_schema foo: from_library_dv `) expectedYAMLTplData := `key: -- from_library_schema -- from_library_dv + - from_library_schema + - from_library_dv ` filesToProcess := files.NewSortedFiles([]*files.File{ diff --git a/pkg/cmd/template/schema_inspect_test.go b/pkg/cmd/template/schema_inspect_test.go index 53839439e..2836a0c2c 100644 --- a/pkg/cmd/template/schema_inspect_test.go +++ b/pkg/cmd/template/schema_inspect_test.go @@ -152,9 +152,9 @@ components: type: integer default: 0 default: - - 1 - - 2 - - 3 + - 1 + - 2 + - 3 array_of_maps: type: array items: @@ -168,12 +168,12 @@ components: type: string default: default default: - - bar: thing 1 - ree: default - - bar: thing 2 - ree: default - - bar: thing 3 - ree: default + - bar: thing 1 + ree: default + - bar: thing 2 + ree: default + - bar: thing 3 + ree: default ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -308,10 +308,10 @@ components: foo: int_key: 0 array_of_scalars: - - "" + - "" array_of_maps: - - foo: "" - bar: "" + - foo: "" + bar: "" ` filesToProcess := files.NewSortedFiles([]*files.File{ files.MustNewFileFromSource(files.NewBytesSource("schema.yml", []byte(schemaYAML))), @@ -351,10 +351,10 @@ components: default: int_key: 0 array_of_scalars: - - "" + - "" array_of_maps: - - foo: "" - bar: "" + - foo: "" + bar: "" ` filesToProcess := files.NewSortedFiles([]*files.File{ files.MustNewFileFromSource(files.NewBytesSource("schema.yml", []byte(schemaYAML))), @@ -508,9 +508,9 @@ components: type: integer default: 0 default: - - 1 - - 2 - - 3 + - 1 + - 2 + - 3 array_of_maps: type: array nullable: true @@ -527,12 +527,12 @@ components: nullable: true default: null default: - - bar: thing 1 - ree: null - - bar: thing 2 - ree: null - - bar: thing 3 - ree: null + - bar: thing 1 + ree: null + - bar: thing 2 + ree: null + - bar: thing 3 + ree: null ` filesToProcess := files.NewSortedFiles([]*files.File{ @@ -798,21 +798,21 @@ components: x-example-description: schema example description example: db_conn: - - hostname: localhost - port: 8080 - timeout: 4.2 - any_key: anything - null_key: null - properties: - db_conn: - type: array - x-example-description: db_conn example description - example: - hostname: localhost port: 8080 timeout: 4.2 any_key: anything null_key: null + properties: + db_conn: + type: array + x-example-description: db_conn example description + example: + - hostname: localhost + port: 8080 + timeout: 4.2 + any_key: anything + null_key: null items: type: object additionalProperties: false diff --git a/pkg/yamlmeta/convert.go b/pkg/yamlmeta/convert.go index 73399b593..95d76cd96 100644 --- a/pkg/yamlmeta/convert.go +++ b/pkg/yamlmeta/convert.go @@ -5,10 +5,12 @@ package yamlmeta import ( "fmt" + "strings" "github.com/vmware-tanzu/carvel-ytt/pkg/filepos" "github.com/vmware-tanzu/carvel-ytt/pkg/orderedmap" "github.com/vmware-tanzu/carvel-ytt/pkg/yamlmeta/internal/yaml.v2" + yaml3 "gopkg.in/yaml.v3" ) func NewASTFromInterface(val interface{}) interface{} { @@ -27,6 +29,76 @@ func NewGoFromAST(val interface{}) interface{} { return convertToGo(val) } +func convertToYAML3Node(val interface{}) *yaml3.Node { + switch typedVal := val.(type) { + case *Document: + // head, inline := convertYAML3Comments(typedVal) + return &yaml3.Node{ + Kind: yaml3.DocumentNode, + Content: []*yaml3.Node{convertToYAML3Node(typedVal.Value)}, + // HeadComment: head.String(), + // LineComment: inline.String(), + } + case *Map: + yamlMap := &yaml3.Node{Kind: yaml3.MappingNode} + for _, item := range typedVal.Items { + key := convertToYAML3Node(item.Key) + value := convertToYAML3Node(item.Value) + yamlMap.Content = append(yamlMap.Content, key, value) + } + return yamlMap + case *orderedmap.Map: + yamlMap := &yaml3.Node{Kind: yaml3.MappingNode} + typedVal.Iterate(func(k, v interface{}) { + key := convertToYAML3Node(k) + value := convertToYAML3Node(v) + yamlMap.Content = append(yamlMap.Content, key, value) + }) + return yamlMap + case *Array: + yamlArray := &yaml3.Node{Kind: yaml3.SequenceNode} + for _, item := range typedVal.Items { + yamlArray.Content = append(yamlArray.Content, convertToYAML3Node(item.Value)) + } + return yamlArray + case []interface{}: + yamlArray := &yaml3.Node{Kind: yaml3.SequenceNode} + for _, item := range typedVal { + yamlArray.Content = append(yamlArray.Content, convertToYAML3Node(item)) + } + return yamlArray + case bool: + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: fmt.Sprintf("%t", val)} + case int, int32, int64, uint, uint32, uint64: + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: fmt.Sprintf("%d", val)} + case float32, float64: + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: fmt.Sprintf("%g", val)} + case nil: + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: "null"} + case string: + if val == "" { + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: "", Style: yaml3.DoubleQuotedStyle} + } else { + return &yaml3.Node{Kind: yaml3.ScalarNode, Value: fmt.Sprintf("%s", val), Tag: "!!str"} + } + default: + panic(fmt.Sprintf("Unexpected type %T = %#v", val, val)) + } +} + +func convertYAML3Comments(typedVal Node) (strings.Builder, strings.Builder) { + head := strings.Builder{} + inline := strings.Builder{} + for _, comment := range typedVal.GetComments() { + if comment.Position.IsNextTo(typedVal.GetPosition()) { + inline.WriteString(comment.Data) + } else { + head.WriteString(comment.Data) + } + } + return head, inline +} + func convertToLowYAML(val interface{}) interface{} { switch typedVal := val.(type) { case map[interface{}]interface{}: diff --git a/pkg/yamlmeta/document.go b/pkg/yamlmeta/document.go index 0e2064572..a4d7a80cf 100644 --- a/pkg/yamlmeta/document.go +++ b/pkg/yamlmeta/document.go @@ -4,7 +4,9 @@ package yamlmeta import ( - "github.com/vmware-tanzu/carvel-ytt/pkg/yamlmeta/internal/yaml.v2" + "bytes" + + yaml3 "gopkg.in/yaml.v3" ) func (d *Document) IsEmpty() bool { @@ -22,7 +24,22 @@ func (d *Document) IsEmpty() bool { } func (d *Document) AsYAMLBytes() ([]byte, error) { - return yaml.Marshal(convertToLowYAML(convertToGo(d.Value))) + out := bytes.Buffer{} + // TODO: re-enable including comments after all tests are verified working, as is. + // if len(d.Comments) > 0 { + // for _, comment := range d.Comments { + // out.WriteString(fmt.Sprintf("#%s\n", comment.Data)) + // } + // out.WriteString("---\n") + // } + + encoder := yaml3.NewEncoder(&out) + encoder.SetIndent(2) + err := encoder.Encode(convertToYAML3Node(d)) + if err != nil { + return nil, err + } + return out.Bytes(), nil } func (d *Document) AsInterface() interface{} { diff --git a/pkg/yamltemplate/filetests/annotation-for.tpltest b/pkg/yamltemplate/filetests/annotation-for.tpltest index a382a2a17..92ebde6e1 100644 --- a/pkg/yamltemplate/filetests/annotation-for.tpltest +++ b/pkg/yamltemplate/filetests/annotation-for.tpltest @@ -16,13 +16,13 @@ test2: +++ test1: -- 0 -- 1 -- 1 -- 2 -- 2 -- 3 + - 0 + - 1 + - 1 + - 2 + - 2 + - 3 test2: -- 0 -- 1 -- 2 + - 0 + - 1 + - 2 diff --git a/pkg/yamltemplate/filetests/datatypes.tpltest b/pkg/yamltemplate/filetests/datatypes.tpltest index 75b59caf5..a7ad84dfa 100644 --- a/pkg/yamltemplate/filetests/datatypes.tpltest +++ b/pkg/yamltemplate/filetests/datatypes.tpltest @@ -32,6 +32,6 @@ metadata: map: a: 123 list: - - a - - 123 - - a: 123 + - a + - 123 + - a: 123 diff --git a/pkg/yamltemplate/filetests/def-across-docs.tpltest b/pkg/yamltemplate/filetests/def-across-docs.tpltest index ac966a810..23e609c39 100644 --- a/pkg/yamltemplate/filetests/def-across-docs.tpltest +++ b/pkg/yamltemplate/filetests/def-across-docs.tpltest @@ -12,5 +12,5 @@ test1: #@ tpl() array: [] --- test1: -- item1 -- item2 + - item1 + - item2 diff --git a/pkg/yamltemplate/filetests/def-recursive.tpltest b/pkg/yamltemplate/filetests/def-recursive.tpltest index 53ba9427f..14a73f6d7 100644 --- a/pkg/yamltemplate/filetests/def-recursive.tpltest +++ b/pkg/yamltemplate/filetests/def-recursive.tpltest @@ -18,9 +18,9 @@ test: +++ test: -- label1: 123 - label2: 124 - label3: 12 - label4: 13 -- label3: 12 - label4: 13 + - label1: 123 + label2: 124 + label3: 12 + label4: 13 + - label3: 12 + label4: 13 diff --git a/pkg/yamltemplate/filetests/def-return.tpltest b/pkg/yamltemplate/filetests/def-return.tpltest index 74a037674..30be7ccd4 100644 --- a/pkg/yamltemplate/filetests/def-return.tpltest +++ b/pkg/yamltemplate/filetests/def-return.tpltest @@ -34,8 +34,8 @@ test: +++ test: -- label1: 123 -- label3: 12 - label4: 13 -- a: 123 -- label1: 123 + - label1: 123 + - label3: 12 + label4: 13 + - a: 123 + - label1: 123 diff --git a/pkg/yamltemplate/filetests/def.tpltest b/pkg/yamltemplate/filetests/def.tpltest index cb6945ac8..d3152ec16 100644 --- a/pkg/yamltemplate/filetests/def.tpltest +++ b/pkg/yamltemplate/filetests/def.tpltest @@ -33,8 +33,8 @@ parent1: label3: 12 label4: 13 parent2: -- label1: 123 - label2: 124 -- label3: 12 - label4: 13 + - label1: 123 + label2: 124 + - label3: 12 + label4: 13 parent3: 123 diff --git a/pkg/yamltemplate/filetests/for-break.tpltest b/pkg/yamltemplate/filetests/for-break.tpltest index a75f4abe6..469ea14d0 100644 --- a/pkg/yamltemplate/filetests/for-break.tpltest +++ b/pkg/yamltemplate/filetests/for-break.tpltest @@ -27,7 +27,7 @@ kind: Deployment metadata: labels: array: - - i: 0 + - i: 0 another: - - i: 1 - - i: 2 + - i: 1 + - i: 2 diff --git a/pkg/yamltemplate/filetests/for-continue.tpltest b/pkg/yamltemplate/filetests/for-continue.tpltest index 32b90ae7d..1f06ea70e 100644 --- a/pkg/yamltemplate/filetests/for-continue.tpltest +++ b/pkg/yamltemplate/filetests/for-continue.tpltest @@ -17,5 +17,5 @@ kind: Deployment metadata: labels: array: - - i: 0 - - i: 2 + - i: 0 + - i: 2 diff --git a/pkg/yamltemplate/filetests/for.tpltest b/pkg/yamltemplate/filetests/for.tpltest index 8fcf178ea..42534cc73 100644 --- a/pkg/yamltemplate/filetests/for.tpltest +++ b/pkg/yamltemplate/filetests/for.tpltest @@ -15,9 +15,9 @@ kind: Deployment metadata: labels: array: - - 0 - - 1 - - 1 - - 2 - - 2 - - 3 + - 0 + - 1 + - 1 + - 2 + - 2 + - 3 diff --git a/pkg/yamltemplate/filetests/fragment/array.tpltest b/pkg/yamltemplate/filetests/fragment/array.tpltest index b04de76f5..af0f23657 100644 --- a/pkg/yamltemplate/filetests/fragment/array.tpltest +++ b/pkg/yamltemplate/filetests/fragment/array.tpltest @@ -28,21 +28,21 @@ test6a: #@ 3 in array() +++ test1: -- str -- string -- true + - str + - string + - true test2: -- 123 -- int -- true + - 123 + - int + - true test3: -- key: 123 -- yamlfragment -- false + - key: 123 + - yamlfragment + - false test4: -- str -- 123 -- key: 123 + - str + - 123 + - key: 123 test5: 3 test6: true test6a: false diff --git a/pkg/yamltemplate/filetests/fragment/docset.tpltest b/pkg/yamltemplate/filetests/fragment/docset.tpltest index 6927c7ab3..9eee85072 100644 --- a/pkg/yamltemplate/filetests/fragment/docset.tpltest +++ b/pkg/yamltemplate/filetests/fragment/docset.tpltest @@ -33,17 +33,17 @@ test6a: #@ 3 in docs() +++ test1: -- str -- string -- true + - str + - string + - true test2: -- 123 -- int -- true + - 123 + - int + - true test3: -- key: 123 -- yamlfragment -- false + - key: 123 + - yamlfragment + - false --- test4 --- diff --git a/pkg/yamltemplate/filetests/fragment/map.tpltest b/pkg/yamltemplate/filetests/fragment/map.tpltest index 1b585502e..87f9a97ca 100644 --- a/pkg/yamltemplate/filetests/fragment/map.tpltest +++ b/pkg/yamltemplate/filetests/fragment/map.tpltest @@ -36,26 +36,26 @@ test7a: #@ "test3" in map() +++ test1: -- str -- string -- true + - str + - string + - true test2: -- sub_key: 123 -- yamlfragment -- false + - sub_key: 123 + - yamlfragment + - false test3: -- 123 -- int -- true + - 123 + - int + - true test4: -- key: test1 - value: str -- key: test2 - value: - sub_key: 123 + - key: test1 + value: str + - key: test2 + value: + sub_key: 123 test5: -- str -- sub_key: 123 + - str + - sub_key: 123 test5a: test1: str test2: diff --git a/pkg/yamltemplate/filetests/if.tpltest b/pkg/yamltemplate/filetests/if.tpltest index 3600dd805..19aa56370 100644 --- a/pkg/yamltemplate/filetests/if.tpltest +++ b/pkg/yamltemplate/filetests/if.tpltest @@ -39,7 +39,7 @@ metadata: t: 456 t2: 456 test2: -- item1 -- item2 + - item1 + - item2 test3: -- item2 + - item2 diff --git a/pkg/yamltemplate/filetests/node-sugar/node-for-nested.tpltest b/pkg/yamltemplate/filetests/node-sugar/node-for-nested.tpltest index 8ce186c25..531a92384 100644 --- a/pkg/yamltemplate/filetests/node-sugar/node-for-nested.tpltest +++ b/pkg/yamltemplate/filetests/node-sugar/node-for-nested.tpltest @@ -28,30 +28,30 @@ kind: Deployment metadata: labels: array1: - - nested: - - 0 - - 1 - - 2 - - nested: - - 0 - - 1 - - 2 - - nested: - - 0 - - 1 - - 2 + - nested: + - 0 + - 1 + - 2 + - nested: + - 0 + - 1 + - 2 + - nested: + - 0 + - 1 + - 2 array2: - - 0,0 - - 0,1 - - 0,2 - - 1,0 - - 1,1 - - 1,2 - - 2,0 - - 2,1 - - 2,2 + - 0,0 + - 0,1 + - 0,2 + - 1,0 + - 1,1 + - 1,2 + - 2,0 + - 2,1 + - 2,2 array3: - - 0,0 - - 0,1 - - 1,0 - - 1,1 + - 0,0 + - 0,1 + - 1,0 + - 1,1 diff --git a/pkg/yamltemplate/filetests/node-sugar/node-for.tpltest b/pkg/yamltemplate/filetests/node-sugar/node-for.tpltest index 559c75b04..2152c60ae 100644 --- a/pkg/yamltemplate/filetests/node-sugar/node-for.tpltest +++ b/pkg/yamltemplate/filetests/node-sugar/node-for.tpltest @@ -13,6 +13,6 @@ kind: Deployment metadata: labels: array: - - 0 - - 1 - - 2 + - 0 + - 1 + - 2 diff --git a/pkg/yamltemplate/filetests/yaml-map-item-in-array-item.tpltest b/pkg/yamltemplate/filetests/yaml-map-item-in-array-item.tpltest index 551657c87..349abff35 100644 --- a/pkg/yamltemplate/filetests/yaml-map-item-in-array-item.tpltest +++ b/pkg/yamltemplate/filetests/yaml-map-item-in-array-item.tpltest @@ -52,18 +52,18 @@ test5: +++ test1: -- value + - value test1a: -- value + - value test2: -- value + - value test3: -- key: value + - key: value test4: -- key: valuea -- key: valueb -- key: valueb -- {} + - key: valuea + - key: valueb + - key: valueb + - {} test5: -- key: a -- {} + - key: a + - {} diff --git a/pkg/yamltemplate/filetests/ytt-library/assert/assert-try-to.tpltest b/pkg/yamltemplate/filetests/ytt-library/assert/assert-try-to.tpltest index 464f7bff3..1fef59295 100644 --- a/pkg/yamltemplate/filetests/ytt-library/assert/assert-try-to.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/assert/assert-try-to.tpltest @@ -44,12 +44,12 @@ test_try_to_succeed_tuple: #@ try_to_succeed_tuple() +++ test_try_to_fail_data_error: -- null -- 'json.decode: invalid character ''}'' looking for beginning of value' + - null + - 'json.decode: invalid character ''}'' looking for beginning of value' test_try_to_fail_bad_ref: NoneType has no .foo field or method test_try_to_succeed_lambda: ytt: rules test_try_to_succeed_function: foo test_try_to_succeed_tuple: -- 1 -- 2 + - 1 + - 2 diff --git a/pkg/yamltemplate/filetests/ytt-library/data-values-struct.tpltest b/pkg/yamltemplate/filetests/ytt-library/data-values-struct.tpltest index 324eb447c..0f39df0d5 100644 --- a/pkg/yamltemplate/filetests/ytt-library/data-values-struct.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/data-values-struct.tpltest @@ -43,38 +43,38 @@ test1: map: a: 123 list: - - a - - 123 - - a: 123 + - a + - 123 + - a: 123 test2: a: 123 test3: -- a -- 123 -- a: 123 + - a + - 123 + - a: 123 test4: -- value: a -- value: 123 -- value: - a: 123 + - value: a + - value: 123 + - value: + a: 123 test5: -- key: a - value: 123 + - key: a + value: 123 is_mapping: test1: 123 test2: 123 test3: 123 is_iterable: test1: - - int = 123 - - intNeg = -49 - - float = 123.123 - - t = True - - f = False - - nullz = None - - string = string - - map = struct(...) - - list = ["a", 123, struct(...)] + - int = 123 + - intNeg = -49 + - float = 123.123 + - t = True + - f = False + - nullz = None + - string = string + - map = struct(...) + - list = ["a", 123, struct(...)] is_sequence: test1: 9 test2: 1 diff --git a/pkg/yamltemplate/filetests/ytt-library/data-values.tpltest b/pkg/yamltemplate/filetests/ytt-library/data-values.tpltest index b460b9a36..937d4860d 100644 --- a/pkg/yamltemplate/filetests/ytt-library/data-values.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/data-values.tpltest @@ -35,10 +35,10 @@ metadata: map: a: 123 list: - - a - - 123 - - a: 123 + - a + - 123 + - a: 123 list_for: - - a - - 123 - - a: 123 + - a + - 123 + - a: 123 diff --git a/pkg/yamltemplate/filetests/ytt-library/json.tpltest b/pkg/yamltemplate/filetests/ytt-library/json.tpltest index 3e09c2fb2..2a2a254d4 100644 --- a/pkg/yamltemplate/filetests/ytt-library/json.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/json.tpltest @@ -44,8 +44,8 @@ decode: test1: {} test2: a: - - 1 - - 2 - - 3 - - c: 456 + - 1 + - 2 + - 3 + - c: 456 b: str diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/append-to-array.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/append-to-array.tpltest index 4797e4b58..5b20e9b48 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/append-to-array.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/append-to-array.tpltest @@ -35,12 +35,12 @@ test2: #@ overlay.apply(test2_left(), test2_right()) +++ test1: -- item1 -- item2 -- item3 + - item1 + - item2 + - item3 --- test2: list1: - - item1 + - item1 list2: - - item1 + - item1 diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/array-by-key.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/array-by-key.tpltest index 29fbc1858..56f8cf1e3 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/array-by-key.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/array-by-key.tpltest @@ -43,15 +43,15 @@ test2 test1 --- clients: -- secret: ree -- secret: bar - needsSecret: false -- secret: ree + - secret: ree + - secret: bar + needsSecret: false + - secret: ree --- test2 --- clients: -- secret: ree -- secret: bar - needsSecret: false -- secret: ree + - secret: ree + - secret: bar + needsSecret: false + - secret: ree diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/assert-nested.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/assert-nested.tpltest index 027e05d12..d90d9af7c 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/assert-nested.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/assert-nested.tpltest @@ -46,13 +46,13 @@ test1: key2a: key2aa: val2 keys: - - 1 - - 2 + - 1 + - 2 test2: key1: key1a: val1 key2a: key2aa: val2 keys: - - 1 - - 2 + - 1 + - 2 diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/assert.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/assert.tpltest index dd70bf38b..a68d0f652 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/assert.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/assert.tpltest @@ -91,12 +91,12 @@ test1b: key2: true key3: string key4: - - abc - - null + - abc + - null --- test2: -- val1 -- val11 + - val1 + - val11 --- val1 --- diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/doc-subset.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/doc-subset.tpltest index c8b02232b..8ddac0b13 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/doc-subset.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/doc-subset.tpltest @@ -111,13 +111,13 @@ test1 metadata: name: test1 key1: -- name: foo + - name: foo --- metadata: name: test1 other: key key1: -- name: foo + - name: foo --- metadata: other: key @@ -125,18 +125,18 @@ metadata: test2 --- metadata: -- name: test2 + - name: test2 key1: -- name: foo + - name: foo --- metadata: -- name: test2 -- other: key + - name: test2 + - other: key key1: -- name: foo + - name: foo --- metadata: -- other: key + - other: key --- test3 --- diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array.tpltest index 99e33a1bb..b3b36d7d0 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array.tpltest @@ -43,18 +43,18 @@ test1: #@ overlay.apply(test1_left(), test1_right()) +++ test1: -- for_item: 1 - before: true -- item: 1 -- for_item: 1 - after: true -- for_item: 2 - before: true -- item: 2 -- for_item: 2 - after: true -- for_item: 3 - before: true -- item: 3 -- for_item: 3 - after: true + - for_item: 1 + before: true + - item: 1 + - for_item: 1 + after: true + - for_item: 2 + before: true + - item: 2 + - for_item: 2 + after: true + - for_item: 3 + before: true + - item: 3 + - for_item: 3 + after: true diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/logical-ops.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/logical-ops.tpltest index 3f4f3e611..6f6a3454a 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/logical-ops.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/logical-ops.tpltest @@ -59,36 +59,36 @@ test3a: #@ overlay.apply(test_left(), test3a_right()) +++ test1: -- name: first -- name: second -- name: third -- found: true + - name: first + - name: second + - name: third + - found: true test1a: -- name: first - found: true -- name: second -- name: third + - name: first + found: true + - name: second + - name: third test1b: -- name: first - found: true -- name: second - found: true -- name: third - found: true + - name: first + found: true + - name: second + found: true + - name: third + found: true test2: -- name: first - found: true -- name: second -- name: third - found: true + - name: first + found: true + - name: second + - name: third + found: true test3: -- name: first -- name: second - found: true -- name: third - found: true + - name: first + - name: second + found: true + - name: third + found: true test3a: -- name: first -- name: second -- name: third -- found: true + - name: first + - name: second + - name: third + - found: true diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/match-child-defaults.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/match-child-defaults.tpltest index f59ec7945..aa2e5adc8 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/match-child-defaults.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/match-child-defaults.tpltest @@ -92,15 +92,15 @@ test1: --- test2: key2: - - name: val1 - - name: val2 - - name: val3 - - name: val4 - - name: val5 + - name: val1 + - name: val2 + - name: val3 + - name: val4 + - name: val5 --- key2: -- name: val1 -- name: val3 + - name: val1 + - name: val3 --- key3: -- name: val3 + - name: val3 diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/merge-over-nil.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/merge-over-nil.tpltest index 61b17610a..82e2c076e 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/merge-over-nil.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/merge-over-nil.tpltest @@ -50,6 +50,6 @@ test1: bar: 42 --- test2: -- - bar 42 + - - bar 42 --- test3: foo bar diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/overlay.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/overlay.tpltest index fa4fbdebd..8031ca926 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/overlay.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/overlay.tpltest @@ -95,20 +95,20 @@ test2: key2: val2 test3: key1: - - item1 - - item3 + - item1 + - item3 test3a: key1: - - item3 - - item3 + - item3 + - item3 test4: key1: - - item4 - - item4 + - item4 + - item4 key2: [] test5: key1: - - name: blah - - name: foo - other: key - - name: foo2 + - name: blah + - name: foo + other: key + - name: foo2 diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/replace-func.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/replace-func.tpltest index 5a9dcd3c0..eb760aa5a 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/replace-func.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/replace-func.tpltest @@ -82,8 +82,8 @@ test1b: key1: val1val2 --- test2: -- prefix-val1-val2 -- prefix-val11-val2 + - prefix-val1-val2 + - prefix-val11-val2 --- test3-prefix-val1-val2 --- diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/replace-or-add.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/replace-or-add.tpltest index 49429f16e..b32a618b2 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/replace-or-add.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/replace-or-add.tpltest @@ -65,13 +65,13 @@ test1: test1a: key1: val1 key2: - - null - - val2 + - null + - val2 --- test2: -- val1 -- val11 -- val2 + - val1 + - val11 + - val2 --- val1 --- diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/required-nested.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/required-nested.tpltest index db2d2f73f..c303533e0 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/required-nested.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/required-nested.tpltest @@ -41,8 +41,8 @@ test1: key1: val1 key2: val2 key2: - - name: foo - other: key + - name: foo + other: key test2: key1: key1: val1 diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/when.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/when.tpltest index fcd8d1bc6..53d4d97de 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/when.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/when.tpltest @@ -105,11 +105,11 @@ test1: input_func: func input_list: list array: - - input_string + - input_string array2: - - input_int + - input_int array3: - - input_func + - input_func --- input_string: string input_int: int diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-array-over-yaml-map.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-array-over-yaml-map.tpltest index 2ce35f61e..40c65967c 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-array-over-yaml-map.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-array-over-yaml-map.tpltest @@ -19,5 +19,5 @@ test1: #@ overlay.apply(test1_left(), test1_right()) test1: key1: - - name: foo - other: key + - name: foo + other: key diff --git a/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-over-map.tpltest b/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-over-map.tpltest index f59f7d1c8..cc1cfee77 100644 --- a/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-over-map.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/overlay/yaml-over-map.tpltest @@ -18,6 +18,6 @@ test1: #@ overlay.apply(test1_left(), test1_right()) test1: key1: - - name: foo - another: key - other: key + - name: foo + another: key + other: key diff --git a/pkg/yamltemplate/filetests/ytt-library/struct-sort.tpltest b/pkg/yamltemplate/filetests/ytt-library/struct-sort.tpltest index f12d81858..3d117e754 100644 --- a/pkg/yamltemplate/filetests/ytt-library/struct-sort.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/struct-sort.tpltest @@ -7,9 +7,9 @@ test1: #@ struct.decode(struct.make(a=[1,2,3], b="str", c=struct.make(d=123))) test1: a: - - 1 - - 2 - - 3 + - 1 + - 2 + - 3 b: str c: d: 123 diff --git a/pkg/yamltemplate/filetests/ytt-library/struct.tpltest b/pkg/yamltemplate/filetests/ytt-library/struct.tpltest index 813e04091..65181e19b 100644 --- a/pkg/yamltemplate/filetests/ytt-library/struct.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/struct.tpltest @@ -106,10 +106,10 @@ make_and_bind: --- encode: test1: - - 1 - - 2 - - 3 - - c: 456 + - 1 + - 2 + - 3 + - c: 456 test2: str test3: 123 is_mapping: @@ -120,30 +120,30 @@ encode: test5: true is_iterable: test1: - - a = [1, 2, 3, struct(...)] - - b = str - - c = struct(...) + - a = [1, 2, 3, struct(...)] + - b = str + - c = struct(...) test2: - - a = [1, 2, 3, struct(...)] - - b = str - - c = struct(...) + - a = [1, 2, 3, struct(...)] + - b = str + - c = struct(...) is_sequence: test1: 3 --- decode: test1: a: - - 1 - - 2 - - 3 + - 1 + - 2 + - 3 b: str c: d: 123 test2: a: - - 1 - - 2 - - 3 + - 1 + - 2 + - 3 b: str c: d: 123 diff --git a/pkg/yamltemplate/filetests/ytt-library/toml.tpltest b/pkg/yamltemplate/filetests/ytt-library/toml.tpltest index 24b7a6f49..1a92cf79f 100644 --- a/pkg/yamltemplate/filetests/ytt-library/toml.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/toml.tpltest @@ -59,10 +59,10 @@ decode: test1: {} test2: a: - - 1 - - 2 - - 3 - - 456 + - 1 + - 2 + - 3 + - 456 b: str test3: stuff: diff --git a/pkg/yamltemplate/filetests/ytt-library/url/url.tpltest b/pkg/yamltemplate/filetests/ytt-library/url/url.tpltest index 7e252f605..e7f0e3c7e 100644 --- a/pkg/yamltemplate/filetests/ytt-library/url/url.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/url/url.tpltest @@ -36,11 +36,11 @@ query_params: test1: x=1&y=2&y=3&z= test2: x: - - "1" - "y": - - "2" - - "3" + - "1" + y: + - "2" + - "3" z: - - "" + - "" test3: "" test4: {} diff --git a/pkg/yamltemplate/filetests/ytt-library/yaml.tpltest b/pkg/yamltemplate/filetests/ytt-library/yaml.tpltest index dc45eb4c3..442b013c9 100644 --- a/pkg/yamltemplate/filetests/ytt-library/yaml.tpltest +++ b/pkg/yamltemplate/filetests/ytt-library/yaml.tpltest @@ -54,28 +54,28 @@ test5 test1: | a: - - 1 - - 2 - - 3 - - c: 456 + - 1 + - 2 + - 3 + - c: 456 b: str test1a: | fragment: - - piece1 - - piece2: true + - piece1 + - piece2: true test1b: | inside_map: fragment: - - piece1 - - piece2: true + - piece1 + - piece2: true inside_array: - - fragment: - - piece1 - - piece2: true + - fragment: + - piece1 + - piece2: true test1c: | fragment: - - piece1 - - piece2: true + - piece1 + - piece2: true --- doc2 test2: | @@ -83,10 +83,10 @@ test2: | test3: {} test4: a: - - 1 - - 2 - - 3 - - c: 456 + - 1 + - 2 + - 3 + - c: 456 b: str --- test5 diff --git a/pkg/yamltemplate/filetests/ytt-replace/array-item.tpltest b/pkg/yamltemplate/filetests/ytt-replace/array-item.tpltest index f6474c6d7..2c0a73ec9 100644 --- a/pkg/yamltemplate/filetests/ytt-replace/array-item.tpltest +++ b/pkg/yamltemplate/filetests/ytt-replace/array-item.tpltest @@ -33,27 +33,27 @@ empty: +++ start: -- a: 123 -- b: 124 -- item1 -- item2 -- c: 126 + - a: 123 + - b: 124 + - item1 + - item2 + - c: 126 middle: -- a: 127 -- b: 123 -- c: 124 -- test4: more-than-one-item -- item1 -- item2 -- d: 126 + - a: 127 + - b: 123 + - c: 124 + - test4: more-than-one-item + - item1 + - item2 + - d: 126 end: -- a: 126 -- b: 123 -- c: 124 -- item1 -- item2 + - a: 126 + - b: 123 + - c: 124 + - item1 + - item2 empty: -- b: 123 -- c: 124 -- item1 -- item2 + - b: 123 + - c: 124 + - item1 + - item2 diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 9938622e3..54b0eb180 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -290,13 +290,13 @@ float: 123.123 } actualOutput := runYtt(t, testInputFiles{"../../examples/data-values/config.yml", "../../examples/data-values/values.yml"}, "", flags, envs) expectedOutput := `nothing: -- 1 -- 2 -- 3 + - 1 + - 2 + - 3 string: -- 1 -- 2 -- 4 + - 1 + - 2 + - 4 bool: true int: 123 float: 123.123 @@ -341,9 +341,9 @@ bool: true int: 123 float: 123.123 any: -- 1 -- 2 -- 4 + - 1 + - 2 + - 4 ` require.Equal(t, expectedOutput, actualOutput) @@ -369,9 +369,9 @@ bool: true int: 123 float: 123.123 any: -- 1 -- 2 -- 4 + - 1 + - 2 + - 4 ` require.Equal(t, expectedOutput, actualOutput) @@ -420,7 +420,7 @@ func TestDataValuesUsages(t *testing.T) { expectedOutput := `app_config: version: "123" ports: - - 8080 + - 8080 ` require.Equal(t, expectedOutput, actualOutput) }) @@ -430,7 +430,7 @@ func TestDataValuesUsages(t *testing.T) { expectedOutput := `app_config: version: v1alpha1 ports: - - 8080 + - 8080 ` require.Equal(t, expectedOutput, actualOutput) }) @@ -440,7 +440,7 @@ func TestDataValuesUsages(t *testing.T) { expectedOutput := `app_config: version: v1beta1 ports: - - 8081 + - 8081 ` require.Equal(t, expectedOutput, actualOutput) }) @@ -450,7 +450,7 @@ func TestDataValuesUsages(t *testing.T) { expectedOutput := `app_config: version: v1 ports: - - 80 + - 80 ` require.Equal(t, expectedOutput, actualOutput) })