BuildConfigurablePlugin builds a plugin of type pluginType from the integration/assets/ directory with the given name, version, and commands. Available pluginTypes: configurable_plugin, configurable_plugin_fails_uninstall, test_plugin, test_plugin_fails_metadata, test_plugin_with_command
(pluginType string, name string, version string, pluginCommands []PluginCommand)
| 28 | // Available pluginTypes: configurable_plugin, configurable_plugin_fails_uninstall, test_plugin, |
| 29 | // test_plugin_fails_metadata, test_plugin_with_command_overrides, test_plugin_with_panic. |
| 30 | func BuildConfigurablePlugin(pluginType string, name string, version string, pluginCommands []PluginCommand) string { |
| 31 | commands := []string{} |
| 32 | commandHelps := []string{} |
| 33 | commandAliases := []string{} |
| 34 | for _, command := range pluginCommands { |
| 35 | commands = append(commands, command.Name) |
| 36 | commandAliases = append(commandAliases, command.Alias) |
| 37 | commandHelps = append(commandHelps, command.Help) |
| 38 | } |
| 39 | |
| 40 | pluginPath, err := Build(fmt.Sprintf("code.cloudfoundry.org/cli/v8/integration/assets/%s", pluginType), |
| 41 | "-o", |
| 42 | name, |
| 43 | "-ldflags", |
| 44 | fmt.Sprintf("-X main.pluginName=%s -X main.version=%s -X main.commands=%s -X main.commandHelps=%s -X main.commandAliases=%s", |
| 45 | name, |
| 46 | version, |
| 47 | strings.Join(commands, ","), |
| 48 | strings.Join(commandHelps, ","), |
| 49 | strings.Join(commandAliases, ","))) |
| 50 | Expect(err).ToNot(HaveOccurred()) |
| 51 | |
| 52 | // gexec.Build builds the plugin with the name of the dir in the plugin path (configurable_plugin) |
| 53 | // in case this function is called multiple times, the plugins need to be unique to be installed |
| 54 | |
| 55 | // also remove the .exe that gexec adds on Windows so the filename is always the |
| 56 | // same in tests |
| 57 | uniquePath := fmt.Sprintf("%s.%s", strings.TrimSuffix(pluginPath, ".exe"), name) |
| 58 | err = os.Rename(pluginPath, uniquePath) |
| 59 | Expect(err).ToNot(HaveOccurred()) |
| 60 | |
| 61 | return uniquePath |
| 62 | } |
no test coverage detected