From 8bd989abb1a8f719e3063505fb407d1c421d7a98 Mon Sep 17 00:00:00 2001 From: Morten Torkildsen Date: Tue, 31 Mar 2020 20:29:50 -0700 Subject: [PATCH] Improve tests for AnnotationsTransformer --- api/builtins/AnnotationsTransformer.go | 2 +- .../AnnotationsTransformer.go | 2 +- .../AnnotationsTransformer_test.go | 35 +++++++++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/api/builtins/AnnotationsTransformer.go b/api/builtins/AnnotationsTransformer.go index 80cee93c5..823b12d62 100644 --- a/api/builtins/AnnotationsTransformer.go +++ b/api/builtins/AnnotationsTransformer.go @@ -19,7 +19,7 @@ type AnnotationsTransformerPlugin struct { // YAMLSupport can be set to true to use the kyaml filter instead of the // kunstruct transformer - YAMLSupport bool + YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"` } func (p *AnnotationsTransformerPlugin) Config( diff --git a/plugin/builtin/annotationstransformer/AnnotationsTransformer.go b/plugin/builtin/annotationstransformer/AnnotationsTransformer.go index b15c94139..7b6ea3296 100644 --- a/plugin/builtin/annotationstransformer/AnnotationsTransformer.go +++ b/plugin/builtin/annotationstransformer/AnnotationsTransformer.go @@ -20,7 +20,7 @@ type plugin struct { // YAMLSupport can be set to true to use the kyaml filter instead of the // kunstruct transformer - YAMLSupport bool + YAMLSupport bool `json:"yamlSupport,omitempty" yaml:"yamlSupport,omitempty"` } //noinspection GoUnusedGlobalVariable diff --git a/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go b/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go index a394ffa60..fb26c6ca1 100644 --- a/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go +++ b/plugin/builtin/annotationstransformer/AnnotationsTransformer_test.go @@ -4,17 +4,14 @@ package main_test import ( + "fmt" "testing" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" ) -func TestAnnotationsTransformer(t *testing.T) { - th := kusttest_test.MakeEnhancedHarness(t). - PrepBuiltin("AnnotationsTransformer") - defer th.Reset() - - rm := th.LoadAndRunTransformer(` +var ( + config = ` apiVersion: builtin kind: AnnotationsTransformer metadata: @@ -22,10 +19,12 @@ metadata: annotations: app: myApp greeting/morning: a string with blanks +yamlSupport: %v fieldSpecs: - path: metadata/annotations create: true -`, ` +` + input = ` apiVersion: v1 kind: Service metadata: @@ -33,9 +32,8 @@ metadata: spec: ports: - port: 7002 -`) - - th.AssertActualEqualsExpected(rm, ` +` + expectedOutput = ` apiVersion: v1 kind: Service metadata: @@ -46,5 +44,20 @@ metadata: spec: ports: - port: 7002 -`) +` +) + +func TestAnnotationsTransformer(t *testing.T) { + for _, b := range []bool{true, false} { + t.Run(fmt.Sprintf("yaml-%v", b), func(t *testing.T) { + th := kusttest_test.MakeEnhancedHarness(t). + PrepBuiltin("AnnotationsTransformer") + defer th.Reset() + + cfg := fmt.Sprintf(config, b) + rm := th.LoadAndRunTransformer(cfg, input) + + th.AssertActualEqualsExpected(rm, expectedOutput) + }) + } }