plugin/discovery: handle the -Xn suffix used by auto-installed plugins

This is used to mark the plugin protocol version. Currently we actually
just ignore this entirely, since only one protocol version exists anyway.
Later we will need to add checks here to ensure that we only pay attention
to plugins of the right version.
This commit is contained in:
Martin Atkins 2017-05-24 17:29:10 -07:00
parent 6ba6508ec9
commit 04bcece59c
2 changed files with 14 additions and 0 deletions

View File

@ -147,6 +147,12 @@ func ResolvePluginPaths(paths []string) PluginMetaSet {
version = parts[1]
}
// Auto-installed plugins contain an extra name portion representing
// the expected plugin version, which we must trim off.
if dashX := strings.Index(version, "-X"); dashX != -1 {
version = version[:dashX]
}
if _, ok := found[nameVersion{name, version}]; ok {
// Skip duplicate versions of the same plugin
// (We do this during this step because after this we will be

View File

@ -53,6 +53,7 @@ func TestResolvePluginPaths(t *testing.T) {
"/example/mockos_mockarch/terraform-foo-bar-V0.0.1",
"/example/mockos_mockarch/terraform-foo-baz-V0.0.1",
"/example/mockos_mockarch/terraform-foo-baz-V1.0.0",
"/example/mockos_mockarch/terraform-foo-baz-V2.0.0-X4",
"/example/terraform-foo-bar",
"/example/mockos_mockarch/terraform-foo-bar-Vbananas",
"/example/mockos_mockarch/terraform-foo-bar-V",
@ -75,6 +76,11 @@ func TestResolvePluginPaths(t *testing.T) {
Version: "1.0.0",
Path: "/example/mockos_mockarch/terraform-foo-baz-V1.0.0",
},
{
Name: "baz",
Version: "2.0.0",
Path: "/example/mockos_mockarch/terraform-foo-baz-V2.0.0-X4",
},
{
Name: "bar",
Version: "0.0.0",
@ -92,6 +98,8 @@ func TestResolvePluginPaths(t *testing.T) {
},
}
t.Logf("got %#v", got)
if got, want := got.Count(), len(want); got != want {
t.Errorf("got %d items; want %d", got, want)
}