sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/config/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 config
    18  
    19  import (
    20  	"fmt"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
    26  )
    27  
    28  var _ = Describe("UnsupportedVersionError", func() {
    29  	err := UnsupportedVersionError{
    30  		Version: Version{Number: 1},
    31  	}
    32  
    33  	Context("Error", func() {
    34  		It("should return the correct error message", func() {
    35  			Expect(err.Error()).To(Equal("version 1 is not supported"))
    36  		})
    37  	})
    38  })
    39  
    40  var _ = Describe("UnsupportedFieldError", func() {
    41  	err := UnsupportedFieldError{
    42  		Version: Version{Number: 1},
    43  		Field:   "name",
    44  	}
    45  
    46  	Context("Error", func() {
    47  		It("should return the correct error message", func() {
    48  			Expect(err.Error()).To(Equal("version 1 does not support the name field"))
    49  		})
    50  	})
    51  })
    52  
    53  var _ = Describe("ResourceNotFoundError", func() {
    54  	err := ResourceNotFoundError{
    55  		GVK: resource.GVK{
    56  			Group:   "group",
    57  			Domain:  "my.domain",
    58  			Version: "v1",
    59  			Kind:    "Kind",
    60  		},
    61  	}
    62  
    63  	Context("Error", func() {
    64  		It("should return the correct error message", func() {
    65  			Expect(err.Error()).To(Equal("resource {group my.domain v1 Kind} could not be found"))
    66  		})
    67  	})
    68  })
    69  
    70  var _ = Describe("PluginKeyNotFoundError", func() {
    71  	err := PluginKeyNotFoundError{
    72  		Key: "go.kubebuilder.io/v1",
    73  	}
    74  
    75  	Context("Error", func() {
    76  		It("should return the correct error message", func() {
    77  			Expect(err.Error()).To(Equal("plugin key \"go.kubebuilder.io/v1\" could not be found"))
    78  		})
    79  	})
    80  })
    81  
    82  var _ = Describe("MarshalError", func() {
    83  	var (
    84  		wrapped = fmt.Errorf("error message")
    85  		err     = MarshalError{Err: wrapped}
    86  	)
    87  
    88  	Context("Error", func() {
    89  		It("should return the correct error message", func() {
    90  			Expect(err.Error()).To(Equal(fmt.Sprintf("error marshalling project configuration: %v", wrapped)))
    91  		})
    92  	})
    93  
    94  	Context("Unwrap", func() {
    95  		It("should unwrap to the wrapped error", func() {
    96  			Expect(err.Unwrap()).To(Equal(wrapped))
    97  		})
    98  	})
    99  })
   100  
   101  var _ = Describe("UnmarshalError", func() {
   102  	var (
   103  		wrapped = fmt.Errorf("error message")
   104  		err     = UnmarshalError{Err: wrapped}
   105  	)
   106  
   107  	Context("Error", func() {
   108  		It("should return the correct error message", func() {
   109  			Expect(err.Error()).To(Equal(fmt.Sprintf("error unmarshalling project configuration: %v", wrapped)))
   110  		})
   111  	})
   112  
   113  	Context("Unwrap", func() {
   114  		It("should unwrap to the wrapped error", func() {
   115  			Expect(err.Unwrap()).To(Equal(wrapped))
   116  		})
   117  	})
   118  })