@@ -26,6 +26,7 @@ import (
26
26
fakeosb "github.com/pmorie/go-open-service-broker-client/v2/fake"
27
27
28
28
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
29
+ "github.com/kubernetes-incubator/service-catalog/test/fake"
29
30
30
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
32
"k8s.io/apimachinery/pkg/fields"
@@ -1051,3 +1052,102 @@ func TestUpdateServiceBrokerCondition(t *testing.T) {
1051
1052
}
1052
1053
}
1053
1054
}
1055
+
1056
+ func TestReconcileClusterServicePlanFromClusterServiceBrokerCatalog (t * testing.T ) {
1057
+ updatedPlan := func () * v1beta1.ClusterServicePlan {
1058
+ p := getTestClusterServicePlan ()
1059
+ p .Spec .Description = "new-description"
1060
+ p .Spec .ExternalName = "new-value"
1061
+ p .Spec .Free = false
1062
+ p .Spec .ExternalMetadata = & runtime.RawExtension {Raw : []byte (`{"field1": "value1"}` )}
1063
+ p .Spec .ServiceInstanceCreateParameterSchema = & runtime.RawExtension {Raw : []byte (`{"field1": "value1"}` )}
1064
+ p .Spec .ServiceInstanceUpdateParameterSchema = & runtime.RawExtension {Raw : []byte (`{"field1": "value1"}` )}
1065
+ p .Spec .ServiceBindingCreateParameterSchema = & runtime.RawExtension {Raw : []byte (`{"field1": "value1"}` )}
1066
+
1067
+ return p
1068
+ }
1069
+
1070
+ cases := []struct {
1071
+ name string
1072
+ newServicePlan * v1beta1.ClusterServicePlan
1073
+ existingServicePlan * v1beta1.ClusterServicePlan
1074
+ listerServicePlan * v1beta1.ClusterServicePlan
1075
+ shouldError bool
1076
+ errText * string
1077
+ catalogClientPrepFunc func (* fake.Clientset )
1078
+ catalogActionsCheckFunc func (t * testing.T , name string , actions []clientgotesting.Action )
1079
+ }{
1080
+ {
1081
+ name : "new plan" ,
1082
+ newServicePlan : getTestClusterServicePlan (),
1083
+ shouldError : false ,
1084
+ catalogActionsCheckFunc : func (t * testing.T , name string , actions []clientgotesting.Action ) {
1085
+ expectNumberOfActions (t , name , actions , 1 )
1086
+ expectCreate (t , name , actions [0 ], getTestClusterServicePlan ())
1087
+ },
1088
+ },
1089
+ {
1090
+ name : "exists, but for a different broker" ,
1091
+ newServicePlan : getTestClusterServicePlan (),
1092
+ existingServicePlan : getTestClusterServicePlan (),
1093
+ listerServicePlan : func () * v1beta1.ClusterServicePlan {
1094
+ p := getTestClusterServicePlan ()
1095
+ p .Spec .ClusterServiceBrokerName = "something-else"
1096
+ return p
1097
+ }(),
1098
+ shouldError : true ,
1099
+ errText : strPtr (`ClusterServiceBroker "test-broker": ClusterServicePlan "test-plan" already exists for Broker "something-else"` ),
1100
+ },
1101
+ {
1102
+ name : "plan update" ,
1103
+ newServicePlan : updatedPlan (),
1104
+ existingServicePlan : getTestClusterServicePlan (),
1105
+ shouldError : false ,
1106
+ catalogActionsCheckFunc : func (t * testing.T , name string , actions []clientgotesting.Action ) {
1107
+ expectNumberOfActions (t , name , actions , 1 )
1108
+ expectUpdate (t , name , actions [0 ], updatedPlan ())
1109
+ },
1110
+ },
1111
+ {
1112
+ name : "plan update - failure" ,
1113
+ newServicePlan : updatedPlan (),
1114
+ existingServicePlan : getTestClusterServicePlan (),
1115
+ catalogClientPrepFunc : func (client * fake.Clientset ) {
1116
+ client .AddReactor ("update" , "clusterserviceplans" , func (action clientgotesting.Action ) (bool , runtime.Object , error ) {
1117
+ return true , nil , errors .New ("oops" )
1118
+ })
1119
+ },
1120
+ shouldError : true ,
1121
+ errText : strPtr ("oops" ),
1122
+ },
1123
+ }
1124
+
1125
+ broker := getTestClusterServiceBroker ()
1126
+
1127
+ for _ , tc := range cases {
1128
+ _ , fakeCatalogClient , _ , testController , sharedInformers := newTestController (t , noFakeActions ())
1129
+ if tc .catalogClientPrepFunc != nil {
1130
+ tc .catalogClientPrepFunc (fakeCatalogClient )
1131
+ }
1132
+
1133
+ if tc .listerServicePlan != nil {
1134
+ sharedInformers .ClusterServicePlans ().Informer ().GetStore ().Add (tc .listerServicePlan )
1135
+ }
1136
+
1137
+ err := testController .reconcileClusterServicePlanFromClusterServiceBrokerCatalog (broker , tc .newServicePlan , tc .existingServicePlan )
1138
+ if err != nil {
1139
+ if ! tc .shouldError {
1140
+ t .Errorf ("%v: unexpected error from method under test: %v" , tc .name , err )
1141
+ continue
1142
+ } else if tc .errText != nil && * tc .errText != err .Error () {
1143
+ t .Errorf ("%v: unexpected error text from method under test; expected %v, got %v" , tc .name , tc .errText , err .Error ())
1144
+ continue
1145
+ }
1146
+ }
1147
+
1148
+ if tc .catalogActionsCheckFunc != nil {
1149
+ actions := fakeCatalogClient .Actions ()
1150
+ tc .catalogActionsCheckFunc (t , tc .name , actions )
1151
+ }
1152
+ }
1153
+ }
0 commit comments