Skip to content

Commit

Permalink
Added requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ddraganovv committed Jan 8, 2025
1 parent 63a2780 commit ae722ab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
26 changes: 26 additions & 0 deletions api/handlers/service_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ var _ = Describe("ServiceBinding", func() {
expectUnprocessableEntityError("Service credential bindings of type 'key' are not supported for user-provided service instances.")
})
})

When("binding to a managed service", func() {
BeforeEach(func() {
serviceInstanceRepo.GetServiceInstanceReturns(repositories.ServiceInstanceRecord{
GUID: "service-instance-guid",
SpaceGUID: "space-guid",
Type: korifiv1alpha1.ManagedType,
}, nil)

serviceBindingRepo.CreateServiceBindingReturns(repositories.ServiceBindingRecord{
GUID: "service-binding-guid",
Type: korifiv1alpha1.CFServiceBindingTypeKey,
}, nil)
})

It("creates a binding", func() {
Expect(serviceBindingRepo.CreateServiceBindingCallCount()).To(Equal(1))
Expect(rr).To(HaveHTTPStatus(http.StatusAccepted))

_, actualAuthInfo, createServiceBindingMessage := serviceBindingRepo.CreateServiceBindingArgsForCall(0)
Expect(actualAuthInfo).To(Equal(authInfo))
Expect(createServiceBindingMessage.ServiceInstanceGUID).To(Equal("service-instance-guid"))
Expect(createServiceBindingMessage.SpaceGUID).To(Equal("space-guid"))
Expect(createServiceBindingMessage.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeKey))
})
})
})

