Skip to content

Commit

Permalink
syncing up to 4680bf95ab3ef649b97218b652908298682e0bdd
Browse files Browse the repository at this point in the history
Co-authored-by: Joey Greco <[email protected]>
  • Loading branch information
superblocksadmin and joeyagreco committed Dec 19, 2024
1 parent 07e382f commit a77b0b0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added support for creating a worksheet in GSheets integration
- Refactor `launchdarkly` client to separate wrapper around LaunchDarkly SDK into its own package separate from the interface for agent specific flags
- Fixed bug in Redis integration that caused some raw Redis queries to error unexpectedly

## v1.17.0

Expand Down
38 changes: 37 additions & 1 deletion workers/javascript/packages/plugins/redis/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ describe('Redis Connection', () => {
});
});
});

describe('Redis Raw Commands', () => {
test('executing an empty raw command does nothing', async () => {
const newProps = buildPropsWithActionConfiguration(
Expand All @@ -388,6 +389,41 @@ describe('Redis Raw Commands', () => {
await assertDbStateHasNotChanged();
});

test('executing a raw command works [DBSIZE]', async () => {
const newProps = buildPropsWithActionConfiguration(
RedisPluginV1.fromJson({
raw: {
singleton: {
query: 'dbsize'
}
}
})
);

const resp = await plugin.execute(newProps);
expect((resp.output as RawOutput).response).toEqual(6);
expect(newProps.mutableOutput.log[0]).toEqual('Running command: DBSIZE');
await assertDbStateHasNotChanged();
});

test('executing a raw command works [INFO]', async () => {
const newProps = buildPropsWithActionConfiguration(
RedisPluginV1.fromJson({
raw: {
singleton: {
query: 'info'
}
}
})
);

const resp = await plugin.execute(newProps);
// no need to make this assertion brittle by asserting on the entire output. this should suffice.
expect((resp.output as RawOutput).response).toContain('redis_version');
expect(newProps.mutableOutput.log[0]).toEqual('Running command: INFO');
await assertDbStateHasNotChanged();
});

test('executing a raw command works [GET]', async () => {
const newProps = buildPropsWithActionConfiguration(
RedisPluginV1.fromJson({
Expand Down Expand Up @@ -1493,7 +1529,7 @@ describe('Redis Misc. Checks', () => {
expect('should not pass').toEqual(true);
})
.catch((err) => {
expect(err.message).toMatch(`Invalid command. Received 'GET'`);
expect(err.message).toMatch(`Error executing command: ERR wrong number of arguments for 'get' command`);
expect(err.code).toEqual(ErrorCode.INTEGRATION_SYNTAX);
});
});
Expand Down
13 changes: 7 additions & 6 deletions workers/javascript/packages/plugins/redis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,21 @@ export default class RedisPlugin extends DatabasePlugin {
try {
const parts = trimmedCommand.split(/\s+/);

// Take the first part as the verb and the rest as args
const verb = parts.shift();
// Take the first part as the command and the rest as args
const command = parts.shift();
const args = parts;

// If no verb or arg(s) exists after splitting, it means the input was not structured correctly.
if (!verb || args.length === 0) {
// If no command exists after splitting, it means the input was not structured correctly.
if (!command) {
throw new IntegrationError(`Invalid command. Received '${trimmedCommand}'`, ErrorCode.INTEGRATION_SYNTAX, {
pluginName: this.pluginName
});
}
const commandDisplayString = `${verb.toUpperCase()} ${args.join(' ')}`;

const commandDisplayString = `${command.toUpperCase()}${args.length ? ' ' + args.join(' ') : ''}`;

mutableOutput.logInfo(`Running command: ${commandDisplayString}`);
const response = await client.sendCommand(new Redis.Command(verb, args));
const response = await client.sendCommand(new Redis.Command(command, args));

// in some cases, we can format the response to make the output easier to consume
let formattedResponse = response;
Expand Down

0 comments on commit a77b0b0

Please sign in to comment.