Skip to content

Commit

Permalink
Regactor some forgotten tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Nov 20, 2024
1 parent bcd7149 commit d8f4ff4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { createAPMTransactionErrorRateIndicator, createSLO } from '../fixtures/s
import { ApmTransactionErrorRateTransformGenerator } from './apm_transaction_error_rate';
import { dataViewsService } from '@kbn/data-views-plugin/server/mocks';

const generator = new ApmTransactionErrorRateTransformGenerator(
'my-space-id',
dataViewsService,
false
);
const generator = new ApmTransactionErrorRateTransformGenerator('my-space-id', dataViewsService);

describe('Transform Generator', () => {
describe('buildCommonGroupBy', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ describe('TransformManager', () => {
it('throws when no generator exists for the slo indicator type', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionDuration': new DummyTransformGenerator(),
'sli.apm.transactionDuration': new DummyTransformGenerator(spaceId, dataViewsService),
};
const service = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await expect(
Expand All @@ -63,15 +60,12 @@ describe('TransformManager', () => {
it('throws when transform generator fails', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionDuration': new FailTransformGenerator(),
'sli.apm.transactionDuration': new FailTransformGenerator(spaceId, dataViewsService),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await expect(
Expand All @@ -85,15 +79,15 @@ describe('TransformManager', () => {
it('installs the transform', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);
const slo = createSLO({ indicator: createAPMTransactionErrorRateIndicator() });

Expand All @@ -110,15 +104,15 @@ describe('TransformManager', () => {
it('previews the transform', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await transformManager.preview('slo-transform-id');
Expand All @@ -133,15 +127,15 @@ describe('TransformManager', () => {
it('starts the transform', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await transformManager.start('slo-transform-id');
Expand All @@ -156,15 +150,15 @@ describe('TransformManager', () => {
it('stops the transform', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await transformManager.stop('slo-transform-id');
Expand All @@ -179,15 +173,15 @@ describe('TransformManager', () => {
it('uninstalls the transform', async () => {
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await transformManager.uninstall('slo-transform-id');
Expand All @@ -203,15 +197,15 @@ describe('TransformManager', () => {
);
// @ts-ignore defining only a subset of the possible SLI
const generators: Record<IndicatorTypes, TransformGenerator> = {
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(),
'sli.apm.transactionErrorRate': new ApmTransactionErrorRateTransformGenerator(
spaceId,
dataViewsService
),
};
const transformManager = new DefaultTransformManager(
generators,
scopedClusterClientMock,
loggerMock,
spaceId,
dataViewsService,
false
loggerMock
);

await transformManager.uninstall('slo-transform-id');
Expand All @@ -224,21 +218,20 @@ describe('TransformManager', () => {
});

class DummyTransformGenerator extends TransformGenerator {
async getTransformParams(
slo: SLODefinition,
spaceId: string,
dataViewService: DataViewsService
): Promise<TransformPutTransformRequest> {
constructor(spaceId: string, dataViewService: DataViewsService) {
super(spaceId, dataViewService);
}
async getTransformParams(slo: SLODefinition): Promise<TransformPutTransformRequest> {
return {} as TransformPutTransformRequest;
}
}

class FailTransformGenerator extends TransformGenerator {
getTransformParams(
slo: SLODefinition,
spaceId: string,
dataViewService: DataViewsService
): Promise<TransformPutTransformRequest> {
constructor(spaceId: string, dataViewService: DataViewsService) {
super(spaceId, dataViewService);
}

getTransformParams(slo: SLODefinition): Promise<TransformPutTransformRequest> {
throw new Error('Some error');
}
}

0 comments on commit d8f4ff4

Please sign in to comment.