// TestNameReferenceNamespace creates serviceAccount and clusterRoleBinding
// object with the same original names (uniquename) in different namespaces
// and with different current Id.
TestNameReferenceNamespace creates serviceAccount and clusterRoleBinding
object with the same original names (uniquename) in different namespaces
and with different current Id.
// TestNameReferenceNamespace creates serviceAccount and clusterRoleBinding // object with the same original names ( uniquename ) in different namespaces // and with different current Id .
func TestNameReferenceClusterWide(t *testing.T) {
	m := resmaptest_test.NewRmBuilderDefault(t).
		AddWithName(orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "ServiceAccount",
			"metadata": map[string]interface{}{
				"name": modifiedname,
			}}).
		AddWithNsAndName(ns1, orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "ServiceAccount",
			"metadata": map[string]interface{}{
				"name":      prefixedname,
				"namespace": ns1,
			}}).
		AddWithNsAndName(ns2, orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "ServiceAccount",
			"metadata": map[string]interface{}{
				"name":      suffixedname,
				"namespace": ns2,
			}}).
		AddWithName(orgname, map[string]interface{}{
			"apiVersion": "v1",
			"kind":       "PersistentVolume",
			"metadata": map[string]interface{}{
				"name": modifiedname,
			}}).
		AddWithName(orgname, map[string]interface{}{
			"apiVersion": "rbac.authorization.k8s.io/v1",
			"kind":       "ClusterRole",
			"metadata": map[string]interface{}{
				"name": modifiedname,
			},
			"rules": []interface{}{
				map[string]interface{}{
					"resources": []interface{}{
						"persistentvolumes",
					},
					"resourceNames": []interface{}{
						orgname,
					},
				},
			}}).
		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": defaultNs,
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": ns1,
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": ns2,
				},
				map[string]interface{}{
					"kind":      "ServiceAccount",
					"name":      orgname,
					"namespace": "random",
				},
			}}).ResMap()
	expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
		ReplaceResource(
			map[string]interface{}{
				"apiVersion": "rbac.authorization.k8s.io/v1",
				"kind":       "ClusterRole",
				"metadata": map[string]interface{}{
					"name": modifiedname,
				},
				"rules": []interface{}{
					map[string]interface{}{
						"resources": []interface{}{
							"persistentvolumes",
						},
						"resourceNames": []interface{}{
							modifiedname,
						},
					},
				}}).
		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":      modifiedname,
						"namespace": defaultNs,
					},
					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",
					},
				},
			}).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 TestNameReferenceClusterWide ( t * testing . T ) { m := resmaptest_test . NewRmBuilderDefault ( t ) . AddWithName ( orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } } ) . AddWithNsAndName ( ns1 , orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : prefixedname , " " : ns1 , } } ) . AddWithNsAndName ( ns2 , 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 , } , " " : [ ] interface { } { map [ string ] interface { } { " " : [ ] interface { } { " " , } , " " : [ ] interface { } { orgname , } , } , } } ) . AddWithName ( orgname , map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } , " " : map [ string ] interface { } { " " : " " , " " : " " , " " : orgname , } , " " : [ ] interface { } { map [ string ] interface { } { " " : " " , " " : orgname , " " : defaultNs , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : ns1 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : ns2 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : " " , } , } } ) . ResMap ( ) expected := resmaptest_test . NewSeededRmBuilderDefault ( t , m . ShallowCopy ( ) ) . ReplaceResource ( map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } , " " : [ ] interface { } { map [ string ] interface { } { " " : [ ] interface { } { " " , } , " " : [ ] interface { } { modifiedname , } , } , } } ) . ReplaceResource ( map [ string ] interface { } { " " : " " , " " : " " , " " : map [ string ] interface { } { " " : modifiedname , } , " " : map [ string ] interface { } { " " : " " , " " : " " , " " : modifiedname , } , " " : [ ] interface { } { map [ string ] interface { } { " " : " " , " " : modifiedname , " " : defaultNs , } , map [ string ] interface { } { " " : " " , " " : prefixedname , " " : ns1 , } , map [ string ] interface { } { " " : " " , " " : suffixedname , " " : ns2 , } , map [ string ] interface { } { " " : " " , " " : orgname , " " : " " , } , } , } ) . 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 ) } }
TestNameReferenceNamespace creates serviceAccount and clusterRoleBinding
object with the same original names (uniquename) in different namespaces
and with different current Id.
TestNameReferenceNamespace 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 noNs, "ns1" and "ns2" namespaces // Add a PersistentVolume to have a clusterwide resource // Behavior of the transformer is still imperfect // It should use the (resources,apigroup,resourceNames) as // combination to select the candidates. // The following tests required a change in // getNameFunc implementation in order to leverage // the namespace field.