-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
headlamp-plugin: Add e2e test for plugin management
This patch adds integration test for plugin management commands. Signed-off-by: yolossn <sannagaraj@microsoft.com>
- Loading branch information
Showing
5 changed files
with
177 additions
and
468 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
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
76 changes: 76 additions & 0 deletions
76
plugins/headlamp-plugin/headlamp-plugin-management.test.js
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,76 @@ | ||
const { execSync } = require('child_process'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const envPaths = require('env-paths'); | ||
|
||
// Helper function to run CLI commands and return the output | ||
function runCommand(command) { | ||
try { | ||
return execSync(command, { encoding: 'utf8' }); | ||
} catch (error) { | ||
console.error(`Error running command "${command}":`, error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
// Helper function to get the default plugins directory | ||
function defaultPluginsDir() { | ||
const paths = envPaths('Headlamp', { suffix: '' }); | ||
const configDir = fs.existsSync(paths.data) ? paths.data : paths.config; | ||
return path.join(configDir, 'plugins'); | ||
} | ||
|
||
// create default plugins directory if it doesn't exist | ||
const pluginsDir = defaultPluginsDir(); | ||
if (!fs.existsSync(pluginsDir)) { | ||
fs.mkdirSync(pluginsDir, { recursive: true }); | ||
} | ||
|
||
// List plugins initially | ||
let output = runCommand('node ./bin/headlamp-plugin.js list --json'); | ||
console.log('Initial list output:', output); | ||
let plugins = JSON.parse(output); | ||
console.log('Initial plugins:', plugins); | ||
|
||
// Ensure the plugin is not installed | ||
const pluginName = 'prometheus'; | ||
let pluginExists = plugins.some(plugin => plugin.pluginName === pluginName); | ||
assert.strictEqual(pluginExists, false, 'Plugin should not be initially installed'); | ||
|
||
// Install the plugin | ||
const pluginURL = 'https://artifacthub.io/packages/headlamp/test-123/prometheus_headlamp_plugin'; | ||
output = runCommand(`node ./bin/headlamp-plugin.js install ${pluginURL}`); | ||
console.log('Install output:', output); | ||
|
||
// List plugins to verify installation | ||
output = runCommand('node ./bin/headlamp-plugin.js list --json'); | ||
plugins = JSON.parse(output); | ||
console.log('Plugins after install:', plugins); | ||
pluginExists = plugins.some(plugin => plugin.pluginName === pluginName); | ||
assert.strictEqual(pluginExists, true, 'Plugin should be installed'); | ||
|
||
// Update the plugin | ||
output = runCommand(`node ./bin/headlamp-plugin.js update ${pluginName}`); | ||
console.log('Update output:', output); | ||
|
||
// List plugins to verify update | ||
output = runCommand('node ./bin/headlamp-plugin.js list --json'); | ||
plugins = JSON.parse(output); | ||
console.log('Plugins after update:', plugins); | ||
pluginExists = plugins.some(plugin => plugin.pluginName === pluginName); | ||
assert.strictEqual(pluginExists, true, 'Plugin should still be installed after update'); | ||
|
||
// Uninstall the plugin | ||
output = runCommand(`node ./bin/headlamp-plugin.js uninstall ${pluginName}`); | ||
console.log('Uninstall output:', output); | ||
|
||
// List plugins to verify uninstallation | ||
output = runCommand('node ./bin/headlamp-plugin.js list --json'); | ||
console.log('Initial list output:', output); | ||
plugins = JSON.parse(output); | ||
console.log('Plugins after uninstall:', plugins); | ||
pluginExists = plugins.some(plugin => plugin.pluginName === pluginName); | ||
assert.strictEqual(pluginExists, false, 'Plugin should be uninstalled'); | ||
|
||
console.log('All tests passed successfully.'); |
Oops, something went wrong.