sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/config/store/errors_test.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package store
    18  
    19  import (
    20  	"fmt"
    21  	"testing"
    22  
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  )
    26  
    27  func TestConfigStore(t *testing.T) {
    28  	RegisterFailHandler(Fail)
    29  	RunSpecs(t, "Config Store Suite")
    30  }
    31  
    32  var _ = Describe("LoadError", func() {
    33  	var (
    34  		wrapped = fmt.Errorf("error message")
    35  		err     = LoadError{Err: wrapped}
    36  	)
    37  
    38  	Context("Error", func() {
    39  		It("should return the correct error message", func() {
    40  			Expect(err.Error()).To(Equal(fmt.Sprintf("unable to load the configuration: %v", wrapped)))
    41  		})
    42  	})
    43  
    44  	Context("Unwrap", func() {
    45  		It("should unwrap to the wrapped error", func() {
    46  			Expect(err.Unwrap()).To(Equal(wrapped))
    47  		})
    48  	})
    49  })
    50  
    51  var _ = Describe("SaveError", func() {
    52  	var (
    53  		wrapped = fmt.Errorf("error message")
    54  		err     = SaveError{Err: wrapped}
    55  	)
    56  
    57  	Context("Error", func() {
    58  		It("should return the correct error message", func() {
    59  			Expect(err.Error()).To(Equal(fmt.Sprintf("unable to save the configuration: %v", wrapped)))
    60  		})
    61  	})
    62  
    63  	Context("Unwrap", func() {
    64  		It("should unwrap to the wrapped error", func() {
    65  			Expect(err.Unwrap()).To(Equal(wrapped))
    66  		})
    67  	})
    68  })