FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/src/test/dotfiles.test.ts at dev/Mathi/worktree · v-Mathiyarasy/cli · GitHub
v-Mathiyarasy
cli
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
src
/
test
/
dotfiles.test.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
121 lines (99 loc) · 6.39 KB
Breadcrumbs
cli
/
src
/
test
/
dotfiles.test.ts
Copy path
File metadata and controls
121 lines (99 loc) · 6.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'assert'
;
import
*
as
path
from
'path'
;
import
{
shellExec
,
pathExists
}
from
'./testUtils'
;
const
pkg
=
require
(
'../../package.json'
)
;
describe
(
'Dotfiles'
,
function
(
)
{
this
.
timeout
(
'240s'
)
;
const
tmp
=
path
.
relative
(
process
.
cwd
(
)
,
path
.
join
(
__dirname
,
'tmp'
)
)
;
const
cli
=
`npx --prefix
${
tmp
}
devcontainer`
;
before
(
'Install'
,
async
(
)
=>
{
await
shellExec
(
`rm -rf
${
tmp
}
/node_modules`
)
;
await
shellExec
(
`mkdir -p
${
tmp
}
`
)
;
await
shellExec
(
`npm --prefix
${
tmp
}
install devcontainers-cli-
${
pkg
.
version
}
.tgz`
)
;
}
)
;
let
containerId
=
''
;
this
.
afterEach
(
'Cleanup'
,
async
(
)
=>
{
assert
.
ok
(
containerId
,
'In Cleanup: Container id not found.'
)
;
await
shellExec
(
`docker rm -f
${
containerId
}
`
)
;
containerId
=
''
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository https://github.com/codspace/test-dotfiles`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with custom install path as filename'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository https://github.com/codspace/test-dotfiles --dotfiles-install-command install.sh`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with custom install path as relative path'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository https://github.com/codspace/test-dotfiles --dotfiles-install-command ./install.sh`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with custom install path as absolute path'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository https://github.com/codspace/test-dotfiles --dotfiles-install-command /home/node/dotfiles/install.sh`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with non executable install script'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository codspace/test-dotfiles-non-executable --dotfiles-install-command .run-my-dotfiles-script`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with non executable absolute path install script'
,
async
(
)
=>
{
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository codspace/test-dotfiles-non-executable --dotfiles-install-command /home/node/dotfiles/.run-my-dotfiles-script`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
}
)
;
it
(
'should execute successfully with valid config and dotfiles with secrets'
,
async
(
)
=>
{
const
testFolder
=
`
${
__dirname
}
/configs`
;
await
shellExec
(
`rm -f
${
testFolder
}
/*.testMarker`
,
undefined
,
undefined
,
true
)
;
const
secrets
=
{
'SECRET1'
:
'SecretValue1'
,
'MASK_IT'
:
'container'
,
}
;
await
shellExec
(
`printf '
${
JSON
.
stringify
(
secrets
)
}
' >
${
testFolder
}
/test-secrets-temp.json`
,
undefined
,
undefined
,
true
)
;
const
res
=
await
shellExec
(
`
${
cli
}
up --workspace-folder
${
__dirname
}
/configs/image-with-git-feature --dotfiles-repository https://github.com/codspace/test-dotfiles --secrets-file
${
testFolder
}
/test-secrets-temp.json --log-level trace --log-format json`
)
;
const
response
=
JSON
.
parse
(
res
.
stdout
)
;
assert
.
equal
(
response
.
outcome
,
'success'
)
;
containerId
=
response
.
containerId
;
assert
.
ok
(
containerId
,
'Container id not found.'
)
;
const
dotfiles
=
await
pathExists
(
cli
,
`
${
__dirname
}
/configs/image-with-git-feature`
,
`/tmp/.dotfilesMarker`
)
;
assert
.
ok
(
dotfiles
,
'Dotfiles not found.'
)
;
// assert file contents to ensure secrets & remoteEnv were available to the command
const
catResp
=
await
shellExec
(
`
${
cli
}
exec --workspace-folder
${
__dirname
}
/configs/image-with-git-feature cat /tmp/.dotfileEnvs`
)
;
const
{
stdout
,
error
}
=
catResp
;
assert
.
strictEqual
(
error
,
null
)
;
assert
.
match
(
stdout
,
/
S
E
C
R
E
T
1
=
S
e
c
r
e
t
V
a
l
u
e
1
/
)
;
assert
.
match
(
stdout
,
/
T
E
S
T
_
R
E
M
O
T
E
_
E
N
V
=
V
a
l
u
e
1
/
)
;
// assert secret masking
// We log the message `Starting container` from CLI. Since the word `container` is specified as a secret here, that should get masked
const
logs
=
res
.
stderr
;
assert
.
match
(
logs
,
/
S
t
a
r
t
i
n
g
\*
\*
\*
\*
\*
\*
\*
\*
/
)
;
assert
.
doesNotMatch
(
logs
,
/
S
t
a
r
t
i
n
g
c
o
n
t
a
i
n
e
r
/
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL