kpt icon indicating copy to clipboard operation
kpt copied to clipboard

Test case for issue 4012 pkg update not updating kptfile

Open michaelvl opened this issue 2 years ago • 0 comments

This PR adds a test-case for kpt pkg get/update that reproduce the issue reported in #4012

Note: Since this is a failing test-case it could be considered to disable the final and failing assertion until the problem have been resolved

This PR adds a Kptfile to dataset1 and dataset2 for the sub package mysql. The change between dataset1 and dataset2 are:

$ diff internal/testutil/testdata/dataset1/mysql/Kptfile internal/testutil/testdata/dataset2/mysql/Kptfile
6c6
<   description: kpt package for mysql
---
>   description: mysql package
12a13,16
>     - image: gcr.io/kpt-fn/set-labels:v0.2.0
>       configMap:
>         fruit: apple
>       name: set fruit label

The test-case basically does a kpt pkg get mysql@dataset1 followed by a kpt pkg update mysql@dataset2 and verifies the content of Kptfile. The issue from #4012 thus results in a test-case failure with the following diff between the local Kptfile vs dataset2 (i.e. the local version have 'removals' compared to dataset2 because the local Kptfile is not properly updated to dataset2):

Diff:
--- Expected
+++ Actual
@@ -19,3 +19,3 @@
 info:
-  description: mysql package
+  description: kpt package for mysql
 pipeline:
@@ -28,6 +28,2 @@
       configMap:
-        fruit: apple
-      name: set fruit label
-    - image: gcr.io/kpt-fn/set-labels:v0.2.0
-      configMap:
         color: orange

Note, a copy of the Kptfile from dataset2 have also been added to dataset4 and dataset5 since these are 'clones' of dataset2.

This PR also correct an issue in testutil.AssertKptfile related to sequence-nodes (this new test-case seems to be the first use of sequence-nodes in Kptfiles). The issue is, that kptfileutil.WriteFile() use encoder option yaml.WideSequenceStyle, while the encoding used in testutil.AssertKptfile is a compact encoding. Without this correction, the test-case would fail with additional whitespace differences, e.g. (this is the initial pkg get verification of dataset1 that fails):

Diff:
--- Expected
+++ Actual
@@ -22,10 +22,10 @@
   mutators:
-  - image: gcr.io/kpt-fn/set-namespace:v0.4.1
-    configMap:
-      namespace: example-ns
-    name: set namespace
-  - image: gcr.io/kpt-fn/set-labels:v0.2.0
-    configMap:
-      color: orange
-    name: set color label
+    - image: gcr.io/kpt-fn/set-namespace:v0.4.1
+      configMap:
+        namespace: example-ns
+      name: set namespace
+    - image: gcr.io/kpt-fn/set-labels:v0.2.0
+      configMap:
+        color: orange
+      name: set color label

michaelvl avatar Aug 27 '23 06:08 michaelvl