// checks that defaulting fails when there are multiple plans to choose from.
checks that defaulting fails when there are multiple plans to choose from.
// checks that defaulting fails when there are multiple plans to choose from .
func TestWithNoPlanFailsWithMultiplePlans(t *testing.T) {
	cases := []struct {
		name          string
		requestedPlan servicecatalog.PlanReference
		namespaced    bool
	}{
		{"cluster external name", servicecatalog.PlanReference{ClusterServiceClassExternalName: "foo"}, false},
		{"cluster external id", servicecatalog.PlanReference{ClusterServiceClassExternalID: "foo"}, false},
		{"cluster k8s", servicecatalog.PlanReference{ClusterServiceClassName: "foo-id"}, false},
		{"ns external name", servicecatalog.PlanReference{ServiceClassExternalName: "foo"}, true},
		{"ns external id", servicecatalog.PlanReference{ServiceClassExternalID: "foo"}, true},
		{"ns k8s", servicecatalog.PlanReference{ServiceClassName: "foo-id"}, true},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			var fakeClient *fake.Clientset
			if tc.namespaced {
				sc := newServiceClass("foo-id", "foo")
				sps := newServicePlans(2, false)
				glog.V(4).Infof("Created Service as %+v", sc)
				fakeClient = newFakeServiceCatalogClientForNamespacedTest(sc, sps, "" )
			} else {
				csc := newClusterServiceClass("foo-id", "foo")
				csps := newClusterServicePlans(2, false)
				glog.V(4).Infof("Created Service as %+v", csc)
				fakeClient = newFakeServiceCatalogClientForTest(csc, csps, "" )
			}
			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 {
				t.Errorf("unexpected success with no plan specified and no serviceclass existing")
				return
			} else if !strings.Contains(err.Error(), "has more than one plan, PlanName must be") {
				t.Errorf("did not find expected error, got %q", err)
			}
		})
	}
}
func TestWithNoPlanFailsWithMultiplePlans ( t * testing . T ) { cases := [ ] struct { name string requestedPlan servicecatalog . PlanReference namespaced bool } { { " " , servicecatalog . PlanReference { ClusterServiceClassExternalName : " " } , false } , { " " , servicecatalog . PlanReference { ClusterServiceClassExternalID : " " } , false } , { " " , servicecatalog . PlanReference { ClusterServiceClassName : " " } , false } , { " " , servicecatalog . PlanReference { ServiceClassExternalName : " " } , true } , { " " , servicecatalog . PlanReference { ServiceClassExternalID : " " } , true } , { " " , servicecatalog . PlanReference { ServiceClassName : " " } , true } , } for _ , tc := range cases { t . Run ( tc . name , func ( t * testing . T ) { var fakeClient * fake . Clientset if tc . namespaced { sc := newServiceClass ( " " , " " ) sps := newServicePlans ( 2 , false ) glog . V ( 4 ) . Infof ( " " , sc ) fakeClient = newFakeServiceCatalogClientForNamespacedTest ( sc , sps , " " ) } else { csc := newClusterServiceClass ( " " , " " ) csps := newClusterServicePlans ( 2 , false ) glog . V ( 4 ) . Infof ( " " , csc ) fakeClient = newFakeServiceCatalogClientForTest ( csc , csps , " " ) } 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 { t . Errorf ( " " ) return } else if ! strings . Contains ( err . Error ( ) , " " ) { t . Errorf ( " " , err ) } } ) } }
checks that defaulting fails when there are multiple plans to choose from.
checks that defaulting fails when there are multiple plans to choose from .
/* do not use get */ /* do not use get */