add method to set multi-plugin version (#10386)

This commit is contained in:
Sylvia Moss 2020-12-14 17:08:38 +01:00 committed by GitHub
parent 4e58987026
commit b7ebcd78db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"sort"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
pluginVersion "github.com/hashicorp/packer/packer-plugin-sdk/version"
"github.com/hashicorp/packer/version"
)
@ -46,6 +47,10 @@ func NewSet() *Set {
}
}
func (i *Set) SetVersion(version *pluginVersion.PluginVersion) {
i.version = version.String()
}
func (i *Set) RegisterBuilder(name string, builder packersdk.Builder) {
if _, found := i.Builders[name]; found {
panic(fmt.Errorf("registering duplicate %s builder", name))

View File

@ -5,6 +5,7 @@ import (
"github.com/google/go-cmp/cmp"
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
pluginVersion "github.com/hashicorp/packer/packer-plugin-sdk/version"
"github.com/hashicorp/packer/version"
)
@ -34,11 +35,13 @@ func TestSet(t *testing.T) {
set.RegisterPostProcessor("example-2", new(MockPostProcessor))
set.RegisterProvisioner("example", new(MockProvisioner))
set.RegisterProvisioner("example-2", new(MockProvisioner))
set.SetVersion(pluginVersion.InitializePluginVersion(
"1.1.1", ""))
outputDesc := set.description()
if diff := cmp.Diff(SetDescription{
Version: version.String(),
Version: "1.1.1",
SDKVersion: version.String(),
Builders: []string{"example", "example-2"},
PostProcessors: []string{"example", "example-2"},