From 04bcece59c2929e9c0f0682095bc05363c51fd77 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 24 May 2017 17:29:10 -0700 Subject: [PATCH] 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. --- plugin/discovery/find.go | 6 ++++++ plugin/discovery/find_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/plugin/discovery/find.go b/plugin/discovery/find.go index 923923dcc..e66ef9a84 100644 --- a/plugin/discovery/find.go +++ b/plugin/discovery/find.go @@ -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 diff --git a/plugin/discovery/find_test.go b/plugin/discovery/find_test.go index 97ae8ed2c..887a3ad95 100644 --- a/plugin/discovery/find_test.go +++ b/plugin/discovery/find_test.go @@ -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) }