sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/cli/suite_test.go (about)

     1  /*
     2  Copyright 2020 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 cli
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	"sigs.k8s.io/kubebuilder/v3/pkg/config"
    26  	"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
    27  )
    28  
    29  func TestCLI(t *testing.T) {
    30  	RegisterFailHandler(Fail)
    31  	RunSpecs(t, "CLI Suite")
    32  }
    33  
    34  // Test plugin types and constructors.
    35  var (
    36  	_ plugin.Plugin = mockPlugin{}
    37  	_ plugin.Plugin = mockDeprecatedPlugin{}
    38  )
    39  
    40  type mockPlugin struct { //nolint:maligned
    41  	name            string
    42  	version         plugin.Version
    43  	projectVersions []config.Version
    44  }
    45  
    46  func newMockPlugin(name, version string, projVers ...config.Version) plugin.Plugin {
    47  	var v plugin.Version
    48  	if err := v.Parse(version); err != nil {
    49  		panic(err)
    50  	}
    51  	return mockPlugin{name, v, projVers}
    52  }
    53  
    54  func (p mockPlugin) Name() string                               { return p.name }
    55  func (p mockPlugin) Version() plugin.Version                    { return p.version }
    56  func (p mockPlugin) SupportedProjectVersions() []config.Version { return p.projectVersions }
    57  
    58  type mockDeprecatedPlugin struct { //nolint:maligned
    59  	mockPlugin
    60  	deprecation string
    61  }
    62  
    63  func newMockDeprecatedPlugin(name, version, deprecation string, projVers ...config.Version) plugin.Plugin {
    64  	return mockDeprecatedPlugin{
    65  		mockPlugin:  newMockPlugin(name, version, projVers...).(mockPlugin),
    66  		deprecation: deprecation,
    67  	}
    68  }
    69  
    70  func (p mockDeprecatedPlugin) DeprecationWarning() string { return p.deprecation }