-
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.
fix: logs not being parsed in stackdriver. (#22)
- Loading branch information
1 parent
be9e915
commit 5f4d393
Showing
15 changed files
with
698 additions
and
144 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
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,28 @@ | ||
import { MockedWebClient } from '@slack-wrench/jest-mock-web-client'; | ||
import { SlackService } from '../slack.service'; | ||
import { createApp } from './fixtures'; | ||
|
||
describe('api', () => { | ||
let service: SlackService; | ||
let output: any; | ||
|
||
beforeEach(async () => { | ||
output = jest.fn(); | ||
const app = await createApp({ | ||
type: 'api', | ||
defaultChannel: 'my-channel', | ||
apiOptions: { token: 'my-token' }, | ||
}); | ||
service = app.get<SlackService>(SlackService); | ||
}); | ||
|
||
it('must send requests to API', async () => { | ||
await service.postMessage({ text: 'hello-world' }); | ||
expect( | ||
MockedWebClient.mock.instances[0].chat.postMessage, | ||
).toHaveBeenCalledWith({ | ||
channel: 'my-channel', | ||
text: 'hello-world', | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { SlackConfig, SlackModule } from '../slack.module'; | ||
|
||
export const createApp = (options?: Partial<SlackConfig>) => { | ||
return Test.createTestingModule({ | ||
imports: [SlackModule.forRoot(options)], | ||
}).compile(); | ||
}; |
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,63 @@ | ||
import { Log, LogSync } from '@google-cloud/logging'; | ||
import { Test } from '@nestjs/testing'; | ||
import { | ||
GOOGLE_LOGGING, | ||
SLACK_MODULE_OPTIONS, | ||
SLACK_WEB_CLIENT, | ||
} from '../constants'; | ||
import { SlackService } from '../slack.service'; | ||
import { createApp } from './fixtures'; | ||
|
||
describe('google logging', () => { | ||
let service: SlackService; | ||
let write: any; | ||
|
||
beforeEach(async () => { | ||
write = jest.fn(); | ||
const app = await Test.createTestingModule({ | ||
providers: [ | ||
{ | ||
provide: SLACK_MODULE_OPTIONS, | ||
useValue: { type: 'google' }, | ||
}, | ||
{ | ||
provide: SLACK_WEB_CLIENT, | ||
useValue: null, | ||
}, | ||
{ | ||
provide: GOOGLE_LOGGING, | ||
useValue: { | ||
write, | ||
entry: (metadata: any, message: any) => ({ | ||
...metadata, | ||
message, | ||
}), | ||
}, | ||
}, | ||
SlackService, | ||
], | ||
}).compile(); | ||
service = app.get<SlackService>(SlackService); | ||
}); | ||
|
||
it('must output requests as structured logs', async () => { | ||
const request = { | ||
text: 'hello-world', | ||
channel: 'hello-world', | ||
}; | ||
await service.postMessage(request); | ||
expect(write).toHaveBeenCalledWith({ | ||
'logging.googleapis.com/labels': { type: 'nestjs-slack' }, | ||
'logging.googleapis.com/operation': { | ||
producer: 'github.com/bjerkio/nestjs-slack', | ||
}, | ||
message: { channel: 'hello-world', text: 'hello-world' }, | ||
severity: 'NOTICE', | ||
}); | ||
}); | ||
|
||
it('must resolve @google/cloud-logging', async () => { | ||
const app = await createApp({ type: 'google' }); | ||
expect(app.get(GOOGLE_LOGGING)).toBeInstanceOf(LogSync); | ||
}); | ||
}); |
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
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,22 @@ | ||
import { SlackService } from '../slack.service'; | ||
import { createApp } from './fixtures'; | ||
|
||
describe('stdout', () => { | ||
let service: SlackService; | ||
let output: any; | ||
|
||
beforeEach(async () => { | ||
output = jest.fn(); | ||
const app = await createApp({ output }); | ||
service = app.get<SlackService>(SlackService); | ||
}); | ||
|
||
it('must output requests to stdout', async () => { | ||
const request = { | ||
text: 'hello-world', | ||
channel: 'hello-world', | ||
}; | ||
await service.postMessage(request); | ||
expect(output).toHaveBeenCalledWith(request); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const SLACK_MODULE_OPTIONS = 'SlackModuleOptions'; | ||
export const SLACK_WEB_CLIENT = 'SlackWebClient'; | ||
export const GOOGLE_LOGGING = 'SlackGoogleLogging'; |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './constants'; | ||
export * from './slack.module'; | ||
export * from './slack.service'; | ||
export * from './types'; |
Oops, something went wrong.