Skip to content

Commit 3b3e7a1

Browse files
committed
Test CMD env case
1 parent 4acb224 commit 3b3e7a1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ function toBooleanConfig(configValue?: string | boolean) {
2929
const envConfig = {
3030
cookiePath: process.env.HMD_CLI_COOKIE_PATH || process.env.CMD_CLI_COOKIE_PATH,
3131
serverUrl: process.env.HMD_CLI_SERVER_URL || process.env.CMD_CLI_SERVER_URL,
32-
enterprise: (process.env.HMD_CLI_COOKIE_PATH || process.env.HMD_CLI_SERVER_URL) ? true : toBooleanConfig(process.env.HMD_CLI_ENTERPRISE)
32+
enterprise: (process.env.HMD_CLI_COOKIE_PATH || process.env.HMD_CLI_SERVER_URL)
33+
? true
34+
: (process.env.CMD_CLI_COOKIE_PATH || process.env.CMD_CLI_SERVER_URL)
35+
? false
36+
: toBooleanConfig(process.env.HMD_CLI_ENTERPRISE)
3337
}
3438

3539
// look for a readable config file; we can merge it with the env.

test/config.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ describe('Config test', function () {
6565
expect(config.enterprise).to.eq(true)
6666
})
6767

68+
it('should set enterprise to false if either CMD_CLI_COOKIE_PATH or CMD_CLI_SERVER_URL are supplied', function () {
69+
fs.writeFileSync(this.configFilePath, '{}', 'utf8')
70+
71+
process.env.CMD_CLI_SERVER_URL = tempDir()
72+
let config = requireConfig()
73+
74+
expect(config.serverUrl).to.eq(process.env.CMD_CLI_SERVER_URL)
75+
expect(config.enterprise).to.eq(false)
76+
77+
cleanup()
78+
79+
process.env.CMD_CLI_COOKIE_PATH = tempDir()
80+
config = requireConfig()
81+
82+
expect(config.cookiePath).to.eq(process.env.CMD_CLI_COOKIE_PATH)
83+
expect(config.enterprise).to.eq(false)
84+
})
85+
6886
it('should set enterprise with HMD_CLI_ENTERPRISE', function () {
6987
fs.writeFileSync(this.configFilePath, '{}', 'utf8')
7088

0 commit comments

Comments
 (0)