1
- import { join } from "path" ;
2
-
3
- import { getHomeDir } from "./getHomeDir" ;
1
+ import { getConfigFilepath } from "./getConfigFilepath" ;
2
+ import { getCredentialsFilepath } from "./getCredentialsFilepath" ;
4
3
import { getProfileData } from "./getProfileData" ;
5
- import { ENV_CONFIG_PATH , ENV_CREDENTIALS_PATH , loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
4
+ import { loadSharedConfigFiles } from "./loadSharedConfigFiles" ;
6
5
import { parseIni } from "./parseIni" ;
7
6
import { slurpFile } from "./slurpFile" ;
8
7
9
- jest . mock ( "path " ) ;
10
- jest . mock ( "./getHomeDir " ) ;
8
+ jest . mock ( "./getConfigFilepath " ) ;
9
+ jest . mock ( "./getCredentialsFilepath " ) ;
11
10
jest . mock ( "./getProfileData" ) ;
12
11
jest . mock ( "./parseIni" ) ;
13
12
jest . mock ( "./slurpFile" ) ;
14
13
15
14
describe ( "loadSharedConfigFiles" , ( ) => {
16
- const mockSeparator = "/" ;
17
- const mockHomeDir = "/mock/home/dir" ;
18
-
19
15
const mockConfigFilepath = "/mock/file/path/config" ;
20
16
const mockCredsFilepath = "/mock/file/path/credentials" ;
21
- const mockCustomSharedConfigFiles = {
17
+ const mockSharedConfigFiles = {
22
18
configFile : mockConfigFilepath ,
23
19
credentialsFile : mockCredsFilepath ,
24
20
} ;
25
21
26
- const defaultConfigFilepath = `${ mockHomeDir } /.aws/config` ;
27
- const defaultCredsFilepath = `${ mockHomeDir } /.aws/credentials` ;
28
- const mockDefaultSharedConfigFiles = {
29
- configFile : defaultConfigFilepath ,
30
- credentialsFile : defaultCredsFilepath ,
31
- } ;
32
-
33
22
beforeEach ( ( ) => {
34
- ( join as jest . Mock ) . mockImplementation ( ( ... args ) => args . join ( mockSeparator ) ) ;
35
- ( getHomeDir as jest . Mock ) . mockReturnValue ( mockHomeDir ) ;
23
+ ( getConfigFilepath as jest . Mock ) . mockReturnValue ( mockConfigFilepath ) ;
24
+ ( getCredentialsFilepath as jest . Mock ) . mockReturnValue ( mockCredsFilepath ) ;
36
25
( parseIni as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
37
26
( getProfileData as jest . Mock ) . mockImplementation ( ( args ) => args ) ;
38
27
( slurpFile as jest . Mock ) . mockImplementation ( ( path ) => Promise . resolve ( path ) ) ;
@@ -45,27 +34,19 @@ describe("loadSharedConfigFiles", () => {
45
34
46
35
it ( "returns configFile and credentialsFile from default locations" , async ( ) => {
47
36
const sharedConfigFiles = await loadSharedConfigFiles ( ) ;
48
- expect ( sharedConfigFiles ) . toStrictEqual ( mockDefaultSharedConfigFiles ) ;
49
- } ) ;
50
-
51
- it ( "returns configFile and credentialsFile from locations defined in environment" , async ( ) => {
52
- const OLD_ENV = process . env ;
53
- process . env = {
54
- ...OLD_ENV ,
55
- [ ENV_CONFIG_PATH ] : mockConfigFilepath ,
56
- [ ENV_CREDENTIALS_PATH ] : mockCredsFilepath ,
57
- } ;
58
- const sharedConfigFiles = await loadSharedConfigFiles ( { } ) ;
59
- expect ( sharedConfigFiles ) . toStrictEqual ( mockCustomSharedConfigFiles ) ;
60
- process . env = OLD_ENV ;
37
+ expect ( sharedConfigFiles ) . toStrictEqual ( mockSharedConfigFiles ) ;
38
+ expect ( getConfigFilepath ) . toHaveBeenCalledWith ( ) ;
39
+ expect ( getCredentialsFilepath ) . toHaveBeenCalledWith ( ) ;
61
40
} ) ;
62
41
63
42
it ( "returns configFile and credentialsFile from init if defined" , async ( ) => {
64
43
const sharedConfigFiles = await loadSharedConfigFiles ( {
65
44
filepath : mockCredsFilepath ,
66
45
configFilepath : mockConfigFilepath ,
67
46
} ) ;
68
- expect ( sharedConfigFiles ) . toStrictEqual ( mockCustomSharedConfigFiles ) ;
47
+ expect ( sharedConfigFiles ) . toStrictEqual ( mockSharedConfigFiles ) ;
48
+ expect ( getConfigFilepath ) . not . toHaveBeenCalled ( ) ;
49
+ expect ( getCredentialsFilepath ) . not . toHaveBeenCalled ( ) ;
69
50
} ) ;
70
51
71
52
describe ( "swallows error and returns empty configuration" , ( ) => {
@@ -86,7 +67,7 @@ describe("loadSharedConfigFiles", () => {
86
67
const sharedConfigFiles = await loadSharedConfigFiles ( ) ;
87
68
expect ( sharedConfigFiles ) . toStrictEqual ( {
88
69
configFile : { } ,
89
- credentialsFile : defaultCredsFilepath ,
70
+ credentialsFile : mockCredsFilepath ,
90
71
} ) ;
91
72
} ) ;
92
73
} ) ;
0 commit comments