Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

service-binding-operator-967 #993

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/reconcile/pipeline/handler/collect/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,15 @@ func collectItems(prefix string, ctx pipeline.Context, service pipeline.Service,
p = ""
}
for _, n := range v.MapKeys() {
collectItems(p, ctx, service, n, v.MapIndex(n).Interface())
if mapVal := v.MapIndex(n).Interface(); mapVal != nil {
collectItems(p, ctx, service, n, mapVal)
} else {
condition := v1alpha1.Conditions().NotCollectionReady().
Msg(fmt.Sprintf("Value for key %v_%v not found", prefix+k.String(), n.String())).
Reason("ValueNotFound").Build()
ctx.SetCondition(condition)
Comment on lines +229 to +232
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from setting the condition, you need to do these as well:

ctx.Error(err)
ctx.StopProcessing()

Also, please extract ValueNotFound into a constant and put around other constant in the same file.

return
}
}
case reflect.Slice:
for i := 0; i < v.Len(); i++ {
Expand Down
68 changes: 68 additions & 0 deletions pkg/reconcile/pipeline/handler/collect/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,74 @@ var _ = Describe("Integration Collect definitions + items", func() {

})

// TODO: spec title should be rephrased: should we have one spec for regression tests?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add these tests cases under others for the existing specs.

var _ = Describe("Issue 943", func() {
var (
mockCtrl *gomock.Controller
)

BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})

AfterEach(func() {
mockCtrl.Finish()
})

type testCase struct {
serviceContent map[string]interface{}
expectedItems []*pipeline.BindingItem
secrets map[string]*unstructured.Unstructured
configMaps map[string]*unstructured.Unstructured
}

It("retrieve binding data",
func() {
tc := testCase{
serviceContent: map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"service.binding/java-maven_port": "path={.status.ports},elementType=sliceOfMaps,sourceKey=name,sourceValue=asdf",
},
},
"status": map[string]interface{}{
"ports": []interface{}{
map[string]interface{}{"name": "foo", "value": "bar"},
},
},
},
}

ctx := mocks.NewMockContext(mockCtrl)
service := mocks.NewMockService(mockCtrl)
serviceResource := &unstructured.Unstructured{Object: tc.serviceContent}

ctx.EXPECT().Services().Return([]pipeline.Service{service}, nil).MinTimes(1)

var bindingDefs []binding.Definition
service.EXPECT().AddBindingDef(gomock.Any()).DoAndReturn(func(bd binding.Definition) { bindingDefs = append(bindingDefs, bd) }).Times(len(serviceResource.GetAnnotations()))
service.EXPECT().BindingDefs().DoAndReturn(func() []binding.Definition { return bindingDefs })
service.EXPECT().Resource().Return(serviceResource).Times(2)

crd := mocks.NewMockCRD(mockCtrl)
crd.EXPECT().Descriptor().Return(nil, nil)
crd.EXPECT().Resource().Return(&unstructured.Unstructured{})
service.EXPECT().CustomResourceDefinition().Return(crd, nil)

// TODO: msg must be rephrased.
ctx.EXPECT().SetCondition(
v1alpha1.Conditions().NotCollectionReady().
Reason("ValueNotFound").
Msg("Value for key java-maven_port_foo not found").
Build())

collect.BindingDefinitions(ctx)
collect.BindingItems(ctx)
},
)

})

type bindingDefMatcher struct {
path []string
}
Expand Down