-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for plugin install command from GitHub
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected]", "-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)) | ||
} |