Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to return nil value when there was an error #1079

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/reconcile/pipeline/context/service/service.go
Expand Up @@ -3,20 +3,22 @@ package service
import (
"context"
e "errors"

olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/redhat-developer/service-binding-operator/pkg/binding"
"github.com/redhat-developer/service-binding-operator/pkg/binding/registry"
"github.com/redhat-developer/service-binding-operator/pkg/client/kubernetes"
"github.com/redhat-developer/service-binding-operator/pkg/reconcile/pipeline"

"reflect"

"github.com/redhat-developer/service-binding-operator/pkg/util"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"reflect"
)

var _ pipeline.Service = &service{}
Expand Down Expand Up @@ -184,6 +186,9 @@ func (s *service) CustomResourceDefinition() (pipeline.CRD, error) {
s.crdLookup = true
return nil, nil
}
if err != nil {
return nil, err
}
s.crd = &customResourceDefinition{resource: u, client: s.client, ns: s.namespace, serviceGVR: s.groupVersionResource}
return s.crd, err
}
Expand Down
20 changes: 19 additions & 1 deletion pkg/reconcile/pipeline/context/service/service_test.go
Expand Up @@ -2,6 +2,8 @@ package service

import (
"errors"
"strings"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
Expand All @@ -17,7 +19,6 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/dynamic/fake"
"k8s.io/client-go/testing"
"strings"
)

var _ = Describe("Service", func() {
Expand Down Expand Up @@ -90,6 +91,23 @@ var _ = Describe("Service", func() {
Expect(res).To(BeNil())
})

It("should return nil when CrdReader returned error", func() {
client = fake.NewSimpleDynamicClient(runtime.NewScheme())
typeLookup.EXPECT().ResourceForKind(gomock.Any()).Return(&schema.GroupVersionResource{Group: "app", Resource: "deployments", Version: "v1"}, nil)
crdResource := &unstructured.Unstructured{}
crdResource.SetName("crdfoo1")
returnErorr := errors.New("some error")
builer := NewBuilder(typeLookup).WithClient(client).WithCrdReader(func(gvk *schema.GroupVersionResource) (*unstructured.Unstructured, error) {
return crdResource, returnErorr
})
service, err := builer.Build(&unstructured.Unstructured{})
Expect(err).NotTo(HaveOccurred())

res, err := service.CustomResourceDefinition()
Expect(err).Should(MatchError(returnErorr))
Expect(res).To(BeNil())
})

Describe("OwnedResources", func() {
It("should return owned resources", func() {
id := uuid.NewUUID()
Expand Down