-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement optional default values in localEnv/containerEnv expansions (…
…#51)
- Loading branch information
1 parent
41dfe5f
commit 051f4ed
Showing
2 changed files
with
155 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
|
||
import { substitute } from '../spec-common/variableSubstitution'; | ||
import { URI } from 'vscode-uri'; | ||
|
||
describe('Variable substitution', function () { | ||
|
||
it(`environment variables`, async () => { | ||
const raw = { | ||
foo: 'bar${env:baz}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
baz: 'somevalue' | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'barsomevaluebar'); | ||
}); | ||
|
||
it(`localWorkspaceFolder`, async () => { | ||
const raw = { | ||
foo: 'bar${localWorkspaceFolder}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
baz: 'somevalue' | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'bar/foo/barbar'); | ||
}); | ||
|
||
it(`containerWorkspaceFolder`, async () => { | ||
const raw = { | ||
foo: 'bar${containerWorkspaceFolder}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
baz: 'somevalue' | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'bar/baz/bluebar'); | ||
}); | ||
|
||
it(`localWorkspaceFolderBasename and containerWorkspaceFolder`, async () => { | ||
const raw = { | ||
foo: 'bar${containerWorkspaceFolder}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/red', | ||
containerWorkspaceFolder: '/baz/${localWorkspaceFolderBasename}', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
baz: 'somevalue' | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'bar/baz/redbar'); | ||
}); | ||
|
||
it(`environment variables with default value if they do not exist`, async () => { | ||
const raw = { | ||
foo: 'bar${localEnv:baz:default}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'bardefaultbar'); | ||
}); | ||
|
||
it(`environment variables without default value if they do not exist`, async () => { | ||
const raw = { | ||
foo: 'bar${localEnv:baz}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'barbar'); | ||
}); | ||
|
||
it(`environment variables with default value if they do not exist`, async () => { | ||
const raw = { | ||
foo: 'bar${localEnv:baz:default}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
baz: 'somevalue' | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'barsomevaluebar'); | ||
}); | ||
|
||
it(`environment variables without default value if they do not exist`, async () => { | ||
const raw = { | ||
foo: 'bar${localEnv:baz:default:a:b:c}bar' | ||
}; | ||
const result = substitute({ | ||
platform: 'linux', | ||
localWorkspaceFolder: '/foo/bar', | ||
containerWorkspaceFolder: '/baz/blue', | ||
configFile: URI.file('/foo/bar/baz.json'), | ||
env: { | ||
}, | ||
}, raw); | ||
assert.strictEqual(result.foo, 'bardefaultbar'); | ||
}); | ||
}); |