diff --git a/cmd/cmd_helpers_test.go b/cmd/cmd_helpers_test.go index e8ed00bc..5e33166a 100644 --- a/cmd/cmd_helpers_test.go +++ b/cmd/cmd_helpers_test.go @@ -6,6 +6,8 @@ import ( "github.com/spf13/cobra" ) +var pluginTestConfigFile = "./test.yaml" + // executeCommandC executes a cobra command and returns the command, output, and error. // Taken from https://github.com/spf13/cobra/blob/0c72800b8dba637092b57a955ecee75949e79a73/command_test.go#L48. func executeCommandC(root *cobra.Command, args ...string) (string, error) { diff --git a/cmd/plugin_init_test.go b/cmd/plugin_init_test.go index b05a077e..9d06df61 100644 --- a/cmd/plugin_init_test.go +++ b/cmd/plugin_init_test.go @@ -10,16 +10,15 @@ import ( func Test_pluginInitCmd(t *testing.T) { // Test plugin init command. - pluginConfigFile := "./test.yaml" - output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginConfigFile) + output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin init command should not have returned an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was created successfully.", pluginConfigFile), + fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile), output, "plugin init command should have returned the correct output") - assert.FileExists(t, pluginConfigFile, "plugin init command should have created a config file") + assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file") // Clean up. - err = os.Remove(pluginConfigFile) + err = os.Remove(pluginTestConfigFile) assert.NoError(t, err) } diff --git a/cmd/plugin_install.go b/cmd/plugin_install.go index 3cc56eb5..9ec7dac4 100644 --- a/cmd/plugin_install.go +++ b/cmd/plugin_install.go @@ -139,7 +139,7 @@ var pluginInstallCmd = &cobra.Command{ }) if downloadURL != "" && releaseID != 0 { cmd.Println("Downloading", downloadURL) - downloadFile(client, account, pluginName, downloadURL, releaseID, pluginFilename) + downloadFile(client, account, pluginName, releaseID, pluginFilename) cmd.Println("Download completed successfully") } else { log.Panic("The plugin file could not be found in the release assets") @@ -151,7 +151,7 @@ var pluginInstallCmd = &cobra.Command{ }) if checksumsFilename != "" && downloadURL != "" && releaseID != 0 { cmd.Println("Downloading", downloadURL) - downloadFile(client, account, pluginName, downloadURL, releaseID, checksumsFilename) + downloadFile(client, account, pluginName, releaseID, checksumsFilename) cmd.Println("Download completed successfully") } else { log.Panic("The checksum file could not be found in the release assets") diff --git a/cmd/plugin_install_test.go b/cmd/plugin_install_test.go index d8e97a63..a54efff0 100644 --- a/cmd/plugin_install_test.go +++ b/cmd/plugin_install_test.go @@ -10,21 +10,19 @@ import ( func Test_pluginInstallCmd(t *testing.T) { // Create a test config file. - pluginConfigFile := "./test.yaml" - output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginConfigFile) + output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin init should not return an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was created successfully.", pluginConfigFile), + fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile), output, "plugin init command should have returned the correct output") - assert.FileExists(t, pluginConfigFile, "plugin init command should have created a config file") + assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file") // Test plugin install command. output, err = executeCommandC( rootCmd, "plugin", "install", - "github.com/gatewayd-io/gatewayd-plugin-cache@v0.2.4", "-p", pluginConfigFile) + "github.com/gatewayd-io/gatewayd-plugin-cache@v0.2.4", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin install should not return an error") - fmt.Println(output) assert.Contains(t, output, "Downloading https://github.com/gatewayd-io/gatewayd-plugin-cache/releases/download/v0.2.4/gatewayd-plugin-cache-linux-amd64-v0.2.4.tar.gz") //nolint:lll assert.Contains(t, output, "Downloading https://github.com/gatewayd-io/gatewayd-plugin-cache/releases/download/v0.2.4/checksums.txt") //nolint:lll assert.Contains(t, output, "Download completed successfully") @@ -33,7 +31,7 @@ func Test_pluginInstallCmd(t *testing.T) { assert.Contains(t, output, "Plugin installed successfully") // See if the plugin was actually installed. - output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginConfigFile) + output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin list should not return an error") assert.Contains(t, output, "Name: gatewayd-plugin-cache") @@ -41,5 +39,5 @@ func Test_pluginInstallCmd(t *testing.T) { assert.NoError(t, os.RemoveAll("plugins/")) assert.NoError(t, os.Remove("checksums.txt")) assert.NoError(t, os.Remove("gatewayd-plugin-cache-linux-amd64-v0.2.4.tar.gz")) - assert.NoError(t, os.Remove(pluginConfigFile)) + assert.NoError(t, os.Remove(pluginTestConfigFile)) } diff --git a/cmd/plugin_lint_test.go b/cmd/plugin_lint_test.go index 88574b23..07dd57cf 100644 --- a/cmd/plugin_lint_test.go +++ b/cmd/plugin_lint_test.go @@ -8,8 +8,7 @@ import ( func Test_pluginLintCmd(t *testing.T) { // Test plugin lint command. - pluginConfigFile := "../gatewayd_plugins.yaml" - output, err := executeCommandC(rootCmd, "plugin", "lint", "-p", pluginConfigFile) + output, err := executeCommandC(rootCmd, "plugin", "lint", "-p", "../gatewayd_plugins.yaml") assert.NoError(t, err, "plugin lint command should not have returned an error") assert.Equal(t, "plugins config is valid\n", diff --git a/cmd/plugin_list_test.go b/cmd/plugin_list_test.go index ea85318d..8b53dc53 100644 --- a/cmd/plugin_list_test.go +++ b/cmd/plugin_list_test.go @@ -10,16 +10,15 @@ import ( func Test_pluginListCmd(t *testing.T) { // Test plugin list command. - pluginConfigFile := "./test.yaml" - output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginConfigFile) + output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin init command should not have returned an error") assert.Equal(t, - fmt.Sprintf("Config file '%s' was created successfully.", pluginConfigFile), + fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile), output, "plugin init command should have returned the correct output") - assert.FileExists(t, pluginConfigFile, "plugin init command should have created a config file") + assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file") - output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginConfigFile) + output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin list command should not have returned an error") assert.Equal(t, "No plugins found\n", @@ -27,15 +26,15 @@ func Test_pluginListCmd(t *testing.T) { "plugin list command should have returned empty output") // Clean up. - err = os.Remove(pluginConfigFile) + err = os.Remove(pluginTestConfigFile) assert.NoError(t, err) } func Test_pluginListCmdWithPlugins(t *testing.T) { // Test plugin list command. // Read the plugin config file from the root directory. - pluginConfigFile := "../gatewayd_plugins.yaml" - output, err := executeCommandC(rootCmd, "plugin", "list", "-p", pluginConfigFile) + pluginTestConfigFile := "../gatewayd_plugins.yaml" + output, err := executeCommandC(rootCmd, "plugin", "list", "-p", pluginTestConfigFile) assert.NoError(t, err, "plugin list command should not have returned an error") assert.Equal(t, `Total plugins: 1 Plugins: diff --git a/cmd/utils.go b/cmd/utils.go index ea4d4598..05e459b8 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -390,8 +390,7 @@ func findAsset(release *github.RepositoryRelease, match func(string) bool) (stri } func downloadFile( - client *github.Client, account, pluginName, downloadURL string, - releaseID int64, filename string, + client *github.Client, account, pluginName string, releaseID int64, filename string, ) { // Download the plugin. readCloser, redirectURL, err := client.Repositories.DownloadReleaseAsset(