Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Sep 18, 2023
1 parent 9b781a7 commit 4394807
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 27 deletions.
2 changes: 2 additions & 0 deletions cmd/cmd_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions cmd/plugin_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions cmd/plugin_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
14 changes: 6 additions & 8 deletions cmd/plugin_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]", "-p", pluginConfigFile)
"github.com/gatewayd-io/[email protected]", "-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")
Expand All @@ -33,13 +31,13 @@ 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")

// Clean up.
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))
}
3 changes: 1 addition & 2 deletions cmd/plugin_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 7 additions & 8 deletions cmd/plugin_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,31 @@ 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",
output,
"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:
Expand Down
3 changes: 1 addition & 2 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4394807

Please sign in to comment.