mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Merge pull request #1291 from monopole/addTest
Add another resmap test.
This commit is contained in:
@@ -39,8 +39,23 @@ type ResMap interface {
|
|||||||
// as appended.
|
// as appended.
|
||||||
Resources() []*resource.Resource
|
Resources() []*resource.Resource
|
||||||
|
|
||||||
// Append adds a Resource.
|
// Append adds a Resource. Error on CurId collision.
|
||||||
// Error on OrgId collision.
|
//
|
||||||
|
// A class invariant of ResMap is that all of its
|
||||||
|
// resources must differ in their value of
|
||||||
|
// CurId(), aka current Id. The Id is the tuple
|
||||||
|
// of {namespace, group, version, kind, name}
|
||||||
|
// (see ResId).
|
||||||
|
//
|
||||||
|
// This invariant reflects the invariant of a
|
||||||
|
// kubernetes cluster, where if one tries to add
|
||||||
|
// a resource to the cluster whose Id matches
|
||||||
|
// that of a resource already in the cluster,
|
||||||
|
// only two outcomes are allowed. Either the
|
||||||
|
// incoming resource is _merged_ into the existing
|
||||||
|
// one, or the incoming resource is rejected.
|
||||||
|
// One cannot end up with two resources
|
||||||
|
// in the cluster with the same Id.
|
||||||
Append(*resource.Resource) error
|
Append(*resource.Resource) error
|
||||||
|
|
||||||
// AppendAll appends another ResMap to self,
|
// AppendAll appends another ResMap to self,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package resmap_test
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||||
@@ -45,6 +46,24 @@ func makeCm(i int) *resource.Resource {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maintain the class invariant that no two
|
||||||
|
// resources can have the same CurId().
|
||||||
|
func TestAppendRejectsDuplicateResId(t *testing.T) {
|
||||||
|
w := New()
|
||||||
|
if err := w.Append(makeCm(1)); err != nil {
|
||||||
|
t.Fatalf("append error: %v", err)
|
||||||
|
}
|
||||||
|
err := w.Append(makeCm(1))
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected append error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(
|
||||||
|
err.Error(),
|
||||||
|
"may not add resource with an already registered id") {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppendRemove(t *testing.T) {
|
func TestAppendRemove(t *testing.T) {
|
||||||
w1 := New()
|
w1 := New()
|
||||||
doAppend(t, w1, makeCm(1))
|
doAppend(t, w1, makeCm(1))
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||||
|
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Change or set the namespace of non-cluster level resources.
|
// Change or set the namespace of non-cluster level resources.
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
|
||||||
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type plugin struct {
|
type plugin struct {
|
||||||
ldr ifc.Loader
|
ldr ifc.Loader
|
||||||
decodedPatch jsonpatch.Patch
|
decodedPatch jsonpatch.Patch
|
||||||
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
|
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
|
||||||
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
Path string `json:"path,omitempty" yaml:"path,omitempty"`
|
||||||
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
|
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//noinspection GoUnusedGlobalVariable
|
//noinspection GoUnusedGlobalVariable
|
||||||
|
|||||||
Reference in New Issue
Block a user