Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
75a1faf
fix(dashmate): parse string as object
pshenmic Apr 3, 2023
0840754
fix: fix masternodes lists
pshenmic Apr 10, 2023
cf301c6
Merge remote-tracking branch 'origin/v0.24-dev' into v0.24-dev
pshenmic Apr 13, 2023
3f6e9ff
Merge remote-tracking branch 'origin/v0.24-dev' into v0.24-dev
pshenmic Apr 14, 2023
4c2f9e4
Merge branch 'v0.24-dev' into fix/config-set-object
pshenmic Apr 14, 2023
80742bc
feat: always JSON.parse on config set
pshenmic Apr 14, 2023
1f19aa4
feat: check schema for value type
pshenmic Apr 14, 2023
f3286e7
fix(dashmate): add support for definitions
pshenmic Apr 14, 2023
395c2df
chore(dashmate): lint fix
pshenmic Apr 14, 2023
3e4d026
Merge branch 'master' into fix/config-set-object
pshenmic May 19, 2023
0297d73
Merge remote-tracking branch 'origin/master' into fix/config-set-object
pshenmic May 19, 2023
b544a2d
Merge remote-tracking branch 'origin/master' into fix/config-set-object
pshenmic Jun 5, 2023
7a0b237
feat(dashmate): add derefence
pshenmic Jun 5, 2023
9fc2aed
feat(dashmate): add set spec
pshenmic Jun 5, 2023
8a56d20
feat(dashmate): lint fix
pshenmic Jun 5, 2023
09604fe
feat(dashmate): enable
pshenmic Jun 5, 2023
941ee2c
feat(dashmate): commit pnp cjs
pshenmic Jun 5, 2023
610fcbc
feat(dashmate): stringify optionValue
pshenmic Jun 5, 2023
a0e4667
feat(dashmate): remove redundant $ref condition
pshenmic Jun 6, 2023
0645b50
feat(dashmate): replace with getPropertyDefinitionByPath.js
pshenmic Jun 6, 2023
33be452
feat(dashmate): replace with JSON.parse()
pshenmic Jun 6, 2023
7172c68
feat(dashmate): add type mismatch case
pshenmic Jun 6, 2023
035ed89
chore(dashmate): remove unused
pshenmic Jun 6, 2023
9c7ad78
chore(dashmate): fix test desc
pshenmic Jun 6, 2023
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
16 changes: 11 additions & 5 deletions packages/dashmate/src/commands/config/set.js
Comment thread
shumkov marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ class ConfigSetCommand extends ConfigBaseCommand {
flags,
config,
) {
if (optionValue === 'null') {
// eslint-disable-next-line no-param-reassign
optionValue = null;
// check for existence
config.get(optionPath);

let value;

try {
value = JSON.parse(optionValue);
} catch (e) {
value = optionValue;
}

config.set(optionPath, optionValue);
config.set(optionPath, value);

// eslint-disable-next-line no-console
console.log(`${optionPath} set to ${config.get(optionPath)}`);
console.log(`${optionPath} set to ${optionValue}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/dashmate/src/config/errors/InvalidOptionError.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const AbstractError = require('../../errors/AbstractError');

class InvalidOptionPathError extends AbstractError {
class InvalidOptionError extends AbstractError {
/**
* @param {string} path
* @param {*} value
Expand Down Expand Up @@ -37,4 +37,4 @@ class InvalidOptionPathError extends AbstractError {
}
}

module.exports = InvalidOptionPathError;
module.exports = InvalidOptionError;
136 changes: 136 additions & 0 deletions packages/dashmate/test/unit/commands/config/set.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
const ConfigSetCommand = require('../../../../src/commands/config/set');
const Config = require('../../../../src/config/Config');
const baseConfig = require('../../../../configs/system/base');

describe('Config set command', () => {
const flags = {};
let config;

beforeEach(async () => {
config = new Config('config', baseConfig);
});

describe('#platform', () => {
it('should allow setting strings', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'core.docker.image', value: 'fake_image',
}, flags, config);
});

it('should allow setting null', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'description', value: null,
}, flags, config);

expect(config.get('description')).to.equal(null);

await command.runWithDependencies({
option: 'description', value: 'null',
}, flags, config);

expect(config.get('description')).to.equal(null);
});

it('should allow setting numbers', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'platform.drive.abci.validatorSet.llmqType',
value: 107,
}, flags, config);

expect(config.get('platform.drive.abci.validatorSet.llmqType')).to.equal(107);

await command.runWithDependencies({
option: 'platform.drive.abci.validatorSet.llmqType',
value: '107',
}, flags, config);

expect(config.get('platform.drive.abci.validatorSet.llmqType')).to.equal(107);
});

it('should allow setting booleans', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'dashmate.helper.api.enable', value: 'true',
}, flags, config);

expect(config.get('dashmate.helper.api.enable')).to.equal(true);

await command.runWithDependencies({
option: 'dashmate.helper.api.enable', value: true,
}, flags, config);

expect(config.get('dashmate.helper.api.enable')).to.equal(true);
});

it('should allow setting array of values', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'core.rpc.allowIps', value: '["1337", "36484"]',
}, flags, config);

expect(config.get('core.rpc.allowIps')).to.deep.equal(['1337', '36484']);
});

it('should allow replacing part of the json', async () => {
const command = new ConfigSetCommand();

await command.runWithDependencies({
option: 'docker',
value: '{"network":{"subnet":"127.0.0.1/24"}}',
}, flags, config);
});

it('should throw on unknown path', async () => {
const command = new ConfigSetCommand();

// invalid path
try {
await command.runWithDependencies({
option: 'fakePath', value: 'fake',
}, flags, config);

expect.fail('should throw error');
} catch (e) {
expect(e.name).to.equal('InvalidOptionPathError');
}
});

it('should throw if invalid json is passed', async () => {
const command = new ConfigSetCommand();

// invalid json
try {
await command.runWithDependencies({
option: 'core.rpc.allowIps', value: 'fake_image',
}, flags, config);

expect.fail('should throw error');
} catch (e) {
expect(e.name).to.equal('InvalidOptionError');
}
});

it('should throw on type mismatch', async () => {
const command = new ConfigSetCommand();

// invalid json
try {
await command.runWithDependencies({
option: 'dashmate.helper.api.enable', value: 120,
}, flags, config);

expect.fail('should throw error');
} catch (e) {
expect(e.name).to.equal('InvalidOptionError');
}
});
});
});