@@ -10,13 +10,31 @@ import * as fs from 'fs-extra'
10
10
11
11
import { createURIFromArgs } from '../../../cloudWatchLogs/cloudWatchLogsUtils'
12
12
import { saveCurrentLogDataContent } from '../../../cloudWatchLogs/commands/saveCurrentLogDataContent'
13
- import { CloudWatchLogsEvent , LogDataRegistry } from '../../../cloudWatchLogs/registry/logDataRegistry'
14
13
import { fileExists , makeTemporaryToolkitFolder , readFileAsString } from '../../../shared/filesystemUtilities'
15
14
import { getTestWindow } from '../../shared/vscode/window'
15
+ import {
16
+ CloudWatchLogsGroupInfo ,
17
+ CloudWatchLogsParameters ,
18
+ CloudWatchLogsResponse ,
19
+ LogDataRegistry ,
20
+ } from '../../../cloudWatchLogs/registry/logDataRegistry'
21
+ import { assertTextEditorContains } from '../../testUtil'
22
+
23
+ async function testFilterLogEvents (
24
+ logGroupInfo : CloudWatchLogsGroupInfo ,
25
+ apiParameters : CloudWatchLogsParameters ,
26
+ nextToken ?: string
27
+ ) : Promise < CloudWatchLogsResponse > {
28
+ return {
29
+ events : [
30
+ { message : 'The first log event' , logStreamName : 'stream1' , timestamp : 1675451113 } ,
31
+ { message : 'The second log event' , logStreamName : 'stream2' , timestamp : 1675451114 } ,
32
+ ] ,
33
+ }
34
+ }
16
35
17
36
describe ( 'saveCurrentLogDataContent' , async function ( ) {
18
37
let filename : string
19
- let fakeRegistry : LogDataRegistry
20
38
let tempDir : string
21
39
const expectedText = `1970-01-20T09:24:11.113+00:00\tThe first log event
22
40
1970-01-20T09:24:11.114+00:00\tThe second log event
@@ -25,15 +43,6 @@ describe('saveCurrentLogDataContent', async function () {
25
43
beforeEach ( async function ( ) {
26
44
tempDir = await makeTemporaryToolkitFolder ( )
27
45
filename = path . join ( tempDir , 'bobLoblawsLawB.log' )
28
- fakeRegistry = {
29
- fetchCachedLogEvents : ( uri : vscode . Uri ) => {
30
- const events : CloudWatchLogsEvent [ ] = [
31
- { message : 'The first log event' , logStreamName : 'stream1' , timestamp : 1675451113 } ,
32
- { message : 'The second log event' , logStreamName : 'stream2' , timestamp : 1675451114 } ,
33
- ]
34
- return events
35
- } ,
36
- } as any as LogDataRegistry
37
46
} )
38
47
39
48
afterEach ( async function ( ) {
@@ -47,19 +56,22 @@ describe('saveCurrentLogDataContent', async function () {
47
56
streamName : 's' ,
48
57
}
49
58
const uri = createURIFromArgs ( logGroupInfo , { } )
59
+ LogDataRegistry . instance . registerInitialLog ( uri , testFilterLogEvents )
60
+ await LogDataRegistry . instance . fetchNextLogEvents ( uri )
61
+ vscode . window . showTextDocument ( uri )
62
+ await assertTextEditorContains ( expectedText , false ) // Wait for document provider.
50
63
51
64
getTestWindow ( ) . onDidShowDialog ( d => d . selectItem ( vscode . Uri . file ( filename ) ) )
52
- await saveCurrentLogDataContent ( uri , fakeRegistry )
65
+ await saveCurrentLogDataContent ( )
53
66
54
67
assert . ok ( await fileExists ( filename ) )
55
68
assert . strictEqual ( await readFileAsString ( filename ) , expectedText )
56
69
} )
57
70
58
71
it ( 'does not do anything if the URI is invalid' , async function ( ) {
59
72
getTestWindow ( ) . onDidShowDialog ( d => d . selectItem ( vscode . Uri . file ( filename ) ) )
60
- await saveCurrentLogDataContent ( vscode . Uri . parse ( `notCloudWatch:hahahaha` ) , fakeRegistry )
73
+ vscode . window . showTextDocument ( vscode . Uri . parse ( `notCloudWatch:hahahaha` ) )
74
+ await saveCurrentLogDataContent ( )
61
75
assert . strictEqual ( await fileExists ( filename ) , false )
62
76
} )
63
-
64
- // TODO: Add test for fs.writeFile failure. Apparently `fs.chmod` doesn't work on Windows?
65
77
} )
0 commit comments