• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 14083115845

26 Mar 2025 12:20PM UTC coverage: 72.977%. Remained the same
14083115845

push

github

web-flow
🌱 (chore): simplify test variable declarations for CLI tests (#4665)

chore: simplify test variable declarations for CLI tests

Replaced redundant multi-line `var` blocks with single-line declarations in
`version_test.go` and `completion_test.go`. This reduces visual noise and aligns
with idiomatic Go style for concise test setup.

2309 of 3164 relevant lines covered (72.98%)

13.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.55
/pkg/plugin/bundle.go
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 plugin
18

19
import (
20
        "fmt"
21

22
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
23
)
24

25
type bundle struct {
26
        name    string
27
        version Version
28
        plugins []Plugin
29

30
        supportedProjectVersions []config.Version
31
        deprecateWarning         string
32
}
33

34
// BundleOption define the options to create the bundle
35
type BundleOption func(*bundle)
36

37
// WithName allow set the name of the Bundle Plugin
38
func WithName(name string) BundleOption {
26✔
39
        return func(opts *bundle) {
52✔
40
                opts.name = name
26✔
41
        }
26✔
42
}
43

44
// WithVersion allow set the version of the Bundle Plugin
45
func WithVersion(version Version) BundleOption {
26✔
46
        return func(opts *bundle) {
52✔
47
                opts.version = version
26✔
48
        }
26✔
49
}
50

51
// WithPlugins allow set the plugins which will be used in the composition for the Bundle Plugin
52
func WithPlugins(plugins ...Plugin) BundleOption {
26✔
53
        return func(opts *bundle) {
52✔
54
                opts.plugins = plugins
26✔
55
        }
26✔
56
}
57

58
// WithDeprecationMessage allow set a deprecate message when needed
59
func WithDeprecationMessage(msg string) BundleOption {
13✔
60
        return func(opts *bundle) {
26✔
61
                opts.deprecateWarning = msg
13✔
62
        }
13✔
63
}
64

65
// NewBundleWithOptions creates a new Bundle with the provided BundleOptions.
66
// The list of supported project versions is computed from the provided plugins in options.
67
func NewBundleWithOptions(opts ...BundleOption) (Bundle, error) {
26✔
68
        bundleOpts := bundle{}
26✔
69

26✔
70
        for _, opts := range opts {
117✔
71
                opts(&bundleOpts)
91✔
72
        }
91✔
73

74
        supportedProjectVersions := CommonSupportedProjectVersions(bundleOpts.plugins...)
26✔
75
        if len(supportedProjectVersions) == 0 {
34✔
76
                return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version")
8✔
77
        }
8✔
78

79
        // Plugins may be bundles themselves, so unbundle here
80
        // NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also
81
        //               including Bundles, and therefore we don't have to use a recursive algorithm when resolving.
82
        allPlugins := make([]Plugin, 0, len(bundleOpts.plugins))
18✔
83
        for _, plugin := range bundleOpts.plugins {
58✔
84
                if pluginBundle, isBundle := plugin.(Bundle); isBundle {
42✔
85
                        allPlugins = append(allPlugins, pluginBundle.Plugins()...)
2✔
86
                } else {
40✔
87
                        allPlugins = append(allPlugins, plugin)
38✔
88
                }
38✔
89
        }
90

91
        return bundle{
18✔
92
                name:                     bundleOpts.name,
18✔
93
                version:                  bundleOpts.version,
18✔
94
                plugins:                  allPlugins,
18✔
95
                supportedProjectVersions: supportedProjectVersions,
18✔
96
                deprecateWarning:         bundleOpts.deprecateWarning,
18✔
97
        }, nil
18✔
98
}
99

100
// Name implements Plugin
101
func (b bundle) Name() string {
14✔
102
        return b.name
14✔
103
}
14✔
104

105
// Version implements Plugin
106
func (b bundle) Version() Version {
14✔
107
        return b.version
14✔
108
}
14✔
109

110
// SupportedProjectVersions implements Plugin
111
func (b bundle) SupportedProjectVersions() []config.Version {
18✔
112
        return b.supportedProjectVersions
18✔
113
}
18✔
114

115
// Plugins implements Bundle
116
func (b bundle) Plugins() []Plugin {
18✔
117
        return b.plugins
18✔
118
}
18✔
119

120
// DeprecationWarning return the warning message
121
func (b bundle) DeprecationWarning() string {
×
122
        return b.deprecateWarning
×
123
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc