mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
- func/struct names prefixed with package name - public funcs/structs that should be private
150 lines
3.7 KiB
Go
150 lines
3.7 KiB
Go
// Copyright 2019 The Kubernetes Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package hash
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
|
"sigs.k8s.io/kustomize/pkg/resid"
|
|
"sigs.k8s.io/kustomize/pkg/resmap"
|
|
"sigs.k8s.io/kustomize/pkg/resource"
|
|
"sigs.k8s.io/kustomize/pkg/types"
|
|
)
|
|
|
|
func TestNameHashTransformer(t *testing.T) {
|
|
rf := resource.NewFactory(
|
|
kunstruct.NewKunstructuredFactoryImpl())
|
|
objs := resmap.ResMap{
|
|
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "ConfigMap",
|
|
"metadata": map[string]interface{}{
|
|
"name": "cm1",
|
|
},
|
|
}),
|
|
resid.NewResId(deploy, "deploy1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"group": "apps",
|
|
"apiVersion": "v1",
|
|
"kind": "Deployment",
|
|
"metadata": map[string]interface{}{
|
|
"name": "deploy1",
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"template": map[string]interface{}{
|
|
"metadata": map[string]interface{}{
|
|
"labels": map[string]interface{}{
|
|
"old-label": "old-value",
|
|
},
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"containers": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "nginx",
|
|
"image": "nginx:1.7.9",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
resid.NewResId(service, "svc1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "Service",
|
|
"metadata": map[string]interface{}{
|
|
"name": "svc1",
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"ports": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "port1",
|
|
"port": "12345",
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
resid.NewResId(secret, "secret1"): rf.FromMapAndOption(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"metadata": map[string]interface{}{
|
|
"name": "secret1",
|
|
},
|
|
}, &types.GeneratorArgs{Behavior: "create"}, &types.GeneratorOptions{DisableNameSuffixHash: false}),
|
|
}
|
|
|
|
expected := resmap.ResMap{
|
|
resid.NewResId(cmap, "cm1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "ConfigMap",
|
|
"metadata": map[string]interface{}{
|
|
"name": "cm1",
|
|
},
|
|
}),
|
|
resid.NewResId(deploy, "deploy1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"group": "apps",
|
|
"apiVersion": "v1",
|
|
"kind": "Deployment",
|
|
"metadata": map[string]interface{}{
|
|
"name": "deploy1",
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"template": map[string]interface{}{
|
|
"metadata": map[string]interface{}{
|
|
"labels": map[string]interface{}{
|
|
"old-label": "old-value",
|
|
},
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"containers": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "nginx",
|
|
"image": "nginx:1.7.9",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
resid.NewResId(service, "svc1"): rf.FromMap(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "Service",
|
|
"metadata": map[string]interface{}{
|
|
"name": "svc1",
|
|
},
|
|
"spec": map[string]interface{}{
|
|
"ports": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "port1",
|
|
"port": "12345",
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
resid.NewResId(secret, "secret1"): rf.FromMapAndOption(
|
|
map[string]interface{}{
|
|
"apiVersion": "v1",
|
|
"kind": "Secret",
|
|
"metadata": map[string]interface{}{
|
|
"name": "secret1-7kc45hd5f7",
|
|
},
|
|
}, &types.GeneratorArgs{Behavior: "create"}, &types.GeneratorOptions{DisableNameSuffixHash: false}),
|
|
}
|
|
|
|
tran := NewTransformer()
|
|
tran.Transform(objs)
|
|
|
|
if !reflect.DeepEqual(objs, expected) {
|
|
err := expected.ErrorIfNotEqual(objs)
|
|
t.Fatalf("actual doesn't match expected: %v", err)
|
|
}
|
|
}
|