From 48717f3f3072a305eb2b4818e1fe90b90289f93a Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Mon, 11 Feb 2019 15:23:26 -0800 Subject: [PATCH] Switch to black box testing of KustTarget and Resource --- pkg/commands/build/build.go | 2 +- pkg/resource/factory_test.go | 3 +- pkg/resource/resource.go | 2 +- pkg/resource/resource_test.go | 13 +++-- pkg/target/baseandoverlaymedium_test.go | 2 +- pkg/target/baseandoverlaysmall_test.go | 2 +- pkg/target/configmaps_test.go | 2 +- pkg/target/crd_test.go | 2 +- pkg/target/customconfig_test.go | 2 +- pkg/target/generatormergeandreplace_test.go | 2 +- pkg/target/generatoroptions_test.go | 2 +- pkg/target/kusttarget.go | 16 +++---- pkg/target/kusttarget_test.go | 48 +++++++++++-------- ...ls_for_test.go => kusttestharness_test.go} | 17 ++----- pkg/target/multiplepatch_test.go | 2 +- pkg/target/namespacedgenerators_test.go | 2 +- pkg/target/nullvalues_test.go | 2 +- pkg/target/resaccumulator.go | 5 ++ pkg/target/resaccumulator_test.go | 3 +- pkg/target/resourceconflict_test.go | 2 +- pkg/target/variableref_test.go | 2 +- pkg/types/genargs.go | 17 +++++++ pkg/types/genargs_test.go | 47 ++++++++++++++++++ pkg/types/var.go | 6 ++- 24 files changed, 136 insertions(+), 67 deletions(-) rename pkg/target/{utils_for_test.go => kusttestharness_test.go} (87%) create mode 100644 pkg/types/genargs_test.go diff --git a/pkg/commands/build/build.go b/pkg/commands/build/build.go index 43c1a982f0..e62747e329 100644 --- a/pkg/commands/build/build.go +++ b/pkg/commands/build/build.go @@ -108,7 +108,7 @@ func (o *Options) RunBuild( return err } defer ldr.Cleanup() - kt, err := target.NewKustTarget(ldr, fSys, rf, ptf) + kt, err := target.NewKustTarget(ldr, rf, ptf) if err != nil { return err } diff --git a/pkg/resource/factory_test.go b/pkg/resource/factory_test.go index 2fb0adeb86..45394f11d3 100644 --- a/pkg/resource/factory_test.go +++ b/pkg/resource/factory_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resource +package resource_test import ( "reflect" @@ -22,6 +22,7 @@ import ( "sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/patch" + . "sigs.k8s.io/kustomize/pkg/resource" ) func TestSliceFromPatches(t *testing.T) { diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index 7cc87a745a..1e0e3764b8 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -38,7 +38,7 @@ func (r *Resource) String() string { if err != nil { return "<" + err.Error() + ">" } - return strings.TrimSpace(string(bs)) + return strings.TrimSpace(string(bs)) + r.options.String() } // DeepCopy returns a new copy of resource diff --git a/pkg/resource/resource_test.go b/pkg/resource/resource_test.go index fbf4ba30bf..b507d26337 100644 --- a/pkg/resource/resource_test.go +++ b/pkg/resource/resource_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package resource +package resource_test import ( "testing" @@ -22,6 +22,7 @@ import ( "sigs.k8s.io/kustomize/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/resid" + . "sigs.k8s.io/kustomize/pkg/resource" ) var factory = NewFactory( @@ -37,7 +38,9 @@ var testConfigMap = factory.FromMap( }, }) -const testConfigMapString = `{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie","namespace":"hundred-acre-wood"}}` +const genArgOptions = "{nsfx:false,beh:unspecified}" + +const configMapAsString = `{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie","namespace":"hundred-acre-wood"}}` var testDeployment = factory.FromMap( map[string]interface{}{ @@ -48,7 +51,7 @@ var testDeployment = factory.FromMap( }, }) -const testDeploymentString = `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"pooh"}}` +const deploymentAsString = `{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"pooh"}}` func TestResourceString(t *testing.T) { tests := []struct { @@ -57,11 +60,11 @@ func TestResourceString(t *testing.T) { }{ { in: testConfigMap, - s: testConfigMapString, + s: configMapAsString + genArgOptions, }, { in: testDeployment, - s: testDeploymentString, + s: deploymentAsString + genArgOptions, }, } for _, test := range tests { diff --git a/pkg/target/baseandoverlaymedium_test.go b/pkg/target/baseandoverlaymedium_test.go index 24f9558a43..6c409db28f 100644 --- a/pkg/target/baseandoverlaymedium_test.go +++ b/pkg/target/baseandoverlaymedium_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/baseandoverlaysmall_test.go b/pkg/target/baseandoverlaysmall_test.go index d9cbdb3fea..dfcd1fd43d 100644 --- a/pkg/target/baseandoverlaysmall_test.go +++ b/pkg/target/baseandoverlaysmall_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/configmaps_test.go b/pkg/target/configmaps_test.go index 9d62a6847c..5c4ad8d08f 100644 --- a/pkg/target/configmaps_test.go +++ b/pkg/target/configmaps_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/crd_test.go b/pkg/target/crd_test.go index a8e9a757d8..7bd71083c3 100644 --- a/pkg/target/crd_test.go +++ b/pkg/target/crd_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/customconfig_test.go b/pkg/target/customconfig_test.go index daf616681d..8aaa91a96b 100644 --- a/pkg/target/customconfig_test.go +++ b/pkg/target/customconfig_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/generatormergeandreplace_test.go b/pkg/target/generatormergeandreplace_test.go index 028dd63e94..469c9c9e19 100644 --- a/pkg/target/generatormergeandreplace_test.go +++ b/pkg/target/generatormergeandreplace_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/generatoroptions_test.go b/pkg/target/generatoroptions_test.go index e3c81c1eee..4dbdbb588e 100644 --- a/pkg/target/generatoroptions_test.go +++ b/pkg/target/generatoroptions_test.go @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/kusttarget.go b/pkg/target/kusttarget.go index 0e5eaa1e3d..f136b2683b 100644 --- a/pkg/target/kusttarget.go +++ b/pkg/target/kusttarget.go @@ -26,7 +26,6 @@ import ( "github.com/ghodss/yaml" "github.com/pkg/errors" "sigs.k8s.io/kustomize/pkg/constants" - "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc/transformer" interror "sigs.k8s.io/kustomize/pkg/internal/error" @@ -42,7 +41,6 @@ import ( type KustTarget struct { kustomization *types.Kustomization ldr ifc.Loader - fSys fs.FileSystem rFactory *resmap.Factory tFactory transformer.Factory } @@ -50,7 +48,6 @@ type KustTarget struct { // NewKustTarget returns a new instance of KustTarget primed with a Loader. func NewKustTarget( ldr ifc.Loader, - fSys fs.FileSystem, rFactory *resmap.Factory, tFactory transformer.Factory) (*KustTarget, error) { content, err := loadKustFile(ldr) @@ -70,7 +67,6 @@ func NewKustTarget( return &KustTarget{ kustomization: &k, ldr: ldr, - fSys: fSys, rFactory: rFactory, tFactory: tFactory, }, nil @@ -123,7 +119,7 @@ func unmarshal(y []byte, o interface{}) error { // MakeCustomizedResMap creates a ResMap per kustomization instructions. // The Resources in the returned ResMap are fully customized. func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) { - ra, err := kt.accumulateTarget() + ra, err := kt.AccumulateTarget() if err != nil { return nil, err } @@ -147,11 +143,11 @@ func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool { !kt.kustomization.GeneratorOptions.DisableNameSuffixHash } -// accumulateTarget returns a new ResAccumulator, +// AccumulateTarget returns a new ResAccumulator, // holding customized resources and the data/rules used // to do so. The name back references and vars are // not yet fixed. -func (kt *KustTarget) accumulateTarget() ( +func (kt *KustTarget) AccumulateTarget() ( ra *ResAccumulator, err error) { // TODO(monopole): Get rid of the KustomizationErrors accumulator. // It's not consistently used, and complicates tests. @@ -249,15 +245,15 @@ func (kt *KustTarget) accumulateBases() ( continue } subKt, err := NewKustTarget( - ldr, kt.fSys, kt.rFactory, kt.tFactory) + ldr, kt.rFactory, kt.tFactory) if err != nil { errs.Append(errors.Wrap(err, "couldn't make target for "+path)) ldr.Cleanup() continue } - subRa, err := subKt.accumulateTarget() + subRa, err := subKt.AccumulateTarget() if err != nil { - errs.Append(errors.Wrap(err, "accumulateTarget")) + errs.Append(errors.Wrap(err, "AccumulateTarget")) ldr.Cleanup() continue } diff --git a/pkg/target/kusttarget_test.go b/pkg/target/kusttarget_test.go index 87c15a19b4..e57fe0f374 100644 --- a/pkg/target/kusttarget_test.go +++ b/pkg/target/kusttarget_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "encoding/base64" @@ -23,18 +23,18 @@ import ( "strings" "testing" - "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" + . "sigs.k8s.io/kustomize/pkg/target" "sigs.k8s.io/kustomize/pkg/types" ) const ( - kustomizationContent1 = ` + kustomizationContent = ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namePrefix: foo- @@ -47,6 +47,8 @@ commonAnnotations: resources: - deployment.yaml - namespace.yaml +generatorOptions: + disableNameSuffixHash: false configMapGenerator: - name: literalConfigMap literals: @@ -83,9 +85,9 @@ metadata: ]` ) -func TestResources1(t *testing.T) { +func TestResources(t *testing.T) { th := NewKustTestHarness(t, "/whatever") - th.writeK("/whatever/", kustomizationContent1) + th.writeK("/whatever/", kustomizationContent) th.writeF("/whatever/deployment.yaml", deploymentContent) th.writeF("/whatever/namespace.yaml", namespaceContent) th.writeF("/whatever/jsonpatch.json", jsonpatchContent) @@ -146,7 +148,9 @@ func TestResources1(t *testing.T) { "DB_USERNAME": "admin", "DB_PASSWORD": "somepw", }, - }, &types.GeneratorArgs{}, nil), + }, + &types.GeneratorArgs{}, + &types.GeneratorOptions{}), resid.NewResIdWithPrefixSuffixNamespace( gvk.Gvk{Version: "v1", Kind: "Secret"}, "secret", "foo-", "-bar", "ns1"): th.fromMapAndOption( @@ -168,7 +172,9 @@ func TestResources1(t *testing.T) { "DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")), "DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")), }, - }, &types.GeneratorArgs{}, nil), + }, + &types.GeneratorArgs{}, + &types.GeneratorOptions{}), resid.NewResIdWithPrefixSuffixNamespace( gvk.Gvk{Version: "v1", Kind: "Namespace"}, "ns1", "foo-", "-bar", ""): th.fromMap( @@ -198,8 +204,7 @@ func TestResources1(t *testing.T) { } func TestKustomizationNotFound(t *testing.T) { - _, err := NewKustTarget( - loadertest.NewFakeLoader("/foo"), fs.MakeFakeFS(), nil, nil) + _, err := NewKustTarget(loadertest.NewFakeLoader("/foo"), nil, nil) if err == nil { t.Fatalf("expected an error") } @@ -211,7 +216,7 @@ func TestKustomizationNotFound(t *testing.T) { func TestResourceNotFound(t *testing.T) { th := NewKustTestHarness(t, "/whatever") - th.writeK("/whatever", kustomizationContent1) + th.writeK("/whatever", kustomizationContent) _, err := th.makeKustTarget().MakeCustomizedResMap() if err == nil { t.Fatalf("Didn't get the expected error for an unknown resource") @@ -232,13 +237,12 @@ func findSecret(m resmap.ResMap) *resource.Resource { func TestDisableNameSuffixHash(t *testing.T) { th := NewKustTestHarness(t, "/whatever") - th.writeK("/whatever/", kustomizationContent1) + th.writeK("/whatever/", kustomizationContent) th.writeF("/whatever/deployment.yaml", deploymentContent) th.writeF("/whatever/namespace.yaml", namespaceContent) th.writeF("/whatever/jsonpatch.json", jsonpatchContent) - kt := th.makeKustTarget() - m, err := kt.MakeCustomizedResMap() + m, err := th.makeKustTarget().MakeCustomizedResMap() if err != nil { t.Fatalf("unexpected Resources error %v", err) } @@ -250,9 +254,11 @@ func TestDisableNameSuffixHash(t *testing.T) { t.Errorf("unexpected secret resource name: %s", secret.GetName()) } - kt.kustomization.GeneratorOptions = &types.GeneratorOptions{ - DisableNameSuffixHash: true} - m, err = kt.MakeCustomizedResMap() + th.writeK("/whatever/", + strings.Replace(kustomizationContent, + "disableNameSuffixHash: false", + "disableNameSuffixHash: true", -1)) + m, err = th.makeKustTarget().MakeCustomizedResMap() if err != nil { t.Fatalf("unexpected Resources error %v", err) } @@ -338,11 +344,11 @@ vars: name: heron apiVersion: v300 `) - ra, err := th.makeKustTarget().accumulateTarget() + ra, err := th.makeKustTarget().AccumulateTarget() if err != nil { t.Fatalf("Err: %v", err) } - vars := ra.varSet.Set() + vars := ra.Vars() if len(vars) != 2 { t.Fatalf("unexpected size %d", len(vars)) } @@ -388,11 +394,11 @@ vars: bases: - ../o1 `) - ra, err := th.makeKustTarget().accumulateTarget() + ra, err := th.makeKustTarget().AccumulateTarget() if err != nil { t.Fatalf("Err: %v", err) } - vars := ra.varSet.Set() + vars := ra.Vars() if len(vars) != 4 { for i, v := range vars { fmt.Printf("%v: %v\n", i, v) @@ -441,7 +447,7 @@ vars: bases: - ../o1 `) - _, err := th.makeKustTarget().accumulateTarget() + _, err := th.makeKustTarget().AccumulateTarget() if err == nil { t.Fatalf("expected var collision") } diff --git a/pkg/target/utils_for_test.go b/pkg/target/kusttestharness_test.go similarity index 87% rename from pkg/target/utils_for_test.go rename to pkg/target/kusttestharness_test.go index 3b3a8f7e52..74cbab348c 100644 --- a/pkg/target/utils_for_test.go +++ b/pkg/target/kusttestharness_test.go @@ -14,24 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test // A collection of utilities used in target tests. import ( "fmt" "path/filepath" - "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig" "strings" "testing" "sigs.k8s.io/kustomize/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/k8sdeps/transformer" "sigs.k8s.io/kustomize/pkg/constants" - "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" + . "sigs.k8s.io/kustomize/pkg/target" + "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig" "sigs.k8s.io/kustomize/pkg/types" ) @@ -50,17 +50,8 @@ func NewKustTestHarness(t *testing.T, path string) *KustTestHarness { } func (th *KustTestHarness) makeKustTarget() *KustTarget { - // Warning: the following filesystem - a fake - must be rooted at /. - // This fs root is used as the working directory for the shell spawned by - // the secretgenerator, and has nothing to do with the filesystem used - // to load relative paths from the fake filesystem. - // This trick only works for secret generator commands that don't actually - // try to read the file system, because these tests don't write to the - // real "/" directory. See use of exec package in the secretfactory. - fakeFs := fs.MakeFakeFS() - fakeFs.Mkdir("/") kt, err := NewKustTarget( - th.ldr, fakeFs, th.rf, transformer.NewFactoryImpl()) + th.ldr, th.rf, transformer.NewFactoryImpl()) if err != nil { th.t.Fatalf("Unexpected construction error %v", err) } diff --git a/pkg/target/multiplepatch_test.go b/pkg/target/multiplepatch_test.go index 6b5ed8ddb3..6aa3bb6aa9 100644 --- a/pkg/target/multiplepatch_test.go +++ b/pkg/target/multiplepatch_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "strings" diff --git a/pkg/target/namespacedgenerators_test.go b/pkg/target/namespacedgenerators_test.go index 2d46f07274..d6e550efc4 100644 --- a/pkg/target/namespacedgenerators_test.go +++ b/pkg/target/namespacedgenerators_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/nullvalues_test.go b/pkg/target/nullvalues_test.go index f04cfb9323..7ccbbf1fa4 100644 --- a/pkg/target/nullvalues_test.go +++ b/pkg/target/nullvalues_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/target/resaccumulator.go b/pkg/target/resaccumulator.go index 41e448b8d6..2ae05ba2c3 100644 --- a/pkg/target/resaccumulator.go +++ b/pkg/target/resaccumulator.go @@ -55,6 +55,11 @@ func (ra *ResAccumulator) ResMap() resmap.ResMap { return result } +// Vars returns a copy of underlying vars. +func (ra *ResAccumulator) Vars() []types.Var { + return ra.varSet.Set() +} + func (ra *ResAccumulator) MergeResourcesWithErrorOnIdCollision( resources resmap.ResMap) (err error) { ra.resMap, err = resmap.MergeWithErrorOnIdCollision( diff --git a/pkg/target/resaccumulator_test.go b/pkg/target/resaccumulator_test.go index 69ec0b791c..0bf1eedaab 100644 --- a/pkg/target/resaccumulator_test.go +++ b/pkg/target/resaccumulator_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "strings" @@ -25,6 +25,7 @@ import ( "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" + . "sigs.k8s.io/kustomize/pkg/target" "sigs.k8s.io/kustomize/pkg/transformers/config" "sigs.k8s.io/kustomize/pkg/types" ) diff --git a/pkg/target/resourceconflict_test.go b/pkg/target/resourceconflict_test.go index 991805a03b..27a5bd18b5 100644 --- a/pkg/target/resourceconflict_test.go +++ b/pkg/target/resourceconflict_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "strings" diff --git a/pkg/target/variableref_test.go b/pkg/target/variableref_test.go index 60aa47add6..9d46030a45 100644 --- a/pkg/target/variableref_test.go +++ b/pkg/target/variableref_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package target +package target_test import ( "testing" diff --git a/pkg/types/genargs.go b/pkg/types/genargs.go index a74a48d222..bef093d350 100644 --- a/pkg/types/genargs.go +++ b/pkg/types/genargs.go @@ -16,6 +16,11 @@ limitations under the License. package types +import ( + "strconv" + "strings" +) + // GenArgs contains both generator args and options type GenArgs struct { args *GeneratorArgs @@ -30,6 +35,18 @@ func NewGenArgs(args *GeneratorArgs, opts *GeneratorOptions) *GenArgs { } } +func (g *GenArgs) String() string { + if g == nil { + return "{nilGenArgs}" + } + return "{" + + strings.Join([]string{ + "nsfx:" + strconv.FormatBool(g.NeedsHashSuffix()), + "beh:" + g.Behavior().String()}, + ",") + + "}" +} + // NeedHashSuffix returns true if the hash suffix is needed. // It is needed when the two conditions are both met // 1) GenArgs is not nil diff --git a/pkg/types/genargs_test.go b/pkg/types/genargs_test.go new file mode 100644 index 0000000000..a50dfd9679 --- /dev/null +++ b/pkg/types/genargs_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2018 The Kubernetes Authors. + Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types_test + +import ( + "testing" + + . "sigs.k8s.io/kustomize/pkg/types" +) + +func TestGenArgs_String(t *testing.T) { + tests := []struct { + ga *GenArgs + expected string + }{ + { + ga: nil, + expected: "{nilGenArgs}", + }, + { + ga: &GenArgs{}, + expected: "{nsfx:false,beh:unspecified}", + }, + { + ga: NewGenArgs( + &GeneratorArgs{Behavior: "merge"}, + &GeneratorOptions{DisableNameSuffixHash: false}), + expected: "{nsfx:true,beh:merge}", + }, + } + for _, test := range tests { + if test.ga.String() != test.expected { + t.Fatalf("Expected '%s', got '%s'", test.expected, test.ga.String()) + } + } +} diff --git a/pkg/types/var.go b/pkg/types/var.go index 4be30078b9..6a48032a08 100644 --- a/pkg/types/var.go +++ b/pkg/types/var.go @@ -75,9 +75,11 @@ type VarSet struct { set []Var } -// Set returns the var set. +// Set returns a copy of the var set. func (vs *VarSet) Set() []Var { - return vs.set + s := make([]Var, len(vs.set)) + copy(s, vs.set) + return s } // MergeSet absorbs other vars with error on name collision.