udpate to plugin name convention
Names are case-insensitive, using lowercase by default.
This commit is contained in:
parent
1b201e67ea
commit
840978b2d5
|
@ -79,7 +79,7 @@ func findPluginPaths(kind string, machineName string, dirs []string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New-style paths must have a version segment in filename
|
// New-style paths must have a version segment in filename
|
||||||
if !strings.Contains(fullName, "-V") {
|
if !strings.Contains(strings.ToLower(fullName), "_v") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +131,12 @@ func ResolvePluginPaths(paths []string) PluginMetaSet {
|
||||||
found := make(map[nameVersion]struct{})
|
found := make(map[nameVersion]struct{})
|
||||||
|
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
baseName := filepath.Base(path)
|
baseName := strings.ToLower(filepath.Base(path))
|
||||||
if !strings.HasPrefix(baseName, "terraform-") {
|
if !strings.HasPrefix(baseName, "terraform-") {
|
||||||
// Should never happen with reasonable input
|
// Should never happen with reasonable input
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
baseName = baseName[10:]
|
baseName = baseName[10:]
|
||||||
firstDash := strings.Index(baseName, "-")
|
firstDash := strings.Index(baseName, "-")
|
||||||
if firstDash == -1 {
|
if firstDash == -1 {
|
||||||
|
@ -149,7 +150,7 @@ func ResolvePluginPaths(paths []string) PluginMetaSet {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.SplitN(baseName, "-V", 2)
|
parts := strings.SplitN(baseName, "_v", 2)
|
||||||
name := parts[0]
|
name := parts[0]
|
||||||
version := "0.0.0"
|
version := "0.0.0"
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
|
@ -158,8 +159,8 @@ func ResolvePluginPaths(paths []string) PluginMetaSet {
|
||||||
|
|
||||||
// Auto-installed plugins contain an extra name portion representing
|
// Auto-installed plugins contain an extra name portion representing
|
||||||
// the expected plugin version, which we must trim off.
|
// the expected plugin version, which we must trim off.
|
||||||
if dashX := strings.Index(version, "-X"); dashX != -1 {
|
if underX := strings.Index(version, "_x"); underX != -1 {
|
||||||
version = version[:dashX]
|
version = version[:underX]
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := found[nameVersion{name, version}]; ok {
|
if _, ok := found[nameVersion{name, version}]; ok {
|
||||||
|
|
|
@ -19,8 +19,8 @@ func TestFindPluginPaths(t *testing.T) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
want := []string{
|
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_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_v1.0.0"),
|
||||||
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-bar"),
|
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-bar"),
|
||||||
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"),
|
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-baz"),
|
||||||
}
|
}
|
||||||
|
@ -50,36 +50,42 @@ func TestFindPluginPaths(t *testing.T) {
|
||||||
|
|
||||||
func TestResolvePluginPaths(t *testing.T) {
|
func TestResolvePluginPaths(t *testing.T) {
|
||||||
got := ResolvePluginPaths([]string{
|
got := ResolvePluginPaths([]string{
|
||||||
"/example/mockos_mockarch/terraform-foo-bar-V0.0.1",
|
"/example/mockos_mockarch/terraform-foo-bar_v0.0.1",
|
||||||
"/example/mockos_mockarch/terraform-foo-baz-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_v1.0.0",
|
||||||
"/example/mockos_mockarch/terraform-foo-baz-V2.0.0-X4",
|
"/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/terraform-foo-bar",
|
||||||
"/example/mockos_mockarch/terraform-foo-bar-Vbananas",
|
"/example/mockos_mockarch/terraform-foo-bar_vbananas",
|
||||||
"/example/mockos_mockarch/terraform-foo-bar-V",
|
"/example/mockos_mockarch/terraform-foo-bar_v",
|
||||||
"/example2/mockos_mockarch/terraform-foo-bar-V0.0.1",
|
"/example2/mockos_mockarch/terraform-foo-bar_v0.0.1",
|
||||||
})
|
})
|
||||||
|
|
||||||
want := []PluginMeta{
|
want := []PluginMeta{
|
||||||
{
|
{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
Version: "0.0.1",
|
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",
|
Name: "baz",
|
||||||
Version: "0.0.1",
|
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",
|
Name: "baz",
|
||||||
Version: "1.0.0",
|
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",
|
Name: "baz",
|
||||||
Version: "2.0.0",
|
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",
|
Name: "bar",
|
||||||
|
@ -89,16 +95,18 @@ func TestResolvePluginPaths(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
Version: "bananas",
|
Version: "bananas",
|
||||||
Path: "/example/mockos_mockarch/terraform-foo-bar-Vbananas",
|
Path: "/example/mockos_mockarch/terraform-foo-bar_vbananas",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
Version: "",
|
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 {
|
if got, want := got.Count(), len(want); got != want {
|
||||||
t.Errorf("got %d items; want %d", got, want)
|
t.Errorf("got %d items; want %d", got, want)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
func TestMetaSHA256(t *testing.T) {
|
func TestMetaSHA256(t *testing.T) {
|
||||||
m := PluginMeta{
|
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()
|
hash, err := m.SHA256()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue