From 9b781a7cf1d0f336658b946ac4198e1689f482e8 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 17 Sep 2023 16:29:09 +0200 Subject: [PATCH] Add test for plugin install command from GitHub --- cmd/plugin_install_test.go | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 cmd/plugin_install_test.go diff --git a/cmd/plugin_install_test.go b/cmd/plugin_install_test.go new file mode 100644 index 00000000..d8e97a63 --- /dev/null +++ b/cmd/plugin_install_test.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_pluginInstallCmd(t *testing.T) { + // Create a test config file. + pluginConfigFile := "./test.yaml" + output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginConfigFile) + assert.NoError(t, err, "plugin init should not return an error") + assert.Equal(t, + fmt.Sprintf("Config file '%s' was created successfully.", pluginConfigFile), + output, + "plugin init command should have returned the correct output") + assert.FileExists(t, pluginConfigFile, "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) + 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") + assert.Contains(t, output, "Checksum verification passed") + assert.Contains(t, output, "Plugin binary extracted to plugins/gatewayd-plugin-cache") + assert.Contains(t, output, "Plugin installed successfully") + + // See if the plugin was actually installed. + output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginConfigFile) + 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)) +}