github.com/IBM-Blockchain/fabric-operator@v1.0.4/pkg/operatorerrors/errors_test.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package operatorerrors_test
    20  
    21  import (
    22  	"errors"
    23  
    24  	. "github.com/onsi/ginkgo/v2"
    25  	. "github.com/onsi/gomega"
    26  
    27  	"github.com/IBM-Blockchain/fabric-operator/pkg/operatorerrors"
    28  	"github.com/go-logr/logr"
    29  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    30  )
    31  
    32  var _ = Describe("operator errors", func() {
    33  	var (
    34  		operatorErr *operatorerrors.OperatorError
    35  		log         logr.Logger
    36  	)
    37  
    38  	BeforeEach(func() {
    39  		operatorErr = operatorerrors.New(operatorerrors.InvalidDeploymentCreateRequest, "operator error occurred")
    40  		log = logf.Log.WithName("test")
    41  	})
    42  
    43  	Context("breaking error", func() {
    44  		It("returns nil if breaking error detected", func() {
    45  			err := operatorerrors.IsBreakingError(operatorErr, "operator error", log)
    46  			Expect(err).NotTo(HaveOccurred())
    47  		})
    48  
    49  		It("returns err if errors is not an operator error", func() {
    50  			err := operatorerrors.IsBreakingError(errors.New("non-operator error"), "not an operator error", log)
    51  			Expect(err).To(HaveOccurred())
    52  		})
    53  	})
    54  })