GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。 NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは 別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
172 lines
6.6 KiB
JavaScript
172 lines
6.6 KiB
JavaScript
const { test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
|
|
function mockClient(sendImpl) {
|
|
return { send: sendImpl };
|
|
}
|
|
|
|
test('getConfig throws when AWS env vars are missing', () => {
|
|
delete process.env.AWS_REGION;
|
|
delete process.env.AWS_ACCESS_KEY_ID;
|
|
delete process.env.AWS_SECRET_ACCESS_KEY;
|
|
const { getConfig } = require('../src/lightsailClient');
|
|
assert.throws(() => getConfig(), /AWS_REGION/);
|
|
});
|
|
|
|
test('listInstances sends GetInstancesCommand and returns instances', async () => {
|
|
const { listInstances } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { instances: [{ name: 'xwiki-01' }] };
|
|
});
|
|
|
|
const result = await listInstances(client);
|
|
|
|
assert.deepStrictEqual(result, [{ name: 'xwiki-01' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'GetInstancesCommand');
|
|
});
|
|
|
|
test('getInstance sends GetInstanceCommand with instanceName and returns instance', async () => {
|
|
const { getInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { instance: { name: 'xwiki-01', state: { name: 'running' } } };
|
|
});
|
|
|
|
const result = await getInstance('xwiki-01', client);
|
|
|
|
assert.deepStrictEqual(result, { name: 'xwiki-01', state: { name: 'running' } });
|
|
assert.strictEqual(calls[0].constructor.name, 'GetInstanceCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-01');
|
|
});
|
|
|
|
test('startInstance sends StartInstanceCommand with instanceName and returns operations', async () => {
|
|
const { startInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Started' }] };
|
|
});
|
|
|
|
const result = await startInstance('xwiki-01', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Started' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'StartInstanceCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-01');
|
|
});
|
|
|
|
test('stopInstance sends StopInstanceCommand with instanceName', async () => {
|
|
const { stopInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Stopped' }] };
|
|
});
|
|
|
|
const result = await stopInstance('xwiki-01', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Stopped' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'StopInstanceCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-01');
|
|
});
|
|
|
|
test('rebootInstance sends RebootInstanceCommand with instanceName', async () => {
|
|
const { rebootInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Rebooting' }] };
|
|
});
|
|
|
|
const result = await rebootInstance('xwiki-01', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Rebooting' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'RebootInstanceCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-01');
|
|
});
|
|
|
|
test('createInstance sends CreateInstancesCommand with correct params', async () => {
|
|
const { createInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Started', operationType: 'CreateInstance' }] };
|
|
});
|
|
|
|
const result = await createInstance({
|
|
instanceName: 'xwiki-02',
|
|
availabilityZone: 'ap-northeast-1a',
|
|
blueprintId: 'ubuntu_22_04',
|
|
bundleId: 'small_2_0',
|
|
}, client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Started', operationType: 'CreateInstance' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'CreateInstancesCommand');
|
|
assert.deepStrictEqual(calls[0].input.instanceNames, ['xwiki-02']);
|
|
assert.strictEqual(calls[0].input.availabilityZone, 'ap-northeast-1a');
|
|
assert.strictEqual(calls[0].input.blueprintId, 'ubuntu_22_04');
|
|
assert.strictEqual(calls[0].input.bundleId, 'small_2_0');
|
|
});
|
|
|
|
test('deleteInstance sends DeleteInstanceCommand with instanceName', async () => {
|
|
const { deleteInstance } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Started', operationType: 'DeleteInstance' }] };
|
|
});
|
|
|
|
const result = await deleteInstance('xwiki-02', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Started', operationType: 'DeleteInstance' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'DeleteInstanceCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-02');
|
|
});
|
|
|
|
test('createSnapshot sends CreateInstanceSnapshotCommand with instanceName and snapshotName', async () => {
|
|
const { createSnapshot } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Started', operationType: 'CreateInstanceSnapshot' }] };
|
|
});
|
|
|
|
const result = await createSnapshot('xwiki-01', 'xwiki-01-backup-20260810', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Started', operationType: 'CreateInstanceSnapshot' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'CreateInstanceSnapshotCommand');
|
|
assert.strictEqual(calls[0].input.instanceName, 'xwiki-01');
|
|
assert.strictEqual(calls[0].input.instanceSnapshotName, 'xwiki-01-backup-20260810');
|
|
});
|
|
|
|
test('listSnapshots sends GetInstanceSnapshotsCommand and returns instanceSnapshots', async () => {
|
|
const { listSnapshots } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { instanceSnapshots: [{ name: 'xwiki-01-backup-20260810' }] };
|
|
});
|
|
|
|
const result = await listSnapshots(client);
|
|
|
|
assert.deepStrictEqual(result, [{ name: 'xwiki-01-backup-20260810' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'GetInstanceSnapshotsCommand');
|
|
});
|
|
|
|
test('deleteSnapshot sends DeleteInstanceSnapshotCommand with instanceSnapshotName', async () => {
|
|
const { deleteSnapshot } = require('../src/lightsailClient');
|
|
const calls = [];
|
|
const client = mockClient(async (cmd) => {
|
|
calls.push(cmd);
|
|
return { operations: [{ status: 'Started', operationType: 'DeleteInstanceSnapshot' }] };
|
|
});
|
|
|
|
const result = await deleteSnapshot('xwiki-01-backup-20260810', client);
|
|
|
|
assert.deepStrictEqual(result, [{ status: 'Started', operationType: 'DeleteInstanceSnapshot' }]);
|
|
assert.strictEqual(calls[0].constructor.name, 'DeleteInstanceSnapshotCommand');
|
|
assert.strictEqual(calls[0].input.instanceSnapshotName, 'xwiki-01-backup-20260810');
|
|
});
|