1
+ import { Logger } from "@aws-sdk/types" ;
2
+
1
3
import { getExtendedInstanceMetadataCredentials } from "./getExtendedInstanceMetadataCredentials" ;
2
4
3
5
describe ( "getExtendedInstanceMetadataCredentials()" , ( ) => {
@@ -6,9 +8,11 @@ describe("getExtendedInstanceMetadataCredentials()", () => {
6
8
accessKeyId : "key" ,
7
9
secretAccessKey : "secret" ,
8
10
} ;
11
+ const logger : Logger = {
12
+ warn : jest . fn ( ) ,
13
+ } as any ;
9
14
10
15
beforeEach ( ( ) => {
11
- jest . spyOn ( global . console , "warn" ) . mockImplementation ( ( ) => { } ) ;
12
16
jest . spyOn ( global . Math , "random" ) ;
13
17
nowMock = jest . spyOn ( Date , "now" ) . mockReturnValueOnce ( new Date ( "2022-02-22T00:00:00Z" ) . getTime ( ) ) ;
14
18
} ) ;
@@ -20,7 +24,7 @@ describe("getExtendedInstanceMetadataCredentials()", () => {
20
24
it ( "should extend the expiration random time(~15 mins) from now" , ( ) => {
21
25
const anyDate : Date = "any date" as unknown as Date ;
22
26
( Math . random as jest . Mock ) . mockReturnValue ( 0.5 ) ;
23
- expect ( getExtendedInstanceMetadataCredentials ( { ...staticSecret , expiration : anyDate } ) ) . toEqual ( {
27
+ expect ( getExtendedInstanceMetadataCredentials ( { ...staticSecret , expiration : anyDate } , logger ) ) . toEqual ( {
24
28
...staticSecret ,
25
29
originalExpiration : anyDate ,
26
30
expiration : new Date ( "2022-02-22T00:17:30Z" ) ,
@@ -30,8 +34,7 @@ describe("getExtendedInstanceMetadataCredentials()", () => {
30
34
31
35
it ( "should print warning message when extending the credentials" , ( ) => {
32
36
const anyDate : Date = "any date" as unknown as Date ;
33
- getExtendedInstanceMetadataCredentials ( { ...staticSecret , expiration : anyDate } ) ;
34
- // TODO: fill the doc link
35
- expect ( console . warn ) . toBeCalledWith ( expect . stringContaining ( "Attempting credential expiration extension" ) ) ;
37
+ getExtendedInstanceMetadataCredentials ( { ...staticSecret , expiration : anyDate } , logger ) ;
38
+ expect ( logger . warn ) . toBeCalledWith ( expect . stringContaining ( "Attempting credential expiration extension" ) ) ;
36
39
} ) ;
37
40
} ) ;
0 commit comments