-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added mocks and logging * https://github.com/elastic/ingest-dev/issues/54 * Added test mocks to GraphQL * Added logging * Added unit tests * Removed dead variable causing the build to fail
- Loading branch information
1 parent
8de4294
commit a022bcd
Showing
8 changed files
with
218 additions
and
4 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
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/secops/server/graphql/sources/source.mock.ts
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,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* tslint:disable */ | ||
|
||
export default | ||
{ | ||
"id": "default", | ||
"configuration": { | ||
"fields": { | ||
"host": "beat.hostname" | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/secops/server/graphql/sources/sources.mock.ts
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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* tslint:disable */ | ||
|
||
export default | ||
[ | ||
{ | ||
"id": "default", | ||
"configuration": { | ||
"fields": { | ||
"container": "docker.container.name", | ||
"host": "beat.hostname", | ||
"message": [ | ||
"message", | ||
"@message" | ||
] | ||
} | ||
} | ||
} | ||
] |
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,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { amMocking } from './kibana.index'; | ||
|
||
describe('kibana.index', () => { | ||
describe('#amMocking', () => { | ||
afterEach(() => delete process.env.INGEST_MOCKS); | ||
|
||
test('should return true when process.ENV.mocking is set to a lower case string true', () => { | ||
process.env.INGEST_MOCKS = 'true'; | ||
expect(amMocking()).toEqual(true); | ||
}); | ||
test('should return false when process.ENV.mocking is not set', () => { | ||
expect(amMocking()).toEqual(false); | ||
}); | ||
test('should return false when process.ENV.mocking is not set to a lower case string (since I am picky)', () => { | ||
process.env.INGEST_MOCKS = 'TRUE'; | ||
expect(amMocking()).toEqual(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
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,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createLogger } from './logger'; | ||
|
||
const APP_ID = 'secops'; | ||
const createMockServer = () => ({ log: jest.fn() }); | ||
|
||
describe('logger', () => { | ||
describe('#createLogger', () => { | ||
test('should log out debug', () => { | ||
const kbnServer = createMockServer(); | ||
const logger = createLogger(kbnServer as any); | ||
logger.debug('debug information'); | ||
expect(kbnServer.log.mock.calls[0][0]).toEqual(['debug', APP_ID]); | ||
expect(kbnServer.log.mock.calls[0][1]).toEqual('debug information'); | ||
}); | ||
|
||
test('should log out info', () => { | ||
const kbnServer = createMockServer(); | ||
const logger = createLogger(kbnServer as any); | ||
logger.info('info information'); | ||
expect(kbnServer.log.mock.calls[0][0]).toEqual(['info', APP_ID]); | ||
expect(kbnServer.log.mock.calls[0][1]).toEqual('info information'); | ||
}); | ||
|
||
test('should log out warn', () => { | ||
const kbnServer = createMockServer(); | ||
const logger = createLogger(kbnServer as any); | ||
logger.warn('warn information'); | ||
expect(kbnServer.log.mock.calls[0][0]).toEqual(['warning', APP_ID]); | ||
expect(kbnServer.log.mock.calls[0][1]).toEqual('warn information'); | ||
}); | ||
|
||
test('should log out error', () => { | ||
const kbnServer = createMockServer(); | ||
const logger = createLogger(kbnServer as any); | ||
logger.error('error information'); | ||
expect(kbnServer.log.mock.calls[0][0]).toEqual(['error', APP_ID]); | ||
expect(kbnServer.log.mock.calls[0][1]).toEqual('error information'); | ||
}); | ||
}); | ||
}); |
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,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Server } from 'hapi'; | ||
|
||
const LOGGING_TAGS = ['secops']; | ||
|
||
export interface Logger { | ||
debug: (message: string) => void; | ||
info: (message: string) => void; | ||
warn: (message: string) => void; | ||
error: (message: string) => void; | ||
} | ||
|
||
export const createLogger = (kbnServer: Readonly<Server>): Readonly<Logger> => ({ | ||
debug: (message: string) => kbnServer.log(['debug', ...LOGGING_TAGS], message), | ||
info: (message: string) => kbnServer.log(['info', ...LOGGING_TAGS], message), | ||
warn: (message: string) => kbnServer.log(['warning', ...LOGGING_TAGS], message), | ||
error: (message: string) => kbnServer.log(['error', ...LOGGING_TAGS], message), | ||
}); |