Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Dec 22, 2024
1 parent c880718 commit a1a91fa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
8 changes: 4 additions & 4 deletions cmd/config_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ func Test_configInitCmd(t *testing.T) {
output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was created successfully.", globalTestConfigFile),
fmt.Sprintf("Config file '%s' was created successfully.", App.GlobalConfigFile),
output,
"configInitCmd should print the correct output")
// Check that the config file was created.
assert.FileExists(t, globalTestConfigFile, "configInitCmd should create a config file")
assert.FileExists(t, App.GlobalConfigFile, "configInitCmd should create a config file")

// Test configInitCmd with the --force flag to overwrite the config file.
output, err = executeCommandC(rootCmd, "config", "init", "--force", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was overwritten successfully.", globalTestConfigFile),
fmt.Sprintf("Config file '%s' was overwritten successfully.", App.GlobalConfigFile),
output,
"configInitCmd should print the correct output")

// Clean up.
err = os.Remove(globalTestConfigFile)
err = os.Remove(App.GlobalConfigFile)
assert.Nil(t, err)
}
6 changes: 3 additions & 3 deletions cmd/config_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func Test_configLintCmd(t *testing.T) {
output, err := executeCommandC(rootCmd, "config", "init", "-c", globalTestConfigFile)
require.NoError(t, err, "configInitCmd should not return an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was created successfully.", globalTestConfigFile),
fmt.Sprintf("Config file '%s' was created successfully.", App.GlobalConfigFile),
output,
"configInitCmd should print the correct output")
// Check that the config file was created.
assert.FileExists(t, globalTestConfigFile, "configInitCmd should create a config file")
assert.FileExists(t, App.GlobalConfigFile, "configInitCmd should create a config file")

// Test configLintCmd.
output, err = executeCommandC(rootCmd, "config", "lint", "-c", globalTestConfigFile)
Expand All @@ -30,6 +30,6 @@ func Test_configLintCmd(t *testing.T) {
"configLintCmd should print the correct output")

// Clean up.
err = os.Remove(globalTestConfigFile)
err = os.Remove(App.GlobalConfigFile)
assert.Nil(t, err)
}
7 changes: 4 additions & 3 deletions cmd/plugin_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ func Test_pluginInitCmd(t *testing.T) {
output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile)
require.NoError(t, err, "plugin init command should not have returned an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile),
fmt.Sprintf("Config file '%s' was created successfully.", App.PluginConfigFile),
output,
"plugin init command should have returned the correct output")
assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file")
assert.FileExists(
t, App.PluginConfigFile, "plugin init command should have created a config file")

// Clean up.
err = os.Remove(pluginTestConfigFile)
err = os.Remove(App.PluginConfigFile)
assert.Nil(t, err)
}
18 changes: 10 additions & 8 deletions cmd/plugin_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func Test_pluginInstallCmd(t *testing.T) {
output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile)
require.NoError(t, err, "plugin init should not return an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile),
fmt.Sprintf("Config file '%s' was created successfully.", App.PluginConfigFile),
output,
"plugin init command should have returned the correct output")
assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file")
assert.FileExists(
t, App.PluginConfigFile, "plugin init command should have created a config file")

// Pull the plugin archive and install it.
pluginArchivePath, err = mustPullPlugin()
Expand All @@ -41,7 +42,7 @@ func Test_pluginInstallCmd(t *testing.T) {

// Clean up.
assert.FileExists(t, "plugins/gatewayd-plugin-cache")
assert.FileExists(t, pluginTestConfigFile+BackupFileExt)
assert.FileExists(t, App.PluginConfigFile+BackupFileExt)
assert.NoFileExists(t, "gatewayd-plugin-cache-linux-amd64-v0.2.4.tar.gz")
assert.NoFileExists(t, "checksums.txt")
assert.NoFileExists(t, "plugins/LICENSE")
Expand All @@ -50,8 +51,8 @@ func Test_pluginInstallCmd(t *testing.T) {
assert.NoFileExists(t, "plugins/gatewayd_plugin.yaml")

require.NoError(t, os.RemoveAll("plugins/"))
require.NoError(t, os.Remove(pluginTestConfigFile))
require.NoError(t, os.Remove(pluginTestConfigFile+BackupFileExt))
require.NoError(t, os.Remove(App.PluginConfigFile))
require.NoError(t, os.Remove(App.PluginConfigFile+BackupFileExt))
}

func Test_pluginInstallCmdAutomatedNoOverwrite(t *testing.T) {
Expand All @@ -65,7 +66,8 @@ func Test_pluginInstallCmdAutomatedNoOverwrite(t *testing.T) {
rootCmd, "plugin", "install",
"-p", pluginTestConfigFile, "--update", "--backup", "--overwrite-config=false")
require.NoError(t, err, "plugin install should not return an error")
assert.Contains(t, output, fmt.Sprintf("/gatewayd-plugin-cache-%s-%s-", runtime.GOOS, runtime.GOARCH))
assert.Contains(
t, output, fmt.Sprintf("/gatewayd-plugin-cache-%s-%s-", runtime.GOOS, runtime.GOARCH))
assert.Contains(t, output, "/checksums.txt")
assert.Contains(t, output, "Download completed successfully")
assert.Contains(t, output, "Checksum verification passed")
Expand All @@ -79,12 +81,12 @@ func Test_pluginInstallCmdAutomatedNoOverwrite(t *testing.T) {

// Clean up.
assert.FileExists(t, "plugins/gatewayd-plugin-cache")
assert.FileExists(t, pluginTestConfigFile+BackupFileExt)
assert.FileExists(t, App.PluginConfigFile+BackupFileExt)
assert.NoFileExists(t, "plugins/LICENSE")
assert.NoFileExists(t, "plugins/README.md")
assert.NoFileExists(t, "plugins/checksum.txt")
assert.NoFileExists(t, "plugins/gatewayd_plugin.yaml")

require.NoError(t, os.RemoveAll("plugins/"))
require.NoError(t, os.Remove(pluginTestConfigFile+BackupFileExt))
require.NoError(t, os.Remove(App.PluginConfigFile+BackupFileExt))
}
6 changes: 3 additions & 3 deletions cmd/plugin_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func Test_pluginListCmd(t *testing.T) {
output, err := executeCommandC(rootCmd, "plugin", "init", "-p", pluginTestConfigFile)
require.NoError(t, err, "plugin init command should not have returned an error")
assert.Equal(t,
fmt.Sprintf("Config file '%s' was created successfully.", pluginTestConfigFile),
fmt.Sprintf("Config file '%s' was created successfully.", App.PluginConfigFile),
output,
"plugin init command should have returned the correct output")
assert.FileExists(t, pluginTestConfigFile, "plugin init command should have created a config file")
assert.FileExists(t, App.PluginConfigFile, "plugin init command should have created a config file")

output, err = executeCommandC(rootCmd, "plugin", "list", "-p", pluginTestConfigFile)
require.NoError(t, err, "plugin list command should not have returned an error")
Expand All @@ -28,7 +28,7 @@ func Test_pluginListCmd(t *testing.T) {
"plugin list command should have returned empty output")

// Clean up.
err = os.Remove(pluginTestConfigFile)
err = os.Remove(App.PluginConfigFile)
assert.Nil(t, err)
}

Expand Down

0 comments on commit a1a91fa

Please sign in to comment.