Repository: GoogleContainerTools/kpt
Pull request #3143 (2022-05-12 19:25:08)

fix e2e test in local mode


Patch:
diff --git a/porch/pkg/engine/builtinruntime.go b/porch/pkg/engine/builtinruntime.go
index ecb9eb1a..bf15b67c 100644
--- a/porch/pkg/engine/builtinruntime.go
+++ b/porch/pkg/engine/builtinruntime.go
@@ -27,6 +27,9 @@ import (
 	"github.com/GoogleContainerTools/kpt/porch/pkg/kpt"
 )
 
+// When updating the version for the builtin functions, please also update the image version
+// in test TestBuiltinFunctionEvaluator in porch/test/e2e/e2e_test.go, if the versions mismatch
+// the e2e test will fail in local deployment mode.
 var (
 	applyReplacementsImageAliases = []string{
 		"gcr.io/kpt-fn/apply-replacements:v0.1.1",
diff --git a/porch/pkg/engine/engine.go b/porch/pkg/engine/engine.go
index c1a09588..aab55621 100644
--- a/porch/pkg/engine/engine.go
+++ b/porch/pkg/engine/engine.go
@@ -583,10 +583,12 @@ func healConfig(old, new map[string]string) (map[string]string, error) {
 		},
 	}
 
+	extra := map[string]string{}
+
 	if err := (kio.Pipeline{
 		Inputs: []kio.Reader{&packageReader{
 			input: repository.PackageResources{Contents: new},
-			extra: map[string]string{},
+			extra: extra,
 		}},
 		Filters:               []kio.Filter{filter},
 		Outputs:               []kio.Writer{out},
@@ -595,5 +597,11 @@ func healConfig(old, new map[string]string) (map[string]string, error) {
 		return nil, err
 	}
 
-	return out.output.Contents, nil
+	healed := out.output.Contents
+
+	for k, v := range extra {
+		healed[k] = v
+	}
+
+	return healed, nil
 }


Test patch:
diff --git a/porch/pkg/engine/replace_test.go b/porch/pkg/engine/replace_test.go
index 40ee312d..8bc3283f 100644
--- a/porch/pkg/engine/replace_test.go
+++ b/porch/pkg/engine/replace_test.go
@@ -17,6 +17,7 @@ package engine
 import (
 	"bytes"
 	"context"
+	"path"
 	"path/filepath"
 	"testing"
 
@@ -63,20 +64,30 @@ func removeComments(t *testing.T, r repository.PackageResources) repository.Pack
 	}
 
 	for k, v := range r.Contents {
-		var data interface{}
-		if err := yaml.Unmarshal([]byte(v), &data); err != nil {
-			t.Fatalf("Failed to unmarshal %q: %v", k, err)
-		}
+		base := path.Base(k)
+		ext := path.Ext(base)
 
-		var nocomment bytes.Buffer
-		encoder := yaml.NewEncoder(&nocomment)
-		encoder.SetIndent(0)
-		if err := encoder.Encode(data); err != nil {
-			t.Fatalf("Failed to re-encode yaml output: %v", err)
+		if ext == ".yaml" || ext == ".yml" || base == "Kptfile" {
+			v = removeCommentsFromFile(t, k, v)
 		}
 
-		out.Contents[k] = nocomment.String()
+		out.Contents[k] = v
 	}
-
 	return out
 }
+
+func removeCommentsFromFile(t *testing.T, name, contents string) string {
+	var data interface{}
+	if err := yaml.Unmarshal([]byte(contents), &data); err != nil {
+		t.Fatalf("Failed to unmarshal %q: %v", name, err)
+	}
+
+	var nocomment bytes.Buffer
+	encoder := yaml.NewEncoder(&nocomment)
+	encoder.SetIndent(0)
+	if err := encoder.Encode(data); err != nil {
+		t.Fatalf("Failed to re-encode yaml output: %v", err)
+	}
+
+	return nocomment.String()
+}
diff --git a/porch/pkg/engine/testdata/replace/README.md b/porch/pkg/engine/testdata/replace/README.md
new file mode 100644
index 00000000..6f0623fa
--- /dev/null
+++ b/porch/pkg/engine/testdata/replace/README.md
@@ -0,0 +1,1 @@
+# replace test
\ No newline at end of file
diff --git a/porch/test/e2e/e2e_test.go b/porch/test/e2e/e2e_test.go
index cc27c3ba..06a556ff 100644
--- a/porch/test/e2e/e2e_test.go
+++ b/porch/test/e2e/e2e_test.go
@@ -834,7 +834,8 @@ func (t *PorchSuite) TestBuiltinFunctionEvaluator(ctx context.Context) {
 				{
 					Type: "eval",
 					Eval: &porchapi.FunctionEvalTaskSpec{
-						Image: "gcr.io/kpt-fn/starlark:v0.4.2",
+						//
+						Image: "gcr.io/kpt-fn/starlark:v0.4.3",
 						ConfigMap: map[string]string{
 							"source": `for resource in ctx.resource_list["items"]:
   resource["metadata"]["annotations"]["foo"] = "bar"`,
@@ -959,6 +960,10 @@ for resource in ctx.resource_list["items"]:
 }
 
 func (t *PorchSuite) TestPodFunctionEvaluatorWithDistrolessImage(ctx context.Context) {
+	if t.local {
+		t.Skipf("Skipping due to not having pod evalutor in local mode")
+	}
+
 	t.registerMainGitRepositoryF(ctx, "git-fn-distroless")
 
 	// Create Package Revision