From 840978b2d5b118760289f2770cca4931264bfe6d Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 9 Jun 2017 16:05:15 -0400 Subject: [PATCH] udpate to plugin name convention Names are case-insensitive, using lowercase by default. --- plugin/discovery/find.go | 11 ++--- plugin/discovery/find_test.go | 40 +++++++++++-------- plugin/discovery/meta_test.go | 2 +- ...oo-bar-V0.0.1 => terraform-foo-bar_v0.0.1} | 0 ...oo-bar-V1.0.0 => terraform-foo-bar_v1.0.0} | 0 ...bar-V0.0.1 => terraform-notfoo-bar_v0.0.1} | 0 6 files changed, 31 insertions(+), 22 deletions(-) rename plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/{terraform-foo-bar-V0.0.1 => terraform-foo-bar_v0.0.1} (100%) rename plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/{terraform-foo-bar-V1.0.0 => terraform-foo-bar_v1.0.0} (100%) rename plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/{terraform-notfoo-bar-V0.0.1 => terraform-notfoo-bar_v0.0.1} (100%) diff --git a/plugin/discovery/find.go b/plugin/discovery/find.go index 6b9b8b172..c28a60183 100644 --- a/plugin/discovery/find.go +++ b/plugin/discovery/find.go @@ -79,7 +79,7 @@ func findPluginPaths(kind string, machineName string, dirs []string) []string { } // New-style paths must have a version segment in filename - if !strings.Contains(fullName, "-V") { + if !strings.Contains(strings.ToLower(fullName), "_v") { continue } @@ -131,11 +131,12 @@ func ResolvePluginPaths(paths []string) PluginMetaSet { found := make(map[nameVersion]struct{}) for _, path := range paths { - baseName := filepath.Base(path) + baseName := strings.ToLower(filepath.Base(path)) if !strings.HasPrefix(baseName, "terraform-") { // Should never happen with reasonable input continue } + baseName = baseName[10:] firstDash := strings.Index(baseName, "-") if firstDash == -1 { @@ -149,7 +150,7 @@ func ResolvePluginPaths(paths []string) PluginMetaSet { continue } - parts := strings.SplitN(baseName, "-V", 2) + parts := strings.SplitN(baseName, "_v", 2) name := parts[0] version := "0.0.0" if len(parts) == 2 { @@ -158,8 +159,8 @@ func ResolvePluginPaths(paths []string) PluginMetaSet { // 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 underX := strings.Index(version, "_x"); underX != -1 { + version = version[:underX] } if _, ok := found[nameVersion{name, version}]; ok { diff --git a/plugin/discovery/find_test.go b/plugin/discovery/find_test.go index 887a3ad95..a788882bb 100644 --- a/plugin/discovery/find_test.go +++ b/plugin/discovery/find_test.go @@ -19,8 +19,8 @@ func TestFindPluginPaths(t *testing.T) { }, ) want := []string{ - filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar-V0.0.1"), - filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar-V1.0.0"), + filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar_v0.0.1"), + filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-bar_v1.0.0"), filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-bar"), filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"), } @@ -50,36 +50,42 @@ func TestFindPluginPaths(t *testing.T) { func TestResolvePluginPaths(t *testing.T) { got := ResolvePluginPaths([]string{ - "/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/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/mockos_mockarch/terraform-foo-upper_V2.0.0_X4", "/example/terraform-foo-bar", - "/example/mockos_mockarch/terraform-foo-bar-Vbananas", - "/example/mockos_mockarch/terraform-foo-bar-V", - "/example2/mockos_mockarch/terraform-foo-bar-V0.0.1", + "/example/mockos_mockarch/terraform-foo-bar_vbananas", + "/example/mockos_mockarch/terraform-foo-bar_v", + "/example2/mockos_mockarch/terraform-foo-bar_v0.0.1", }) want := []PluginMeta{ { Name: "bar", Version: "0.0.1", - Path: "/example/mockos_mockarch/terraform-foo-bar-V0.0.1", + Path: "/example/mockos_mockarch/terraform-foo-bar_v0.0.1", }, { Name: "baz", Version: "0.0.1", - Path: "/example/mockos_mockarch/terraform-foo-baz-V0.0.1", + Path: "/example/mockos_mockarch/terraform-foo-baz_v0.0.1", }, { Name: "baz", Version: "1.0.0", - Path: "/example/mockos_mockarch/terraform-foo-baz-V1.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", + Path: "/example/mockos_mockarch/terraform-foo-baz_v2.0.0_x4", + }, + { + Name: "upper", + Version: "2.0.0", + Path: "/example/mockos_mockarch/terraform-foo-upper_V2.0.0_X4", }, { Name: "bar", @@ -89,16 +95,18 @@ func TestResolvePluginPaths(t *testing.T) { { Name: "bar", Version: "bananas", - Path: "/example/mockos_mockarch/terraform-foo-bar-Vbananas", + Path: "/example/mockos_mockarch/terraform-foo-bar_vbananas", }, { Name: "bar", Version: "", - Path: "/example/mockos_mockarch/terraform-foo-bar-V", + Path: "/example/mockos_mockarch/terraform-foo-bar_v", }, } - t.Logf("got %#v", got) + for p := range got { + t.Logf("got %#v", p) + } if got, want := got.Count(), len(want); got != want { t.Errorf("got %d items; want %d", got, want) diff --git a/plugin/discovery/meta_test.go b/plugin/discovery/meta_test.go index 9249d6f44..3efd3ab34 100644 --- a/plugin/discovery/meta_test.go +++ b/plugin/discovery/meta_test.go @@ -7,7 +7,7 @@ import ( func TestMetaSHA256(t *testing.T) { m := PluginMeta{ - Path: "test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar-V0.0.1", + Path: "test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar_v0.0.1", } hash, err := m.SHA256() if err != nil { diff --git a/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar-V0.0.1 b/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar_v0.0.1 similarity index 100% rename from plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar-V0.0.1 rename to plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar_v0.0.1 diff --git a/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar-V1.0.0 b/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar_v1.0.0 similarity index 100% rename from plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar-V1.0.0 rename to plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-foo-bar_v1.0.0 diff --git a/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-notfoo-bar-V0.0.1 b/plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-notfoo-bar_v0.0.1 similarity index 100% rename from plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-notfoo-bar-V0.0.1 rename to plugin/discovery/test-fixtures/current-style-plugins/mockos_mockarch/terraform-notfoo-bar_v0.0.1