From 0edadab37217c58796529776b142ed95446843be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pereira?= Date: Mon, 4 Nov 2024 15:07:59 -0600 Subject: [PATCH] Fix linter again v7 (#3287) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix linter with multiple main package inside the same folder * Bump version of golangci-lint used Signed-off-by: João Pereira --- .github/workflows/golangci-lint.yml | 2 +- .gitignore | 6 ++-- Makefile | 4 +-- cf/commands/plugin/install_plugin_test.go | 22 +++++++------- cf/commands/plugin/plugin_suite_test.go | 18 +++++------ cf/commands/plugin/plugins_test.go | 4 +-- cf/commands/plugin/uninstall_plugin_test.go | 7 ++--- .../pluginconfig/plugin_config_test.go | 6 ++-- .../.cf/plugins/config.json | 4 +-- .../plugin-config/.cf/plugins/config.json | 4 +-- .../{ => alias_conflicts}/alias_conflicts.go | 0 .../{ => call_core_cmd}/call_core_cmd.go | 0 .../{ => empty_plugin}/empty_plugin.go | 0 fixtures/plugins/{ => input}/input.go | 0 fixtures/plugins/{ => my_say}/my_say.go | 0 fixtures/plugins/{ => panics}/panics.go | 0 fixtures/plugins/{ => test_1}/test_1.go | 0 fixtures/plugins/{ => test_2}/test_2.go | 0 .../{ => test_with_help}/test_with_help.go | 0 .../{ => test_with_orgs}/test_with_orgs.go | 0 .../test_with_orgs_short_name.go | 0 .../{ => test_with_push}/test_with_push.go | 0 .../test_with_push_short_name.go | 0 integration/helpers/curl.go | 4 +-- integration/helpers/route.go | 4 +-- integration/helpers/version.go | 2 +- integration/v6/isolated/app_command_test.go | 2 +- .../v6/isolated/create_shared_domain_test.go | 6 ++-- integration/v7/isolated/app_command_test.go | 2 +- integration/v7/push/droplet_flag_test.go | 6 ++-- plugin/plugin_examples/README.md | 30 +++++++++---------- .../{ => basic_plugin}/basic_plugin.go | 0 plugin/plugin_examples/{ => echo}/echo.go | 0 .../{ => interactive}/interactive.go | 0 .../multiple_commands.go | 0 plugin/plugin_shim_test.go | 2 +- plugin/plugin_suite_test.go | 2 +- 37 files changed, 67 insertions(+), 70 deletions(-) rename fixtures/plugins/{ => alias_conflicts}/alias_conflicts.go (100%) rename fixtures/plugins/{ => call_core_cmd}/call_core_cmd.go (100%) rename fixtures/plugins/{ => empty_plugin}/empty_plugin.go (100%) rename fixtures/plugins/{ => input}/input.go (100%) rename fixtures/plugins/{ => my_say}/my_say.go (100%) rename fixtures/plugins/{ => panics}/panics.go (100%) rename fixtures/plugins/{ => test_1}/test_1.go (100%) rename fixtures/plugins/{ => test_2}/test_2.go (100%) rename fixtures/plugins/{ => test_with_help}/test_with_help.go (100%) rename fixtures/plugins/{ => test_with_orgs}/test_with_orgs.go (100%) rename fixtures/plugins/{ => test_with_orgs_short_name}/test_with_orgs_short_name.go (100%) rename fixtures/plugins/{ => test_with_push}/test_with_push.go (100%) rename fixtures/plugins/{ => test_with_push_short_name}/test_with_push_short_name.go (100%) rename plugin/plugin_examples/{ => basic_plugin}/basic_plugin.go (100%) rename plugin/plugin_examples/{ => echo}/echo.go (100%) rename plugin/plugin_examples/{ => interactive}/interactive.go (100%) rename plugin/plugin_examples/{ => multiple_commands}/multiple_commands.go (100%) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 88b0b530f53..7cd276f1f8a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -37,7 +37,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.58 + version: v1.61 args: -v --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin format: name: Run go fmt diff --git a/.gitignore b/.gitignore index bdd84341efc..71fae6c6c10 100644 --- a/.gitignore +++ b/.gitignore @@ -57,9 +57,9 @@ tmp/ fixtures/.cf #Compiled Plugins -fixtures/plugins/test_1 -fixtures/plugins/test_2 -fixtures/plugins/empty_plugin +fixtures/plugins/test_1/test_1 +fixtures/plugins/test_2/test_2 +fixtures/plugins/empty_plugin/empty_plugin fixtures/config/plugin-config/.cf/plugins/test_1 fixtures/config/plugin-config/.cf/plugins/test_2 fixtures/config/plugin-config/.cf/plugins/empty_plugin diff --git a/Makefile b/Makefile index 6ed3ce755a0..a62625cdb14 100644 --- a/Makefile +++ b/Makefile @@ -200,13 +200,13 @@ units-plugin: install-test-deps ifeq ($(OS),Windows_NT) units-non-plugin: install-test-deps - @rm -f $(wildcard fixtures/plugins/*.exe) + @rm -f $(wildcard fixtures/plugins/*/*.exe) @ginkgo version CF_HOME=$(CURDIR)/fixtures CF_USERNAME="" CF_PASSWORD="" $(ginkgo_units) \ -skip-package integration,plugin,cf\actors\plugin,cf\commands\plugin,cf\actors\plugin,util\randomword else units-non-plugin: install-test-deps - @rm -f $(wildcard fixtures/plugins/*.exe) + @rm -f $(wildcard fixtures/plugins/*/*.exe) @ginkgo version CF_HOME=$(CURDIR)/fixtures CF_USERNAME="" CF_PASSWORD="" $(ginkgo_units) \ -skip-package integration,plugin,cf/actors/plugin,cf/commands/plugin,cf/actors/plugin,util/randomword diff --git a/cf/commands/plugin/install_plugin_test.go b/cf/commands/plugin/install_plugin_test.go index 5e7e3645e6b..d0913e59874 100644 --- a/cf/commands/plugin/install_plugin_test.go +++ b/cf/commands/plugin/install_plugin_test.go @@ -2,13 +2,11 @@ package plugin_test import ( "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" "path/filepath" "runtime" - "strings" "sync" "code.cloudfoundry.org/cli/cf/actors/pluginrepo/pluginrepofakes" @@ -81,15 +79,15 @@ var _ = Describe("Install", func() { if err != nil { panic(err) } - test_1 = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_1.exe") - test_2 = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_2.exe") + test_1 = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_1", "test_1.exe") + test_2 = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_2", "test_2.exe") test_curDir = filepath.Join("test_1.exe") - test_with_help = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_help.exe") - test_with_orgs = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_orgs.exe") - test_with_orgs_short_name = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_orgs_short_name.exe") - aliasConflicts = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "alias_conflicts.exe") + test_with_help = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_help", "test_with_help.exe") + test_with_orgs = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_orgs", "test_with_orgs.exe") + test_with_orgs_short_name = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "test_with_orgs_short_name", "test_with_orgs_short_name.exe") + aliasConflicts = filepath.Join(dir, "..", "..", "..", "fixtures", "plugins", "alias_conflicts", "alias_conflicts.exe") - homeDir, err = ioutil.TempDir(os.TempDir(), "plugins") + homeDir, err = os.MkdirTemp(os.TempDir(), "plugins") Expect(err).ToNot(HaveOccurred()) pluginDir = filepath.Join(homeDir, ".cf", "plugins") @@ -97,7 +95,7 @@ var _ = Describe("Install", func() { curDir, err = os.Getwd() Expect(err).ToNot(HaveOccurred()) - pluginFile, err = ioutil.TempFile("./", "test_plugin") + pluginFile, err = os.CreateTemp("./", "test_plugin") Expect(err).ToNot(HaveOccurred()) if runtime.GOOS != "windows" { @@ -542,7 +540,7 @@ var _ = Describe("Install", func() { runCommand(filepath.Join(curDir, pluginFile.Name()), "-f") Expect(ui.Outputs()).To(ContainSubstrings( []string{"Installing plugin"}, - []string{"The file ", strings.Trim(pluginFile.Name(), "./"), "already exists"}, + []string{"The file", filepath.Clean(pluginFile.Name()), "already exists"}, []string{"FAILED"}, )) }) @@ -560,7 +558,7 @@ var _ = Describe("Install", func() { curDir, err := os.Getwd() Expect(err).ToNot(HaveOccurred()) - err = os.Chdir("../../../fixtures/plugins") + err = os.Chdir("../../../fixtures/plugins/test_1") Expect(err).ToNot(HaveOccurred()) runCommand(test_curDir, "-f") diff --git a/cf/commands/plugin/plugin_suite_test.go b/cf/commands/plugin/plugin_suite_test.go index c970694347c..b3609ae1eb2 100644 --- a/cf/commands/plugin/plugin_suite_test.go +++ b/cf/commands/plugin/plugin_suite_test.go @@ -21,15 +21,15 @@ func TestPlugin(t *testing.T) { RegisterFailHandler(Fail) - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_with_help") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_with_orgs") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_with_orgs_short_name") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_with_push") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_with_push_short_name") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_1") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "test_2") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "empty_plugin") - pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins"), "alias_conflicts") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_with_help"), "test_with_help") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_with_orgs"), "test_with_orgs") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_with_orgs_short_name"), "test_with_orgs_short_name") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_with_push"), "test_with_push") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_with_push_short_name"), "test_with_push_short_name") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_1"), "test_1") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "test_2"), "test_2") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "empty_plugin"), "empty_plugin") + pluginbuilder.BuildTestBinary(filepath.Join("..", "..", "..", "fixtures", "plugins", "alias_conflicts"), "alias_conflicts") RunSpecs(t, "Plugin Suite") } diff --git a/cf/commands/plugin/plugins_test.go b/cf/commands/plugin/plugins_test.go index 3f9caea8fd0..d9634b02190 100644 --- a/cf/commands/plugin/plugins_test.go +++ b/cf/commands/plugin/plugins_test.go @@ -48,7 +48,7 @@ var _ = Describe("Plugins", func() { It("computes and prints the sha1 checksum of the binary", func() { config.PluginsReturns(map[string]pluginconfig.PluginMetadata{ "Test1": { - Location: "../../../fixtures/plugins/test_1.go", + Location: "../../../fixtures/plugins/test_1/test_1.go", Version: plugin.VersionType{Major: 1, Minor: 2, Build: 3}, Commands: []plugin.Command{ {Name: "test_1_cmd1", HelpText: "help text for test_1_cmd1"}, @@ -157,7 +157,7 @@ var _ = Describe("Plugins", func() { It("does not list the plugin when it provides no available commands", func() { config.PluginsReturns(map[string]pluginconfig.PluginMetadata{ - "EmptyPlugin": {Location: "../../../fixtures/plugins/empty_plugin.exe"}, + "EmptyPlugin": {Location: "../../../fixtures/plugins/empty_plugin/empty_plugin.exe"}, }) runCommand() diff --git a/cf/commands/plugin/uninstall_plugin_test.go b/cf/commands/plugin/uninstall_plugin_test.go index eccf500ad65..2060faa3565 100644 --- a/cf/commands/plugin/uninstall_plugin_test.go +++ b/cf/commands/plugin/uninstall_plugin_test.go @@ -1,7 +1,6 @@ package plugin_test import ( - "io/ioutil" "os" "path/filepath" @@ -41,7 +40,7 @@ var _ = Describe("Uninstall", func() { requirementsFactory = new(requirementsfakes.FakeFactory) var err error - fakePluginRepoDir, err = ioutil.TempDir("", "plugins") + fakePluginRepoDir, err = os.MkdirTemp("", "plugins") Expect(err).ToNot(HaveOccurred()) fixtureDir := filepath.Join("..", "..", "..", "fixtures", "plugins") @@ -50,8 +49,8 @@ var _ = Describe("Uninstall", func() { err = os.MkdirAll(pluginDir, 0700) Expect(err).NotTo(HaveOccurred()) - fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_1.exe"), filepath.Join(pluginDir, "test_1.exe")) - fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_2.exe"), filepath.Join(pluginDir, "test_2.exe")) + fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_1", "test_1.exe"), filepath.Join(pluginDir, "test_1.exe")) + fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_2", "test_2.exe"), filepath.Join(pluginDir, "test_2.exe")) confighelpers.PluginRepoDir = func() string { return fakePluginRepoDir diff --git a/cf/configuration/pluginconfig/plugin_config_test.go b/cf/configuration/pluginconfig/plugin_config_test.go index ffc259781be..2b7c0b84547 100644 --- a/cf/configuration/pluginconfig/plugin_config_test.go +++ b/cf/configuration/pluginconfig/plugin_config_test.go @@ -83,7 +83,7 @@ var _ = Describe("PluginConfig", func() { } metadata = PluginMetadata{ - Location: "../../../fixtures/plugins/test_1.exe", + Location: "../../../fixtures/plugins/test_1/test_1.exe", Commands: commands1, } }) @@ -110,9 +110,9 @@ var _ = Describe("PluginConfig", func() { }) It("returns a list of plugin executables and their location", func() { - Expect(plugins["Test1"].Location).To(Equal("../../../fixtures/plugins/test_1.exe")) + Expect(plugins["Test1"].Location).To(Equal("../../../fixtures/plugins/test_1/test_1.exe")) Expect(plugins["Test1"].Commands).To(Equal(commands1)) - Expect(plugins["Test2"].Location).To(Equal("../../../fixtures/plugins/test_2.exe")) + Expect(plugins["Test2"].Location).To(Equal("../../../fixtures/plugins/test_2/test_2.exe")) Expect(plugins["Test2"].Commands).To(Equal(commands2)) }) }) diff --git a/fixtures/config/help-plugin-test-config/.cf/plugins/config.json b/fixtures/config/help-plugin-test-config/.cf/plugins/config.json index acd96407dca..d37ebc91b07 100644 --- a/fixtures/config/help-plugin-test-config/.cf/plugins/config.json +++ b/fixtures/config/help-plugin-test-config/.cf/plugins/config.json @@ -1,14 +1,14 @@ { "Plugins": { "Test1":{ - "Location":"../../fixtures/plugins/test_1.exe", + "Location":"../../fixtures/plugins/test_1/test_1.exe", "Commands":[ {"Name":"test1_cmd1","Alias":"test1_cmd1_alias","HelpText":"help text for test1 cmd1"}, {"Name":"test1_cmd2","HelpText":"help text for test1 cmd2"} ] }, "Test2":{ - "Location":"../../fixtures/plugins/test_2.exe", + "Location":"../../fixtures/plugins/test_2/test_2.exe", "Commands":[ {"Name":"test2_cmd1","Alias":"tc1","HelpText":"help text for test2 cmd1"}, {"Name":"test2_cmd2","HelpText":"help text for test2 cmd2"}, diff --git a/fixtures/config/plugin-config/.cf/plugins/config.json b/fixtures/config/plugin-config/.cf/plugins/config.json index b039625b481..b4234c8887c 100644 --- a/fixtures/config/plugin-config/.cf/plugins/config.json +++ b/fixtures/config/plugin-config/.cf/plugins/config.json @@ -1,14 +1,14 @@ { "Plugins": { "Test1":{ - "Location":"../../../fixtures/plugins/test_1.exe", + "Location":"../../../fixtures/plugins/test_1/test_1.exe", "Commands":[ {"Name":"test_1_cmd1","HelpText":"help text for test1 cmd1"}, {"Name":"test_1_cmd2","HelpText":"help text for test1 cmd2"} ] }, "Test2":{ - "Location":"../../../fixtures/plugins/test_2.exe", + "Location":"../../../fixtures/plugins/test_2/test_2.exe", "Commands":[ {"Name":"test_2_cmd1","HelpText":"help text for test2 cmd1"}, {"Name":"test_2_cmd2","HelpText":"help text for test2 cmd2"} diff --git a/fixtures/plugins/alias_conflicts.go b/fixtures/plugins/alias_conflicts/alias_conflicts.go similarity index 100% rename from fixtures/plugins/alias_conflicts.go rename to fixtures/plugins/alias_conflicts/alias_conflicts.go diff --git a/fixtures/plugins/call_core_cmd.go b/fixtures/plugins/call_core_cmd/call_core_cmd.go similarity index 100% rename from fixtures/plugins/call_core_cmd.go rename to fixtures/plugins/call_core_cmd/call_core_cmd.go diff --git a/fixtures/plugins/empty_plugin.go b/fixtures/plugins/empty_plugin/empty_plugin.go similarity index 100% rename from fixtures/plugins/empty_plugin.go rename to fixtures/plugins/empty_plugin/empty_plugin.go diff --git a/fixtures/plugins/input.go b/fixtures/plugins/input/input.go similarity index 100% rename from fixtures/plugins/input.go rename to fixtures/plugins/input/input.go diff --git a/fixtures/plugins/my_say.go b/fixtures/plugins/my_say/my_say.go similarity index 100% rename from fixtures/plugins/my_say.go rename to fixtures/plugins/my_say/my_say.go diff --git a/fixtures/plugins/panics.go b/fixtures/plugins/panics/panics.go similarity index 100% rename from fixtures/plugins/panics.go rename to fixtures/plugins/panics/panics.go diff --git a/fixtures/plugins/test_1.go b/fixtures/plugins/test_1/test_1.go similarity index 100% rename from fixtures/plugins/test_1.go rename to fixtures/plugins/test_1/test_1.go diff --git a/fixtures/plugins/test_2.go b/fixtures/plugins/test_2/test_2.go similarity index 100% rename from fixtures/plugins/test_2.go rename to fixtures/plugins/test_2/test_2.go diff --git a/fixtures/plugins/test_with_help.go b/fixtures/plugins/test_with_help/test_with_help.go similarity index 100% rename from fixtures/plugins/test_with_help.go rename to fixtures/plugins/test_with_help/test_with_help.go diff --git a/fixtures/plugins/test_with_orgs.go b/fixtures/plugins/test_with_orgs/test_with_orgs.go similarity index 100% rename from fixtures/plugins/test_with_orgs.go rename to fixtures/plugins/test_with_orgs/test_with_orgs.go diff --git a/fixtures/plugins/test_with_orgs_short_name.go b/fixtures/plugins/test_with_orgs_short_name/test_with_orgs_short_name.go similarity index 100% rename from fixtures/plugins/test_with_orgs_short_name.go rename to fixtures/plugins/test_with_orgs_short_name/test_with_orgs_short_name.go diff --git a/fixtures/plugins/test_with_push.go b/fixtures/plugins/test_with_push/test_with_push.go similarity index 100% rename from fixtures/plugins/test_with_push.go rename to fixtures/plugins/test_with_push/test_with_push.go diff --git a/fixtures/plugins/test_with_push_short_name.go b/fixtures/plugins/test_with_push_short_name/test_with_push_short_name.go similarity index 100% rename from fixtures/plugins/test_with_push_short_name.go rename to fixtures/plugins/test_with_push_short_name/test_with_push_short_name.go diff --git a/integration/helpers/curl.go b/integration/helpers/curl.go index 13a089c8dff..37131bc572a 100644 --- a/integration/helpers/curl.go +++ b/integration/helpers/curl.go @@ -9,10 +9,10 @@ import ( . "github.com/onsi/gomega/gexec" ) -// Curl runs a 'cf curl' command with a URL format string, allowing props to be +// Curlf runs a 'cf curl' command with a URL format string, allowing props to be // interpolated into the URL string with fmt.Sprintf. The JSON response is // unmarshaled into given obj. -func Curl(obj interface{}, url string, props ...interface{}) { +func Curlf(obj interface{}, url string, props ...interface{}) { session := CF("curl", fmt.Sprintf(url, props...)) Eventually(session).Should(Exit(0)) rawJSON := strings.TrimSpace(string(session.Out.Contents())) diff --git a/integration/helpers/route.go b/integration/helpers/route.go index d9ad43c9b12..d4cad8196ae 100644 --- a/integration/helpers/route.go +++ b/integration/helpers/route.go @@ -117,7 +117,7 @@ func (r Route) GUID() string { var domainReceiver struct { Domains []resources.Domain `json:"resources"` } - Curl(&domainReceiver, "/v3/domains?names=%s", r.Domain) + Curlf(&domainReceiver, "/v3/domains?names=%s", r.Domain) Expect(domainReceiver.Domains).To(HaveLen(1)) query := []string{fmt.Sprintf("domain_guids=%s", domainReceiver.Domains[0].GUID)} @@ -138,7 +138,7 @@ func (r Route) GUID() string { var routeReceiver struct { Routes []resources.Route `json:"resources"` } - Curl(&routeReceiver, "/v3/routes?%s", strings.Join(query, "&")) + Curlf(&routeReceiver, "/v3/routes?%s", strings.Join(query, "&")) Expect(routeReceiver.Routes).To(HaveLen(1)) return routeReceiver.Routes[0].GUID diff --git a/integration/helpers/version.go b/integration/helpers/version.go index 485913db015..60f27da4c5d 100644 --- a/integration/helpers/version.go +++ b/integration/helpers/version.go @@ -181,7 +181,7 @@ func SkipIfNoRoutingAPI() { var response struct { RoutingEndpoint string `json:"routing_endpoint"` } - Curl(&response, "/v2/info") + Curlf(&response, "/v2/info") if response.RoutingEndpoint == "" { Skip("Test requires routing endpoint on /v2/info") diff --git a/integration/v6/isolated/app_command_test.go b/integration/v6/isolated/app_command_test.go index fa45ad6791d..0b122fffea2 100644 --- a/integration/v6/isolated/app_command_test.go +++ b/integration/v6/isolated/app_command_test.go @@ -269,7 +269,7 @@ applications: } `json:"resources"` } - helpers.Curl(&AppInfo, "/v3/apps?names=%s", appName) + helpers.Curlf(&AppInfo, "/v3/apps?names=%s", appName) appGUID = AppInfo.Resources[0].GUID }) diff --git a/integration/v6/isolated/create_shared_domain_test.go b/integration/v6/isolated/create_shared_domain_test.go index a6364c8669b..db73884d9bd 100644 --- a/integration/v6/isolated/create_shared_domain_test.go +++ b/integration/v6/isolated/create_shared_domain_test.go @@ -114,7 +114,7 @@ var _ = Describe("create-shared-domain command", func() { } } - helpers.Curl(&sharedDomainResponse, "/v2/shared_domains?q=name:%s", domainName) + helpers.Curlf(&sharedDomainResponse, "/v2/shared_domains?q=name:%s", domainName) Expect(sharedDomainResponse.Resources).To(HaveLen(1)) isInternal := sharedDomainResponse.Resources[0].Entity.Internal Expect(isInternal).To(BeTrue()) @@ -162,13 +162,13 @@ var _ = Describe("create-shared-domain command", func() { } } - helpers.Curl(&sharedDomainResponse, "/v2/shared_domains?q=name:%s", domainName) + helpers.Curlf(&sharedDomainResponse, "/v2/shared_domains?q=name:%s", domainName) Expect(sharedDomainResponse.Resources).To(HaveLen(1)) currentRouterGroupGUID := sharedDomainResponse.Resources[0].Entity.RouterGroupGUID var routerGroupListResponse []struct{ GUID string } - helpers.Curl(&routerGroupListResponse, "/routing/v1/router_groups?name=%s", routerGroupName) + helpers.Curlf(&routerGroupListResponse, "/routing/v1/router_groups?name=%s", routerGroupName) Expect(routerGroupListResponse).To(HaveLen(1)) expectedRouterGroupGUID := routerGroupListResponse[0].GUID Expect(currentRouterGroupGUID).Should(Equal(expectedRouterGroupGUID)) diff --git a/integration/v7/isolated/app_command_test.go b/integration/v7/isolated/app_command_test.go index 66bf2707779..de5add9c078 100644 --- a/integration/v7/isolated/app_command_test.go +++ b/integration/v7/isolated/app_command_test.go @@ -215,7 +215,7 @@ applications: } `json:"resources"` } - helpers.Curl(&AppInfo, "/v3/apps?names=%s", appName) + helpers.Curlf(&AppInfo, "/v3/apps?names=%s", appName) appGUID = AppInfo.Resources[0].GUID }) diff --git a/integration/v7/push/droplet_flag_test.go b/integration/v7/push/droplet_flag_test.go index cf7378bc802..5eb14a49e68 100644 --- a/integration/v7/push/droplet_flag_test.go +++ b/integration/v7/push/droplet_flag_test.go @@ -93,9 +93,9 @@ var _ = Describe("--droplet flag", func() { GUID string `json:"guid"` } - currentDropletEndpoint := fmt.Sprintf("v3/apps/%s/droplets/current", originalAppGUID) + const droppletEndpointFormat = "v3/apps/%s/droplets/current" - helpers.Curl(&routeResponse, currentDropletEndpoint) + helpers.Curlf(&routeResponse, droppletEndpointFormat, originalAppGUID) preUploadDropletGUID := routeResponse.GUID session := helpers.CF(PushCommandName, originalApp, "--droplet", dropletPath, "--no-start") @@ -104,7 +104,7 @@ var _ = Describe("--droplet flag", func() { Eventually(session).Should(Say(`requested state:\s+stopped`)) Eventually(session).Should(Exit(0)) - helpers.Curl(&routeResponse, currentDropletEndpoint) + helpers.Curlf(&routeResponse, droppletEndpointFormat, originalAppGUID) postUploadDropletGUID := routeResponse.GUID Expect(preUploadDropletGUID).To(Not(Equal(postUploadDropletGUID))) diff --git a/plugin/plugin_examples/README.md b/plugin/plugin_examples/README.md index 44a088f8e18..b4cf7ddd939 100644 --- a/plugin/plugin_examples/README.md +++ b/plugin/plugin_examples/README.md @@ -14,15 +14,15 @@ Our current plugin architecture currently requires a review and possible large o # Changes in v6.14.0 - API `AccessToken()` now provides a refreshed o-auth token. -- [Examples](https://github.com/cloudfoundry/cli/tree/master/plugin/plugin_examples#test-driven-development-tdd) on how to use fake `CliConnection` and test RPC server for TDD development. +- [Examples](https://github.com/cloudfoundry/cli/tree/v8/plugin/plugin_examples#test-driven-development-tdd) on how to use fake `CliConnection` and test RPC server for TDD development. - Fix Plugin API file descriptors leakage. - Fix bug where some CLI versions does not respect `PluginMetadata.MinCliVersion`. - The field `PackageUpdatedAt` returned by `GetApp()` API is now populated. -[Complete change log ...](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/CHANGELOG.md) +[Complete change log ...](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/CHANGELOG.md) # Developing a Plugin -[Go here for documentation of the plugin API](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/DOC.md) +[Go here for documentation of the plugin API](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/DOC.md) This README discusses how to develop a cf CLI plugin. For user-focused documentation, see [Using the cf CLI](http://docs.cloudfoundry.org/cf-cli/use-cli-plugins.html). @@ -50,26 +50,26 @@ Here is an illustration of the work flow when a plugin command is being invoked. 1: CLI launches 2 processes, the rpc server and the independent plugin executable

-workflow 1 +workflow 1

2: Plugin establishes a connection to the RPC server, the connection is used to invoke core cli commands.

-workflow 1 +workflow 1

3: When a plugin invokes a cli command, it talks to the rpc server, and the rpc server interacts with cf cli to perform the command. The result is passed back to the plugin through the rpc server.

-workflow 1 +workflow 1

- Plugins that you develop for the cf CLI must conform to a predefined plugin interface that we discuss below. ## Writing a Plugin -[Go here for documentation of the plugin API](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/DOC.md) +[Go here for documentation of the plugin API](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/DOC.md) -To write a plugin for the cf CLI, implement the [predefined plugin interface](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin.go). +To write a plugin for the cf CLI, implement the [predefined plugin interface](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin.go). The interface uses a `Run(...)` method as the main entry point between the CLI and a plugin. This method receives the following arguments: @@ -82,21 +82,21 @@ Plugin names with spaces must be enclosed in quotes when installed and uninstall To initialize a plugin, call `plugin.Start(new(MyPluginStruct))` from within the `main()` method of your plugin. The `plugin.Start(...)` function requires a new reference to the struct that implements the defined interface. -This repo contains a basic plugin example [here](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/basic_plugin.go).
-To see more examples, go [here](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/). +This repo contains a basic plugin example [here](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/basic_plugin/basic_plugin.go).
+To see more examples, go [here](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/). ### Uninstalling A Plugin Uninstall of the plugin needs to be explicitly handled. When a user calls the `cf uninstall-plugin` command, CLI notifies the plugin via a call with `CLI-MESSAGE-UNINSTALL` as the first item in `[]args` from within the plugin's `Run(...)` method. ### Test Driven Development (TDD) An example which was developed using TDD is available: -- `Test RPC server`: an RPC server to be used as a back-end for the plugin. It allows the plugin to be tested as a stand alone binary without replying on CLI as a back-end. [See example](https://github.com/cloudfoundry/cli/tree/master/plugin/plugin_examples/test_rpc_server_example) +- `Test RPC server`: an RPC server to be used as a back-end for the plugin. It allows the plugin to be tested as a stand alone binary without replying on CLI as a back-end. [See example](https://github.com/cloudfoundry/cli/tree/v8/plugin/plugin_examples/test_rpc_server_example) ### Using Command Line Arguments The `Run(...)` method accepts the command line arguments and flags that you define for a plugin. - See the [command line arguments example] (https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/echo.go) included in this repo. + See the [command line arguments example] (https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/echo/echo.go) included in this repo. #### Global Flags There are several global flags that will not be passed to the plugin. These are: @@ -109,15 +109,15 @@ You can invoke CLI commands with `cliConnection.CliCommand([]args)` from within The `cliConnection.CliCommand([]args)` returns the output printed by the command and an error. The output is returned as a slice of strings. The error will be present if the call to the CLI command fails. -See the [test plugin example](https://github.com/cloudfoundry/cli/blob/master/integration/assets/test_plugin/test_plugin.go) included in this repo. +See the [test plugin example](https://github.com/cloudfoundry/cli/blob/v8/integration/assets/test_plugin/test_plugin.go) included in this repo. ### Creating Interactive Plugins -Because a plugin has access to stdin during a call to the `Run(...)` method, you can create interactive plugins. See the [interactive plugin example](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/interactive.go) included in this repo. +Because a plugin has access to stdin during a call to the `Run(...)` method, you can create interactive plugins. See the [interactive plugin example](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/interactive/interactive.go) included in this repo. ### Creating Plugins with multiple commands -A single plugin binary can have more than one command, and each command can have it's own help text defined. For an example of multi-command plugins, see the [multiple commands example](https://github.com/cloudfoundry/cli/blob/master/plugin/plugin_examples/multiple_commands.go) +A single plugin binary can have more than one command, and each command can have it's own help text defined. For an example of multi-command plugins, see the [multiple commands example](https://github.com/cloudfoundry/cli/blob/v8/plugin/plugin_examples/multiple_commands/multiple_commands.go) ### Enforcing a minimum CLI version required for the plugin. diff --git a/plugin/plugin_examples/basic_plugin.go b/plugin/plugin_examples/basic_plugin/basic_plugin.go similarity index 100% rename from plugin/plugin_examples/basic_plugin.go rename to plugin/plugin_examples/basic_plugin/basic_plugin.go diff --git a/plugin/plugin_examples/echo.go b/plugin/plugin_examples/echo/echo.go similarity index 100% rename from plugin/plugin_examples/echo.go rename to plugin/plugin_examples/echo/echo.go diff --git a/plugin/plugin_examples/interactive.go b/plugin/plugin_examples/interactive/interactive.go similarity index 100% rename from plugin/plugin_examples/interactive.go rename to plugin/plugin_examples/interactive/interactive.go diff --git a/plugin/plugin_examples/multiple_commands.go b/plugin/plugin_examples/multiple_commands/multiple_commands.go similarity index 100% rename from plugin/plugin_examples/multiple_commands.go rename to plugin/plugin_examples/multiple_commands/multiple_commands.go diff --git a/plugin/plugin_shim_test.go b/plugin/plugin_shim_test.go index 24b49226655..04604b9570f 100644 --- a/plugin/plugin_shim_test.go +++ b/plugin/plugin_shim_test.go @@ -15,7 +15,7 @@ import ( var _ = Describe("Command", func() { var ( - validPluginPath = filepath.Join("..", "fixtures", "plugins", "test_1.exe") + validPluginPath = filepath.Join("..", "fixtures", "plugins", "test_1", "test_1.exe") ) Describe(".Start", func() { diff --git a/plugin/plugin_suite_test.go b/plugin/plugin_suite_test.go index 8076cb8955e..8c318db9fc4 100644 --- a/plugin/plugin_suite_test.go +++ b/plugin/plugin_suite_test.go @@ -11,6 +11,6 @@ import ( func TestPlugin(t *testing.T) { RegisterFailHandler(Fail) - pluginbuilder.BuildTestBinary(filepath.Join("..", "fixtures", "plugins"), "test_1") + pluginbuilder.BuildTestBinary(filepath.Join("..", "fixtures", "plugins", "test_1"), "test_1") RunSpecs(t, "Plugin Suite") }