|
1 |
| -/* eslint-disable @typescript-eslint/no-use-before-define */ |
2 | 1 | import commander from "commander";
|
3 | 2 | import { Config } from "../../config";
|
4 | 3 | import {
|
@@ -27,42 +26,6 @@ export interface ValidateConfig {
|
27 | 26 | key: string;
|
28 | 27 | }
|
29 | 28 |
|
30 |
| -/** |
31 |
| - * Executes the command, can all exit function with 0 or 1 |
32 |
| - * when command completed successfully or failed respectively. |
33 |
| - * |
34 |
| - * @param opts validated option values |
35 |
| - * @param exitFn exit function |
36 |
| - */ |
37 |
| -export const execute = async ( |
38 |
| - opts: CommandOptions, |
39 |
| - exitFn: (status: number) => Promise<void> |
40 |
| -): Promise<void> => { |
41 |
| - try { |
42 |
| - const config = isValidConfig(Config()); |
43 |
| - |
44 |
| - if (opts.selfTest) { |
45 |
| - await runSelfTest(config); |
46 |
| - } |
47 |
| - await exitFn(0); |
48 |
| - } catch (err) { |
49 |
| - logger.error(err); |
50 |
| - await exitFn(1); |
51 |
| - } |
52 |
| -}; |
53 |
| - |
54 |
| -/** |
55 |
| - * Adds the validate command to the commander command object |
56 |
| - * @param command Commander command object to decorate |
57 |
| - */ |
58 |
| -export const commandDecorator = (command: commander.Command): void => { |
59 |
| - buildCmd(command, decorator).action(async (opts: CommandOptions) => { |
60 |
| - await execute(opts, async (status: number) => { |
61 |
| - await exitCmd(logger, process.exit, status); |
62 |
| - }); |
63 |
| - }); |
64 |
| -}; |
65 |
| - |
66 | 29 | /**
|
67 | 30 | * Validates that the deployment configuration is specified.
|
68 | 31 | */
|
@@ -132,44 +95,6 @@ export const isValidConfig = (config: ConfigYaml): ValidateConfig => {
|
132 | 95 | );
|
133 | 96 | };
|
134 | 97 |
|
135 |
| -/** |
136 |
| - * Run the self-test for introspection |
137 |
| - * |
138 |
| - * @param config spk configuration values |
139 |
| - */ |
140 |
| -export const runSelfTest = async (config: ValidateConfig): Promise<void> => { |
141 |
| - try { |
142 |
| - logger.info("Writing self-test data for introspection..."); |
143 |
| - const buildId = await writeSelfTestData( |
144 |
| - config.key, |
145 |
| - config.accountName, |
146 |
| - config.partitionKey, |
147 |
| - config.tableName |
148 |
| - ); |
149 |
| - |
150 |
| - logger.info("Deleting self-test data..."); |
151 |
| - const isVerified = await deleteSelfTestData( |
152 |
| - config.key, |
153 |
| - config.accountName, |
154 |
| - config.partitionKey, |
155 |
| - config.tableName, |
156 |
| - buildId |
157 |
| - ); |
158 |
| - |
159 |
| - const statusMessage = |
160 |
| - "Finished running self-test. Service introspection self-test status: "; |
161 |
| - |
162 |
| - if (!isVerified) { |
163 |
| - logger.error(statusMessage + "FAILED. Please try again."); |
164 |
| - } else { |
165 |
| - logger.info(statusMessage + "SUCCEEDED."); |
166 |
| - } |
167 |
| - } catch (err) { |
168 |
| - logger.error("Error running self-test."); |
169 |
| - throw err; |
170 |
| - } |
171 |
| -}; |
172 |
| - |
173 | 98 | /**
|
174 | 99 | * Writes self-test pipeline data to the storage account table.
|
175 | 100 | * @param accountKey storage account key
|
@@ -261,3 +186,77 @@ export const deleteSelfTestData = async (
|
261 | 186 | });
|
262 | 187 | return isDeleted;
|
263 | 188 | };
|
| 189 | + |
| 190 | +/** |
| 191 | + * Run the self-test for introspection |
| 192 | + * |
| 193 | + * @param config spk configuration values |
| 194 | + */ |
| 195 | +export const runSelfTest = async (config: ValidateConfig): Promise<void> => { |
| 196 | + try { |
| 197 | + logger.info("Writing self-test data for introspection..."); |
| 198 | + const buildId = await writeSelfTestData( |
| 199 | + config.key, |
| 200 | + config.accountName, |
| 201 | + config.partitionKey, |
| 202 | + config.tableName |
| 203 | + ); |
| 204 | + |
| 205 | + logger.info("Deleting self-test data..."); |
| 206 | + const isVerified = await deleteSelfTestData( |
| 207 | + config.key, |
| 208 | + config.accountName, |
| 209 | + config.partitionKey, |
| 210 | + config.tableName, |
| 211 | + buildId |
| 212 | + ); |
| 213 | + |
| 214 | + const statusMessage = |
| 215 | + "Finished running self-test. Service introspection self-test status: "; |
| 216 | + |
| 217 | + if (!isVerified) { |
| 218 | + logger.error(statusMessage + "FAILED. Please try again."); |
| 219 | + } else { |
| 220 | + logger.info(statusMessage + "SUCCEEDED."); |
| 221 | + } |
| 222 | + } catch (err) { |
| 223 | + logger.error("Error running self-test."); |
| 224 | + throw err; |
| 225 | + } |
| 226 | +}; |
| 227 | + |
| 228 | +/** |
| 229 | + * Executes the command, can all exit function with 0 or 1 |
| 230 | + * when command completed successfully or failed respectively. |
| 231 | + * |
| 232 | + * @param opts validated option values |
| 233 | + * @param exitFn exit function |
| 234 | + */ |
| 235 | +export const execute = async ( |
| 236 | + opts: CommandOptions, |
| 237 | + exitFn: (status: number) => Promise<void> |
| 238 | +): Promise<void> => { |
| 239 | + try { |
| 240 | + const config = isValidConfig(Config()); |
| 241 | + |
| 242 | + if (opts.selfTest) { |
| 243 | + await runSelfTest(config); |
| 244 | + } |
| 245 | + await exitFn(0); |
| 246 | + } catch (err) { |
| 247 | + logger.error(err); |
| 248 | + await exitFn(1); |
| 249 | + } |
| 250 | +}; |
| 251 | + |
| 252 | +/** |
| 253 | + * Adds the validate command to the commander command object |
| 254 | + * @param command Commander command object to decorate |
| 255 | + */ |
| 256 | +export const commandDecorator = (command: commander.Command): void => { |
| 257 | + buildCmd(command, decorator).action(async (opts: CommandOptions) => { |
| 258 | + await execute(opts, async (status: number) => { |
| 259 | + await exitCmd(logger, process.exit, status); |
| 260 | + }); |
| 261 | + }); |
| 262 | +}; |
0 commit comments