-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validator): active instances validation properly filtered for sh…
…utdown instances (#156) adds unit tests for validator groupHasActiveInstances method
- Loading branch information
1 parent
3c840df
commit 9c0ea11
Showing
3 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
// @ts-nocheck | ||
|
||
import assert from 'node:assert'; | ||
import test, { afterEach, describe, mock } from 'node:test'; | ||
|
||
import Validator from '../validator'; | ||
|
||
describe('Validator', () => { | ||
let context = { | ||
logger: { | ||
info: mock.fn(), | ||
debug: mock.fn(), | ||
error: mock.fn(), | ||
warn: mock.fn(), | ||
}, | ||
}; | ||
|
||
const instanceTracker = { | ||
trimCurrent: mock.fn(), | ||
}; | ||
|
||
const instanceGroupManager = { | ||
getInstanceGroup: mock.fn(), | ||
}; | ||
|
||
const metricsLoop = { | ||
getCloudInstances: mock.fn(), | ||
}; | ||
|
||
const groupName = 'group'; | ||
|
||
const validator = new Validator({ instanceTracker, instanceGroupManager, metricsLoop }); | ||
|
||
afterEach(() => { | ||
context = { | ||
logger: { | ||
info: mock.fn(), | ||
debug: mock.fn(), | ||
error: mock.fn(), | ||
warn: mock.fn(), | ||
}, | ||
}; | ||
}); | ||
|
||
// these tests are for the groupHasActiveInstances method | ||
describe('validator', () => { | ||
test('should return false for a group with no instances', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => []); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => []); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, false); | ||
}); | ||
|
||
test('should return true for a group with an instance', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => [{ instanceId: '1' }]); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => []); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
test('should return false for a group with an instance, shutdown completed', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => [ | ||
{ instanceId: '1', shutdownComplete: true }, | ||
]); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => []); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, false); | ||
}); | ||
|
||
test('should return true for a group with one active and one shutdown instance', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => [ | ||
{ instanceId: '1' }, | ||
{ instanceId: '2', shutdownComplete: new Date().toISOString() }, | ||
]); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => []); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
test('should return true for a group with cloud status running', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => [{ instanceId: '1' }]); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => [ | ||
{ instanceId: '1', cloudStatus: 'running' }, | ||
]); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, true); | ||
}); | ||
|
||
test('should return false for a group with cloud status shutdown', async () => { | ||
instanceTracker.trimCurrent.mock.mockImplementationOnce(() => [{ instanceId: '1' }]); | ||
metricsLoop.getCloudInstances.mock.mockImplementationOnce(() => [ | ||
{ instanceId: '1', cloudStatus: 'shutdown' }, | ||
]); | ||
|
||
const result = await validator.groupHasActiveInstances(context, groupName); | ||
assert.strictEqual(result, false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters