// checks that defaulting succeeds when there are multiple plans but only a
// single plan for the specified Service Class
checks that defaulting succeeds when there are multiple plans but only a
single plan for the specified Service Class
// checks that defaulting succeeds when there are multiple plans but only a // single plan for the specified Service Class
func TestWithNoPlanSucceedsWithMultiplePlansFromDifferentClasses(t *testing.T) {
	cases := []struct {
		name          string
		requestedPlan servicecatalog.PlanReference
		resolvedPlan  servicecatalog.PlanReference
		namespaced    bool
	}{
		{"cluster external name",
			servicecatalog.PlanReference{ClusterServiceClassExternalName: "foo"},
			servicecatalog.PlanReference{ClusterServiceClassExternalName: "foo", ClusterServicePlanExternalName: "bar"}, false},
		{"cluster external id",
			servicecatalog.PlanReference{ClusterServiceClassExternalID: "foo"},
			servicecatalog.PlanReference{ClusterServiceClassExternalID: "foo", ClusterServicePlanExternalID: "12345"}, false},
		{"cluster k8s", servicecatalog.PlanReference{ClusterServiceClassName: "foo-id"},
			servicecatalog.PlanReference{ClusterServiceClassName: "foo-id", ClusterServicePlanName: "bar-id"}, false},
		{"ns external name",
			servicecatalog.PlanReference{ServiceClassExternalName: "foo"},
			servicecatalog.PlanReference{ServiceClassExternalName: "foo", ServicePlanExternalName: "bar"}, true},
		{"ns external id",
			servicecatalog.PlanReference{ServiceClassExternalID: "foo"},
			servicecatalog.PlanReference{ServiceClassExternalID: "foo", ServicePlanExternalID: "12345"}, true},
		{"ns k8s", servicecatalog.PlanReference{ServiceClassName: "foo-id"},
			servicecatalog.PlanReference{ServiceClassName: "foo-id", ServicePlanName: "bar-id"}, true},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			var fakeClient *fake.Clientset
			classFilter := "test-serviceclass"
			if tc.namespaced {
				sc := newServiceClass("foo-id", "foo")
				sps := newServicePlans(2, true)
				glog.V(4).Infof("Created Service as %+v", sc)
				fakeClient = newFakeServiceCatalogClientForNamespacedTest(sc, sps, classFilter )
			} else {
				csc := newClusterServiceClass("foo-id", "foo")
				csps := newClusterServicePlans(2, true)
				glog.V(4).Infof("Created Service as %+v", csc)
				fakeClient = newFakeServiceCatalogClientForTest(csc, csps, classFilter )
			}
			handler, informerFactory, err := newHandlerForTest(fakeClient)
			if err != nil {
				t.Errorf("unexpected error initializing handler: %v", err)
			}
			informerFactory.Start(wait.NeverStop)
			instance := newServiceInstance("dummy")
			instance.Spec.PlanReference = tc.requestedPlan
			err = handler.(admission.MutationInterface).Admit(admission.NewAttributesRecord(&instance, nil, servicecatalog.Kind("ServiceInstance").WithVersion("version"), instance.Namespace, instance.Name, servicecatalog.Resource("serviceinstances").WithVersion("version"), "", admission.Create, nil))
			if err != nil {
				actions := ""
				for _, action := range fakeClient.Actions() {
					actions = actions + action.GetVerb() + ":" + action.GetResource().Resource + ":" + action.GetSubresource() + ", "
				}
				t.Errorf("unexpected error %q returned from admission handler: %v", err, actions)
			}
			assertPlanReference(t,
				tc.resolvedPlan,
				instance.Spec.PlanReference)
		})
	}
}
func TestWithNoPlanSucceedsWithMultiplePlansFromDifferentClasses ( t * testing . T ) { cases := [ ] struct { name string requestedPlan servicecatalog . PlanReference resolvedPlan servicecatalog . PlanReference namespaced bool } { { " " , servicecatalog . PlanReference { ClusterServiceClassExternalName : " " } , servicecatalog . PlanReference { ClusterServiceClassExternalName : " " , ClusterServicePlanExternalName : " " } , false } , { " " , servicecatalog . PlanReference { ClusterServiceClassExternalID : " " } , servicecatalog . PlanReference { ClusterServiceClassExternalID : " " , ClusterServicePlanExternalID : " " } , false } , { " " , servicecatalog . PlanReference { ClusterServiceClassName : " " } , servicecatalog . PlanReference { ClusterServiceClassName : " " , ClusterServicePlanName : " " } , false } , { " " , servicecatalog . PlanReference { ServiceClassExternalName : " " } , servicecatalog . PlanReference { ServiceClassExternalName : " " , ServicePlanExternalName : " " } , true } , { " " , servicecatalog . PlanReference { ServiceClassExternalID : " " } , servicecatalog . PlanReference { ServiceClassExternalID : " " , ServicePlanExternalID : " " } , true } , { " " , servicecatalog . PlanReference { ServiceClassName : " " } , servicecatalog . PlanReference { ServiceClassName : " " , ServicePlanName : " " } , true } , } for _ , tc := range cases { t . Run ( tc . name , func ( t * testing . T ) { var fakeClient * fake . Clientset classFilter := " " if tc . namespaced { sc := newServiceClass ( " " , " " ) sps := newServicePlans ( 2 , true ) glog . V ( 4 ) . Infof ( " " , sc ) fakeClient = newFakeServiceCatalogClientForNamespacedTest ( sc , sps , classFilter ) } else { csc := newClusterServiceClass ( " " , " " ) csps := newClusterServicePlans ( 2 , true ) glog . V ( 4 ) . Infof ( " " , csc ) fakeClient = newFakeServiceCatalogClientForTest ( csc , csps , classFilter ) } handler , informerFactory , err := newHandlerForTest ( fakeClient ) if err != nil { t . Errorf ( " " , err ) } informerFactory . Start ( wait . NeverStop ) instance := newServiceInstance ( " " ) instance . Spec . PlanReference = tc . requestedPlan err = handler . ( admission . MutationInterface ) . Admit ( admission . NewAttributesRecord ( & instance , nil , servicecatalog . Kind ( " " ) . WithVersion ( " " ) , instance . Namespace , instance . Name , servicecatalog . Resource ( " " ) . WithVersion ( " " ) , " " , admission . Create , nil ) ) if err != nil { actions := " " for _ , action := range fakeClient . Actions ( ) { actions = actions + action . GetVerb ( ) + " " + action . GetResource ( ) . Resource + " " + action . GetSubresource ( ) + " " } t . Errorf ( " " , err , actions ) } assertPlanReference ( t , tc . resolvedPlan , instance . Spec . PlanReference ) } ) } }
checks that defaulting succeeds when there are multiple plans but only a
single plan for the specified Service Class
checks that defaulting succeeds when there are multiple plans but only a single plan for the specified Service Class
/* do not use get */ /* do not use get */