Skip to content

Commit

Permalink
fix: validate plugins : allow many versions of the same plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed May 30, 2020
1 parent 9eb8673 commit 3d4ae11
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
10 changes: 5 additions & 5 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ func validatePlugins(plugins ...plugin.Base) error {
pluginName, projectVersion, err)
}
}
// Check for duplicate plugin names. Names outside of a version can
// conflict because multiple project versions of a plugin may exist.
if _, seen := pluginNameSet[pluginName]; seen {
return fmt.Errorf("two plugins have the same name: %q", pluginName)
// Check for duplicate plugin keys.
pluginKey := plugin.KeyFor(p)
if _, seen := pluginNameSet[pluginKey]; seen {
return fmt.Errorf("two plugins have the same key: %q", pluginKey)
}
pluginNameSet[pluginName] = struct{}{}
pluginNameSet[pluginKey] = struct{}{}
}
return nil
}
Expand Down
29 changes: 0 additions & 29 deletions pkg/cli/cli_suite_test.go

This file was deleted.

29 changes: 29 additions & 0 deletions pkg/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ limitations under the License.
package cli

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"sigs.k8s.io/kubebuilder/pkg/plugin"
)

func TestCLI(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "CLI Suite")
}

var _ = Describe("CLI", func() {
Describe("resolvePluginsByKey", func() {
plugins := makePluginsForKeys(
Expand Down Expand Up @@ -78,6 +85,28 @@ var _ = Describe("CLI", func() {
Expect(err).To(MatchError(`plugin key "foo" matches more than one known plugin`))
})
})

Describe("Check if has duplicate plugins", func() {
It("should work successfully when a plugin has many versions", func() {
plugins := makePluginsForKeys(
"foo.example.com/v1.0.0",
"foo.example.com/v2.0.0",
"foo.example.com/v3.0.0",
)

err := validatePlugins(plugins...)
Expect(err).NotTo(HaveOccurred())
})
It("should fail when found more than one plugin with the same name and version", func() {
plugins := makePluginsForKeys(
"foo.example.com/v1.0.0",
"foo.example.com/v1.0.0",
)

err := validatePlugins(plugins...)
Expect(err).To(HaveOccurred())
})
})
})

type mockPlugin struct {
Expand Down

0 comments on commit 3d4ae11

Please sign in to comment.