When("creating a service binding of type app", func() {
Expand Down
4 changes: 1 addition & 3 deletions api/payloads/service_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ func (l ServiceBindingList) Validate() error {
}

func (l *ServiceBindingList) ToMessage() repositories.ListServiceBindingsMessage {
message := repositories.ListServiceBindingsMessage{
return repositories.ListServiceBindingsMessage{
ServiceInstanceGUIDs: parse.ArrayParam(l.ServiceInstanceGUIDs),
AppGUIDs: parse.ArrayParam(l.AppGUIDs),
LabelSelector: l.LabelSelector,
PlanGUIDs: parse.ArrayParam(l.PlanGUIDs),
}

return message
}

func (l *ServiceBindingList) SupportedKeys() []string {
Expand Down
4 changes: 3 additions & 1 deletion api/payloads/service_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ var _ = Describe("ServiceBindingList", func() {
Expect(*actualServiceBindingList).To(Equal(expectedServiceBindingList))
},
Entry("type", "type=key", payloads.ServiceBindingList{Type: korifiv1alpha1.CFServiceBindingTypeKey}),
Entry("type", "type=app", payloads.ServiceBindingList{Type: korifiv1alpha1.CFServiceBindingTypeApp}),
Entry("app_guids", "app_guids=app_guid", payloads.ServiceBindingList{AppGUIDs: "app_guid"}),
Entry("service_instance_guids", "service_instance_guids=si_guid", payloads.ServiceBindingList{ServiceInstanceGUIDs: "si_guid"}),
Entry("include", "include=app", payloads.ServiceBindingList{Include: "app"}),
Entry("include", "include=key", payloads.ServiceBindingList{Include: "key"}),
Entry("label_selector=foo", "label_selector=foo", payloads.ServiceBindingList{LabelSelector: "foo"}),
Entry("service_plan_guids=plan-guid", "service_plan_guids=plan-guid", payloads.ServiceBindingList{PlanGUIDs: "plan-guid"}),
)
Expand Down Expand Up @@ -128,7 +130,7 @@ var _ = Describe("ServiceBindingCreate", func() {
Expect(serviceBindingCreate).To(gstruct.PointTo(Equal(createPayload)))
})

When("binding is key and name field is omitted", func() {
When("name field is omitted", func() {
BeforeEach(func() {
createPayload.Name = ""
})
Expand Down
43 changes: 20 additions & 23 deletions api/repositories/service_binding_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ var _ = Describe("ServiceBindingRepo", func() {

It("creates a new CFServiceBinding resource and returns a record", func() {
Expect(createErr).NotTo(HaveOccurred())
Expect(serviceBindingRecord.GUID).NotTo(BeEmpty())
Expect(serviceBindingRecord.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeApp))
Expect(serviceBindingRecord.GUID).To(matchers.BeValidUUID())
Expect(serviceBindingRecord.Name).To(BeNil())
Expand Down Expand Up @@ -550,7 +549,7 @@ var _ = Describe("ServiceBindingRepo", func() {
It("creates a new CFServiceBinding resource and returns a record", func() {
Expect(createErr).NotTo(HaveOccurred())

Expect(serviceBindingRecord.GUID).NotTo(BeEmpty())
Expect(serviceBindingRecord.GUID).To(matchers.BeValidUUID())
Expect(serviceBindingRecord.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeApp))
Expect(*(serviceBindingRecord.Name)).To(Equal(serviceBindingName))
Expect(serviceBindingRecord.AppGUID).To(Equal(appGUID))
Expand All @@ -568,16 +567,22 @@ var _ = Describe("ServiceBindingRepo", func() {
k8sClient.Get(ctx, types.NamespacedName{Name: serviceBindingRecord.GUID, Namespace: space.Name}, serviceBinding),
).To(Succeed())

Expect(serviceBinding.Labels).To(HaveKeyWithValue("servicebinding.io/provisioned-service", "true"))
Expect(serviceBinding.Spec.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeApp))
Expect(*(serviceBinding.Spec.DisplayName)).To(Equal(serviceBindingName))
Expect(serviceBinding.Spec.Service).To(Equal(corev1.ObjectReference{
Kind: "CFServiceInstance",
APIVersion: korifiv1alpha1.SchemeGroupVersion.Identifier(),
Name: cfServiceInstance.Name,
}))
Expect(serviceBinding.Spec.AppRef).To(Equal(corev1.LocalObjectReference{
Name: appGUID,
Expect(*serviceBinding).To(MatchFields(IgnoreExtras, Fields{
"ObjectMeta": MatchFields(IgnoreExtras, Fields{
"Labels": HaveKeyWithValue("servicebinding.io/provisioned-service", "true"),
}),
"Spec": MatchFields(IgnoreExtras, Fields{
"Type": Equal(korifiv1alpha1.CFServiceBindingTypeApp),
"DisplayName": PointTo(Equal(serviceBindingName)),
"Service": Equal(corev1.ObjectReference{
Kind: "CFServiceInstance",
APIVersion: korifiv1alpha1.SchemeGroupVersion.Identifier(),
Name: cfServiceInstance.Name,
}),
"AppRef": Equal(corev1.LocalObjectReference{
Name: appGUID,
}),
}),
}))
})
})
Expand All @@ -600,19 +605,11 @@ var _ = Describe("ServiceBindingRepo", func() {
})

It("creates a key binding", func() {
Expect(createErr).NotTo(HaveOccurred())
Expect(serviceBindingRecord.GUID).NotTo(BeEmpty())
Expect(serviceBindingRecord.AppGUID).To(Equal(""))
Expect(serviceBindingRecord.Type).To(Equal(korifiv1alpha1.CFServiceBindingTypeKey))
Expect(serviceBindingRecord.Relationships()).To(HaveKeyWithValue("app", ""))
Expect(*(serviceBindingRecord.Name)).To(Equal(serviceBindingName))
Expect(serviceBindingRecord.AppGUID).To(Equal(""))
Expect(serviceBindingRecord.ServiceInstanceGUID).To(Equal(cfServiceInstance.Name))
Expect(serviceBindingRecord.SpaceGUID).To(Equal(space.Name))
Expect(serviceBindingRecord.CreatedAt).NotTo(BeZero())
Expect(serviceBindingRecord.UpdatedAt).NotTo(BeNil())
Expect(serviceBindingRecord.Relationships()).To(Equal(map[string]string{
"app": "",
"service_instance": cfServiceInstance.Name,
}))
Expect(createErr).NotTo(HaveOccurred())

serviceBinding := new(korifiv1alpha1.CFServiceBinding)
Expect(
Expand Down

0 comments on commit ae722ab

Please sign in to comment.