@@ -11,6 +11,7 @@ import {
11
11
logger ,
12
12
} from "../../logger" ;
13
13
import {
14
+ DashboardConfig ,
14
15
execute ,
15
16
extractManifestRepositoryInformation ,
16
17
getEnvVars ,
@@ -20,6 +21,20 @@ import {
20
21
import * as dashboard from "./dashboard" ;
21
22
22
23
import uuid from "uuid/v4" ;
24
+ import { deepClone } from "../../lib/util" ;
25
+
26
+ const dashboardConf : DashboardConfig = {
27
+ port : 2020 ,
28
+ image : "mcr.microsoft.com/k8s/bedrock/spektate:latest" ,
29
+ org : "testOrg" ,
30
+ project : "testProject" ,
31
+ key : "fakeKey" ,
32
+ accountName : "fakeAccount" ,
33
+ tableName : "fakeTable" ,
34
+ partitionKey : "fakePartitionKey" ,
35
+ accessToken : "accessToken" ,
36
+ sourceRepoAccessToken : "test_token" ,
37
+ } ;
23
38
24
39
beforeAll ( ( ) => {
25
40
enableVerboseLogging ( ) ;
@@ -37,6 +52,10 @@ const mockConfig = (): void => {
37
52
project : uuid ( ) ,
38
53
} ,
39
54
introspection : {
55
+ dashboard : {
56
+ image : "mcr.microsoft.com/k8s/bedrock/spektate:latest" ,
57
+ name : "spektate" ,
58
+ } ,
40
59
azure : {
41
60
account_name : uuid ( ) ,
42
61
key : uuid ( ) ,
@@ -81,8 +100,7 @@ describe("Test validateValues function", () => {
81
100
} ) ;
82
101
it ( "positive test" , ( ) => {
83
102
mockConfig ( ) ;
84
- const config = Config ( ) ;
85
- validateValues ( config , {
103
+ validateValues ( Config ( ) , {
86
104
port : "4000" ,
87
105
removeAll : false ,
88
106
} ) ;
@@ -96,7 +114,7 @@ describe("Test execute function", () => {
96
114
jest
97
115
. spyOn ( dashboard , "launchDashboard" )
98
116
. mockReturnValueOnce ( Promise . resolve ( uuid ( ) ) ) ;
99
- jest . spyOn ( dashboard , "validateValues" ) . mockReturnValueOnce ( ) ;
117
+ jest . spyOn ( dashboard , "validateValues" ) . mockReturnValueOnce ( dashboardConf ) ;
100
118
( open as jest . Mock ) . mockReturnValueOnce ( Promise . resolve ( ) ) ;
101
119
await execute (
102
120
{
@@ -125,16 +143,13 @@ describe("Test execute function", () => {
125
143
describe ( "Validate dashboard container pull" , ( ) => {
126
144
test ( "Pull dashboard container if docker is installed" , async ( ) => {
127
145
try {
128
- mockConfig ( ) ;
129
- const config = Config ( ) ;
130
- const dashboardContainerId = await launchDashboard ( config , 2020 , false ) ;
146
+ const dashboardContainerId = await launchDashboard ( dashboardConf , false ) ;
131
147
const dockerInstalled = validatePrereqs ( [ "docker" ] , false ) ;
132
148
if ( dockerInstalled ) {
133
149
const dockerId = await exec ( "docker" , [
134
150
"images" ,
135
151
"-q" ,
136
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
137
- config . introspection ! . dashboard ! . image ! ,
152
+ dashboardConf . image ,
138
153
] ) ;
139
154
expect ( dockerId ) . toBeDefined ( ) ;
140
155
expect ( dashboardContainerId ) . not . toBe ( "" ) ;
@@ -152,22 +167,22 @@ describe("Validate dashboard container pull", () => {
152
167
describe ( "Validate dashboard clean up" , ( ) => {
153
168
test ( "Launch the dashboard two times" , async ( ) => {
154
169
try {
155
- mockConfig ( ) ;
156
- const config = Config ( ) ;
157
- const dashboardContainerId = await launchDashboard ( config , 2020 , true ) ;
170
+ const dashboardContainerId = await launchDashboard ( dashboardConf , true ) ;
158
171
const dockerInstalled = validatePrereqs ( [ "docker" ] , false ) ;
159
172
if ( dockerInstalled ) {
160
173
const dockerId = await exec ( "docker" , [
161
174
"images" ,
162
175
"-q" ,
163
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
164
- config . introspection ! . dashboard ! . image ! ,
176
+ dashboardConf . image ,
165
177
] ) ;
166
178
167
179
expect ( dockerId ) . toBeDefined ( ) ;
168
180
expect ( dashboardContainerId ) . not . toBe ( "" ) ;
169
181
logger . info ( "Verified that docker image has been pulled." ) ;
170
- const dashboardContainerId2 = await launchDashboard ( config , 2020 , true ) ;
182
+ const dashboardContainerId2 = await launchDashboard (
183
+ dashboardConf ,
184
+ true
185
+ ) ;
171
186
expect ( dashboardContainerId ) . not . toBe ( dashboardContainerId2 ) ;
172
187
await exec ( "docker" , [ "container" , "stop" , dashboardContainerId2 ] ) ;
173
188
} else {
@@ -183,7 +198,7 @@ describe("Fallback to azure devops access token", () => {
183
198
test ( "Has repo_access_token specified" , async ( ) => {
184
199
mockConfig ( ) ;
185
200
const config = Config ( ) ;
186
- const envVars = ( await getEnvVars ( config ) ) . toString ( ) ;
201
+ const envVars = ( await getEnvVars ( dashboardConf ) ) . toString ( ) ;
187
202
logger . info (
188
203
`spin: ${ envVars } , act: ${
189
204
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -195,41 +210,33 @@ describe("Fallback to azure devops access token", () => {
195
210
} ) ;
196
211
197
212
it ( "No repo_access_token was specified" , async ( ) => {
198
- mockConfig ( ) ;
199
- const config = Config ( ) ;
200
- const envVars = ( await getEnvVars ( config ) ) . toString ( ) ;
201
- const expectedSubstring =
202
- "REACT_APP_SOURCE_REPO_ACCESS_TOKEN=" +
203
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
204
- config . introspection ! . azure ! . source_repo_access_token ! ;
213
+ const envVars = ( await getEnvVars ( dashboardConf ) ) . toString ( ) ;
214
+ const expectedSubstring = `REACT_APP_SOURCE_REPO_ACCESS_TOKEN=${ dashboardConf . sourceRepoAccessToken } ` ;
205
215
expect ( envVars . includes ( expectedSubstring ) ) . toBeTruthy ( ) ;
206
216
} ) ;
207
217
} ) ;
208
218
209
219
describe ( "Extract manifest repository information" , ( ) => {
210
220
test ( "Manifest repository information is successfully extracted" , ( ) => {
211
- ( Config as jest . Mock ) . mockReturnValue ( {
212
- azure_devops : {
213
- manifest_repository :
214
- "https://dev.azure.com/bhnook/fabrikam/_git/materialized" ,
215
- } ,
216
- } ) ;
217
- const config = Config ( ) ;
221
+ const config = deepClone ( dashboardConf ) ;
222
+ config . manifestRepository =
223
+ "https://dev.azure.com/bhnook/fabrikam/_git/materialized" ;
224
+
218
225
let manifestInfo = extractManifestRepositoryInformation ( config ) ;
219
226
expect ( manifestInfo ) . toBeDefined ( ) ;
220
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
221
- expect ( manifestInfo ! . githubUsername ) . toBeUndefined ( ) ;
222
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
223
- expect ( manifestInfo ! . manifestRepoName ) . toBe ( "materialized" ) ;
224
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
225
- config . azure_devops ! [ "manifest_repository" ] =
226
- "https://github.com/username/manifest" ;
227
+ if ( manifestInfo ) {
228
+ expect ( manifestInfo . githubUsername ) . toBeUndefined ( ) ;
229
+ expect ( manifestInfo . manifestRepoName ) . toBe ( "materialized" ) ;
230
+ }
231
+
232
+ config . manifestRepository = "https://github.com/username/manifest" ;
227
233
manifestInfo = extractManifestRepositoryInformation ( config ) ;
234
+
228
235
expect ( manifestInfo ) . toBeDefined ( ) ;
229
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
230
- expect ( manifestInfo ! . githubUsername ) . toBe ( "username" ) ;
231
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
232
- expect ( manifestInfo ! . manifestRepoName ) . toBe ( "manifest" ) ;
236
+ if ( manifestInfo ) {
237
+ expect ( manifestInfo . githubUsername ) . toBe ( "username" ) ;
238
+ expect ( manifestInfo . manifestRepoName ) . toBe ( "manifest" ) ;
239
+ }
233
240
234
241
logger . info ( "Verified that manifest repository extraction works" ) ;
235
242
} ) ;
0 commit comments