Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Catalog prerequisites #1907

Merged
merged 7 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ frontend-test:
plugins-test:
cd plugins/headlamp-plugin && npm install && ./test-headlamp-plugin.js
cd plugins/headlamp-plugin && ./test-plugins-examples.sh
cd plugins/headlamp-plugin && node ./headlamp-plugin-management.test.js
cd plugins/headlamp-plugin && npx jest ./plugin-management-utils.test.js

# IMAGE_BASE can be used to specify a base final image.
# IMAGE_BASE=debian:latest make image
Expand Down
4 changes: 2 additions & 2 deletions plugins/headlamp-plugin/bin/headlamp-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ function test(packageFolder) {
return runScriptOnPackages(packageFolder, 'test', script, { UNDER_TEST: 'true' });
}

const headlampPluginBin = fs.realpathSync(process.argv[1]);
console.log('headlampPluginBin path:', headlampPluginBin);
// const headlampPluginBin = fs.realpathSync(process.argv[1]);
illume marked this conversation as resolved.
Show resolved Hide resolved
// console.log('headlampPluginBin path:', headlampPluginBin);

yargs(process.argv.slice(2))
.command(
Expand Down
76 changes: 76 additions & 0 deletions plugins/headlamp-plugin/headlamp-plugin-management.test.js
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.');
Loading
Loading