// TestInstanceUpdate tests that updates to the spec of an Instance.
TestInstanceUpdate tests that updates to the spec of an Instance.
// TestInstanceUpdate tests that updates to the spec of an Instance .
func TestInstanceUpdate(t *testing.T) {
	cases := []struct {
		name                      string
		older                     *servicecatalog.ServiceInstance
		newer                     *servicecatalog.ServiceInstance
		shouldGenerationIncrement bool
		shouldPlanRefClear        bool
	}{
		{
			name:  "no spec change",
			older: getTestInstance(),
			newer: getTestInstance(),
		},
		{
			name: "UpdateRequest increment",
			older: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.UpdateRequests = 1
				return i
			}(),
			newer: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.UpdateRequests = 2
				return i
			}(),
			shouldGenerationIncrement: true,
		},
		{
			name:  "external plan name change",
			older: getTestInstance(),
			newer: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.ClusterServicePlanExternalName = "new-plan"
				return i
			}(),
			shouldGenerationIncrement: true,
			shouldPlanRefClear:        true,
		},
		{
			name: "external plan id change",
			older: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.ClusterServiceClassExternalName = ""
				i.Spec.ClusterServicePlanExternalName = ""
				i.Spec.ClusterServiceClassExternalID = "test-clusterserviceclass"
				i.Spec.ClusterServicePlanExternalID = "test-clusterserviceplan"
				return i
			}(),
			newer: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.ClusterServiceClassExternalName = ""
				i.Spec.ClusterServicePlanExternalName = ""
				i.Spec.ClusterServiceClassExternalID = "test-clusterserviceclass"
				i.Spec.ClusterServicePlanExternalID = "new plan"
				return i
			}(),
			shouldGenerationIncrement: true,
			shouldPlanRefClear:        true,
		},
		{
			name: "k8s plan change",
			older: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.ClusterServiceClassExternalName = ""
				i.Spec.ClusterServicePlanExternalName = ""
				i.Spec.ClusterServiceClassName = "test-clusterserviceclass"
				i.Spec.ClusterServicePlanName = "test-clusterserviceplan"
				return i
			}(),
			newer: func() *servicecatalog.ServiceInstance {
				i := getTestInstance()
				i.Spec.ClusterServiceClassExternalName = ""
				i.Spec.ClusterServicePlanExternalName = ""
				i.Spec.ClusterServiceClassName = "test-clusterserviceclass"
				i.Spec.ClusterServicePlanName = "new plan"
				return i
			}(),
			shouldGenerationIncrement: true,
			shouldPlanRefClear:        true,
		},
	}
	creatorUserName := "creator"
	createContext := sctestutil.ContextWithUserName(creatorUserName)
	for _, tc := range cases {
		instanceRESTStrategies.PrepareForUpdate(createContext, tc.newer, tc.older)
		expectedGeneration := tc.older.Generation
		if tc.shouldGenerationIncrement {
			expectedGeneration = expectedGeneration + 1
		}
		if e, a := expectedGeneration, tc.newer.Generation; e != a {
			t.Errorf("%v: expected %v, got %v for generation", tc.name, e, a)
			continue
		}
		if tc.shouldPlanRefClear {
			if tc.newer.Spec.ClusterServicePlanRef != nil {
				t.Errorf("%v: expected ServicePlanRef to be nil", tc.name)
			}
		} else {
			if tc.newer.Spec.ClusterServicePlanRef == nil {
				t.Errorf("%v: expected ServicePlanRef to not be nil", tc.name)
			}
		}
	}
}
func TestInstanceUpdate ( t * testing . T ) { cases := [ ] struct { name string older * servicecatalog . ServiceInstance newer * servicecatalog . ServiceInstance shouldGenerationIncrement bool shouldPlanRefClear bool } { { name : " " , older : getTestInstance ( ) , newer : getTestInstance ( ) , } , { name : " " , older : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . UpdateRequests = 1 return i } ( ) , newer : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . UpdateRequests = 2 return i } ( ) , shouldGenerationIncrement : true , } , { name : " " , older : getTestInstance ( ) , newer : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . ClusterServicePlanExternalName = " " return i } ( ) , shouldGenerationIncrement : true , shouldPlanRefClear : true , } , { name : " " , older : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . ClusterServiceClassExternalName = " " i . Spec . ClusterServicePlanExternalName = " " i . Spec . ClusterServiceClassExternalID = " " i . Spec . ClusterServicePlanExternalID = " " return i } ( ) , newer : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . ClusterServiceClassExternalName = " " i . Spec . ClusterServicePlanExternalName = " " i . Spec . ClusterServiceClassExternalID = " " i . Spec . ClusterServicePlanExternalID = " " return i } ( ) , shouldGenerationIncrement : true , shouldPlanRefClear : true , } , { name : " " , older : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . ClusterServiceClassExternalName = " " i . Spec . ClusterServicePlanExternalName = " " i . Spec . ClusterServiceClassName = " " i . Spec . ClusterServicePlanName = " " return i } ( ) , newer : func ( ) * servicecatalog . ServiceInstance { i := getTestInstance ( ) i . Spec . ClusterServiceClassExternalName = " " i . Spec . ClusterServicePlanExternalName = " " i . Spec . ClusterServiceClassName = " " i . Spec . ClusterServicePlanName = " " return i } ( ) , shouldGenerationIncrement : true , shouldPlanRefClear : true , } , } creatorUserName := " " createContext := sctestutil . ContextWithUserName ( creatorUserName ) for _ , tc := range cases { instanceRESTStrategies . PrepareForUpdate ( createContext , tc . newer , tc . older ) expectedGeneration := tc . older . Generation if tc . shouldGenerationIncrement { expectedGeneration = expectedGeneration + 1 } if e , a := expectedGeneration , tc . newer . Generation ; e != a { t . Errorf ( " " , tc . name , e , a ) continue } if tc . shouldPlanRefClear { if tc . newer . Spec . ClusterServicePlanRef != nil { t . Errorf ( " " , tc . name ) } } else { if tc . newer . Spec . ClusterServicePlanRef == nil { t . Errorf ( " " , tc . name ) } } } }
TestInstanceUpdate tests that updates to the spec of an Instance.
TestInstanceUpdate tests that updates to the spec of an Instance .