Skip to content

Commit

Permalink
test: added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skuruppu committed May 6, 2021
1 parent 0886c75 commit bef8232
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ describe('Spanner', () => {
name: PATH,
displayName: NAME,
nodeCount: 1,
processingUnits: undefined,
config: `projects/project-id/instanceConfigs/${CONFIG.config}`,
},
});
Expand Down
3 changes: 3 additions & 0 deletions test/mockserver/mockinstanceadmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ export class MockInstanceAdmin {
nodeCount: call.request!.instance
? call.request!.instance.nodeCount
: undefined,
processingUnits: call.request!.instance
? call.request!.instance.processingUnits
: undefined,
labels: call.request!.instance
? call.request!.instance.labels
: undefined,
Expand Down
49 changes: 49 additions & 0 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,55 @@ describe('Spanner with mock server', () => {
);
});

it('should create an instance with processing units', async () => {
const [createdInstance] = await spanner
.createInstance('new-instance', {
config: 'test-instance-config',
processingUnits: 500,
})
.then(data => {
const operation = data[1];
return operation.promise() as Promise<
[Instance, CreateInstanceMetadata, object]
>;
})
.then(response => {
return response;
});
assert.strictEqual(
createdInstance.name,
`projects/${spanner.projectId}/instances/new-instance`
);
assert.strictEqual(createdInstance.processingUnits, 500);
assert.strictEqual(createdInstance.nodeCount, 0);
});

it('should fail if both nodes and processingUnits are given', async () => {
try {
await spanner
.createInstance('new-instance', {
config: 'test-instance-config',
nodes: 1,
processingUnits: 500,
})
.then(data => {
const operation = data[1];
return operation.promise() as Promise<
[Instance, CreateInstanceMetadata, object]
>;
})
.then(response => {
return response;
});
assert.fail('missing expected error');
} catch (err) {
assert.strictEqual(
err.message,
'Only one of nodeCount or processingUnits can be specified.'
);
}
});

it('should update an instance', async () => {
const instance = spanner.instance(mockInstanceAdmin.PROD_INSTANCE_NAME);
const [updatedInstance] = await instance
Expand Down

0 comments on commit bef8232

Please sign in to comment.