Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin/discovery: trim off .exe suffix when parsing filenames #15587

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin/discovery/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ func ResolvePluginPaths(paths []string) PluginMetaSet {
continue
}

// Trim the .exe suffix used on Windows before we start wrangling
// the remainder of the path.
if strings.HasSuffix(baseName, ".exe") {
baseName = baseName[:len(baseName)-4]
}

parts := strings.SplitN(baseName, "_v", 2)
name := parts[0]
version := VersionZero
Expand Down
20 changes: 19 additions & 1 deletion plugin/discovery/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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_v1.0.0.exe"),
// un-versioned plugins are still picked up, even in current-style paths
filepath.Join("test-fixtures", "current-style-plugins", "mockos_mockarch", "terraform-foo-missing-version"),
filepath.Join("test-fixtures", "legacy-style-plugins", "terraform-foo-bar"),
Expand Down Expand Up @@ -59,6 +59,9 @@ func TestResolvePluginPaths(t *testing.T) {
"/example/terraform-foo-bar",
"/example/mockos_mockarch/terraform-foo-bar_vbananas",
"/example/mockos_mockarch/terraform-foo-bar_v",
"/example/mockos_mockarch/terraform-foo-windowsthing1_v1.0.0.exe",
"/example/mockos_mockarch/terraform-foo-windowsthing2_v1.0.0_x4.exe",
"/example/mockos_mockarch/terraform-foo-windowsthing3.exe",
"/example2/mockos_mockarch/terraform-foo-bar_v0.0.1",
})

Expand Down Expand Up @@ -103,6 +106,21 @@ func TestResolvePluginPaths(t *testing.T) {
Version: "",
Path: "/example/mockos_mockarch/terraform-foo-bar_v",
},
{
Name: "windowsthing1",
Version: "1.0.0",
Path: "/example/mockos_mockarch/terraform-foo-windowsthing1_v1.0.0.exe",
},
{
Name: "windowsthing2",
Version: "1.0.0",
Path: "/example/mockos_mockarch/terraform-foo-windowsthing2_v1.0.0_x4.exe",
},
{
Name: "windowsthing3",
Version: "0.0.0",
Path: "/example/mockos_mockarch/terraform-foo-windowsthing3.exe",
},
}

for p := range got {
Expand Down