// TestNameReferenceNamespaceTransformation creates serviceAccount and clusterRoleBinding
// object with the same original names (uniquename) in different namespaces
// and with different current Id.
TestNameReferenceNamespaceTransformation creates serviceAccount and clusterRoleBinding
object with the same original names (uniquename) in different namespaces
and with different current Id.
// TestNameReferenceNamespaceTransformation creates serviceAccount and clusterRoleBinding // object with the same original names ( uniquename ) in different namespaces // and with different current Id .
func TestNameReferenceNamespaceTransformation(t *testing.T) {
	m := resmaptest_test.NewRmBuilderDefault(t).
		AddWithNsAndName(ns4, orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "Secret",
			"metadata": map[string]interface{}{
				"name":      orgname,
				"namespace": ns4,
			}}).
		AddWithNsAndName(ns1, orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "ServiceAccount",
			"metadata": map[string]interface{}{
				"name":      prefixedname,
				"namespace": ns1,
			}}).
		AddWithNsAndName(ns3, orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "ServiceAccount",
			"metadata": map[string]interface{}{
				"name":      suffixedname,
				"namespace": ns2,
			}}).
		AddWithName(orgname, map[string]interface{}{
			"apiVersion": "rbac.authorization.k8s.io/v1",
			"kind":       "ClusterRole",
			"metadata": map[string]interface{}{
				"name": modifiedname,
			}}).
		AddWithName(orgname, map[string]interface{}{
			"apiVersion": "rbac.authorization.k8s.io/v1",
			"kind":       "ClusterRoleBinding",
			"metadata": map[string]interface{}{
				"name": modifiedname,
			},
			"roleRef": map[string]interface{}{
				"apiGroup": "rbac.authorization.k8s.io",
				"kind":     "ClusterRole",
				"name":     orgname,
			},
			"subjects": []interface{}{
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": ns1,
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": ns3,
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": "random",
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": ns4,
				},
			}}).ResMap()
	expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
		ReplaceResource(
			map[string]interface{}{
				"apiVersion": "rbac.authorization.k8s.io/v1",
				"kind":       "ClusterRoleBinding",
				"metadata": map[string]interface{}{
					"name": modifiedname,
				},
				"roleRef": map[string]interface{}{
					"apiGroup": "rbac.authorization.k8s.io",
					"kind":     "ClusterRole",
					"name":     modifiedname,
				},
				"subjects": []interface{}{
					map[string]interface{}{
						"kind":      "ServiceAccount",
						"name":      prefixedname,
						"namespace": ns1,
					},
					map[string]interface{}{
						"kind":      "ServiceAccount",
						"name":      suffixedname,
						"namespace": ns2,
					},
					map[string]interface{}{
						"kind":      "ServiceAccount",
						"name":      orgname,
						"namespace": "random",
					},
					map[string]interface{}{
						"kind":      "ServiceAccount",
						"name":      orgname,
						"namespace": ns4,
					},
				},
			}).ResMap()
	clusterRoleId := resid.NewResId(
		resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRole"),
		modifiedname)
	clusterRoleBindingId := resid.NewResId(
		resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRoleBinding"),
		modifiedname)
	clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
	clusterRole.AppendRefBy(clusterRoleBindingId)
	nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
	err := nrt.Transform(m)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	m.RemoveBuildAnnotations()
	if err = expected.ErrorIfNotEqualLists(m); err != nil {
		t.Fatalf(notEqualErrFmt, err)
	}
}
func TestNameReferenceNamespaceTransformation ( t * testing . T ) { m := resmaptest_test . NewRmBuilderDefault ( t ) . AddWithNsAndName ( ns4 , orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : orgname , " " : ns4 , } } ) . AddWithNsAndName ( ns1 , orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : prefixedname , " " : ns1 , } } ) . AddWithNsAndName ( ns3 , orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : suffixedname , " " : ns2 , } } ) . AddWithName ( orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } } ) . AddWithName ( orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } , " " : map [ string ] interface { } { " " : " " , " " : " " , " " : orgname , } , " " : [ ] interface { } { map [ string ] interface { } { " " : " " , " " : orgname , " " : ns1 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : ns3 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : " " , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : ns4 , } , } } ) . ResMap ( ) expected := resmaptest_test . NewSeededRmBuilderDefault ( t , m . ShallowCopy ( ) ) . ReplaceResource ( map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } , " " : map [ string ] interface { } { " " : " " , " " : " " , " " : modifiedname , } , " " : [ ] interface { } { map [ string ] interface { } { " " : " " , " " : prefixedname , " " : ns1 , } , map [ string ] interface { } { " " : " " , " " : suffixedname , " " : ns2 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : " " , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : ns4 , } , } , } ) . ResMap ( ) clusterRoleId := resid . NewResId ( resid . NewGvk ( " " , " " , " " ) , modifiedname ) clusterRoleBindingId := resid . NewResId ( resid . NewGvk ( " " , " " , " " ) , modifiedname ) clusterRole , _ := expected . GetByCurrentId ( clusterRoleId ) clusterRole . AppendRefBy ( clusterRoleBindingId ) nrt := newNameReferenceTransformer ( builtinconfig . MakeDefaultConfig ( ) . NameReference ) err := nrt . Transform ( m ) if err != nil { t . Fatalf ( " " , err ) } m . RemoveBuildAnnotations ( ) if err = expected . ErrorIfNotEqualLists ( m ) ; err != nil { t . Fatalf ( notEqualErrFmt , err ) } }
TestNameReferenceNamespaceTransformation creates serviceAccount and clusterRoleBinding
object with the same original names (uniquename) in different namespaces
and with different current Id.
TestNameReferenceNamespaceTransformation creates serviceAccount and clusterRoleBinding object with the same original names ( uniquename ) in different namespaces and with different current Id .
// Add ServiceAccount with the same org name in "ns1" namespaces // Simulate NamespaceTransformer effect (ns3 transformed in ns2) // The following tests required a change in // getNameFunc implementation in order to leverage // the namespace field.