@skyramp/skyramp 2025.8.11 → 2025.12.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/scripts/download-binary.js +0 -5
- package/src/classes/MockV2.d.ts +93 -0
- package/src/classes/MockV2.js +62 -0
- package/src/classes/ResponseV2.d.ts +2 -1
- package/src/classes/ResponseV2.js +5 -1
- package/src/classes/SkyrampClient.d.ts +123 -36
- package/src/classes/SkyrampClient.js +93 -4
- package/src/classes/SmartPlaywright.d.ts +5 -0
- package/src/classes/SmartPlaywright.js +992 -0
- package/src/function.d.ts +20 -0
- package/src/index.d.ts +21 -19
- package/src/index.js +7 -1
- package/src/utils.d.ts +82 -0
- package/src/utils.js +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyramp/skyramp",
|
|
3
|
-
"version": "2025.
|
|
3
|
+
"version": "2025.12.19+0aa51d8",
|
|
4
4
|
"description": "module for leveraging skyramp cli functionality",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint 'src/**/*.js' 'src/**/*.ts' --fix",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"src/classes/*.ts"
|
|
18
18
|
],
|
|
19
19
|
"main": "src/index.js",
|
|
20
|
+
"types": "src/index.d.ts",
|
|
20
21
|
"author": "",
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"dependencies": {
|
|
@@ -30,4 +31,4 @@
|
|
|
30
31
|
"@typescript-eslint/parser": "^6.14.0",
|
|
31
32
|
"eslint": "^8.55.0"
|
|
32
33
|
}
|
|
33
|
-
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module for MockV2 class used in Skyramp mocking functionality.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Represents a mock object configuration for API endpoint mocking.
|
|
7
|
+
*/
|
|
8
|
+
export class MockV2 {
|
|
9
|
+
/**
|
|
10
|
+
* The URL of the service to mock
|
|
11
|
+
*/
|
|
12
|
+
URL: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The endpoint path to mock (e.g., "/api/v1/products")
|
|
16
|
+
*/
|
|
17
|
+
endpoint: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The port number of the service
|
|
21
|
+
*/
|
|
22
|
+
port: number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The HTTP method (GET, POST, PUT, DELETE, etc.)
|
|
26
|
+
*/
|
|
27
|
+
method: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The HTTP status code to return
|
|
31
|
+
*/
|
|
32
|
+
responseStatusCode: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The response body to return
|
|
36
|
+
*/
|
|
37
|
+
responseBody: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Optional request body to match
|
|
41
|
+
*/
|
|
42
|
+
requestBody?: string | null;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Optional data override object
|
|
46
|
+
*/
|
|
47
|
+
dataOverride?: Record<string, unknown> | null;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new MockV2 instance
|
|
51
|
+
* @param URL - The URL of the service to mock
|
|
52
|
+
* @param endpoint - The endpoint path to mock (e.g., "/api/v1/products")
|
|
53
|
+
* @param port - The port number of the service
|
|
54
|
+
* @param method - The HTTP method (GET, POST, PUT, DELETE, etc.)
|
|
55
|
+
* @param responseStatusCode - The HTTP status code to return
|
|
56
|
+
* @param responseBody - The response body to return
|
|
57
|
+
* @param requestBody - Optional request body to match
|
|
58
|
+
* @param dataOverride - Optional data override object
|
|
59
|
+
*/
|
|
60
|
+
constructor(
|
|
61
|
+
URL: string,
|
|
62
|
+
endpoint: string,
|
|
63
|
+
port: number,
|
|
64
|
+
method: string,
|
|
65
|
+
responseStatusCode: number,
|
|
66
|
+
responseBody: string,
|
|
67
|
+
requestBody?: string | null,
|
|
68
|
+
dataOverride?: Record<string, unknown> | null
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Convert the MockV2 object to a dictionary.
|
|
73
|
+
* @returns Dictionary representation of the MockV2 object with snake_case keys
|
|
74
|
+
*/
|
|
75
|
+
toDict(): {
|
|
76
|
+
url: string;
|
|
77
|
+
endpoint: string;
|
|
78
|
+
port: number;
|
|
79
|
+
method: string;
|
|
80
|
+
status_code: number;
|
|
81
|
+
response_body: string;
|
|
82
|
+
request_body?: string;
|
|
83
|
+
data_override?: Record<string, unknown>;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Convert the MockV2 object to a JSON string.
|
|
88
|
+
* @returns JSON string representation of the MockV2 object
|
|
89
|
+
*/
|
|
90
|
+
toJSON(): string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default MockV2;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module for MockV2 class used in Skyramp mocking functionality.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
class MockV2 {
|
|
6
|
+
/**
|
|
7
|
+
* Represents a mock object configuration for API endpoint mocking.
|
|
8
|
+
* @param {string} URL - The URL of the service to mock
|
|
9
|
+
* @param {string} endpoint - The endpoint path to mock (e.g., "/api/v1/products")
|
|
10
|
+
* @param {number} port - The port number of the service
|
|
11
|
+
* @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.)
|
|
12
|
+
* @param {number} responseStatusCode - The HTTP status code to return
|
|
13
|
+
* @param {string} responseBody - The response body to return
|
|
14
|
+
* @param {string} [requestBody] - Optional request body to match
|
|
15
|
+
* @param {Object} [dataOverride] - Optional data override object
|
|
16
|
+
*/
|
|
17
|
+
constructor(URL, endpoint, port, method, responseStatusCode, responseBody, requestBody = null, dataOverride = null) {
|
|
18
|
+
this.URL = URL;
|
|
19
|
+
this.endpoint = endpoint;
|
|
20
|
+
this.port = port;
|
|
21
|
+
this.method = method;
|
|
22
|
+
this.responseStatusCode = responseStatusCode;
|
|
23
|
+
this.responseBody = responseBody;
|
|
24
|
+
this.requestBody = requestBody;
|
|
25
|
+
this.dataOverride = dataOverride;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Convert the MockV2 object to a dictionary.
|
|
30
|
+
* @returns {Object} Dictionary representation of the MockV2 object with snake_case keys
|
|
31
|
+
*/
|
|
32
|
+
toDict() {
|
|
33
|
+
const result = {
|
|
34
|
+
url: this.URL,
|
|
35
|
+
endpoint: this.endpoint,
|
|
36
|
+
port: this.port,
|
|
37
|
+
method: this.method,
|
|
38
|
+
status_code: this.responseStatusCode,
|
|
39
|
+
response_body: this.responseBody
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (this.requestBody !== null) {
|
|
43
|
+
result.request_body = this.requestBody;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (this.dataOverride !== null) {
|
|
47
|
+
result.data_override = this.dataOverride;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Convert the MockV2 object to a JSON string.
|
|
55
|
+
* @returns {string} JSON string representation of the MockV2 object
|
|
56
|
+
*/
|
|
57
|
+
toJSON() {
|
|
58
|
+
return JSON.stringify(this.toDict());
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = MockV2;
|
|
@@ -6,11 +6,12 @@ interface ResponseV2Options {
|
|
|
6
6
|
error?: string;
|
|
7
7
|
path?: string;
|
|
8
8
|
method?: string;
|
|
9
|
-
statusCode?:
|
|
9
|
+
statusCode?: int;
|
|
10
10
|
responseHeaders?: {[headerName: string]: string};
|
|
11
11
|
responseBody?: string;
|
|
12
12
|
requestHeaders?: {[headerName: string]: string};
|
|
13
13
|
requestBody?: string;
|
|
14
|
+
cookies?: {[cookieName: string]: string};
|
|
14
15
|
duration?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -14,16 +14,18 @@ class ResponseV2 {
|
|
|
14
14
|
* @param {string} [options.response_body=''] - Body of the response
|
|
15
15
|
* @param {Object} [options.request_headers={}] - Headers included in the request
|
|
16
16
|
* @param {string} [options.request_body=''] - Body of the request
|
|
17
|
+
* @param {Object} [options.cookies={}] - Cookies included in the response
|
|
17
18
|
* @param {string} [options.duration=''] - Duration of the request/response cycle
|
|
18
19
|
*/
|
|
19
20
|
constructor(options = {}) {
|
|
20
21
|
this.path = options.path || '';
|
|
21
22
|
this.method = options.method || '';
|
|
22
|
-
this.statusCode = options.status_code ||
|
|
23
|
+
this.statusCode = options.status_code || 0;
|
|
23
24
|
this.responseHeaders = options.response_headers || {};
|
|
24
25
|
this.responseBody = options.response_body || '';
|
|
25
26
|
this.requestHeaders = options.request_headers || {};
|
|
26
27
|
this.requestBody = options.request_body || '';
|
|
28
|
+
this.cookies = options.cookies || {};
|
|
27
29
|
this.duration = options.duration || '';
|
|
28
30
|
this.error = options.error || '';
|
|
29
31
|
this.description = options.description || '';
|
|
@@ -39,6 +41,7 @@ class ResponseV2 {
|
|
|
39
41
|
responseBody: 'response_body',
|
|
40
42
|
requestHeaders: 'request_headers',
|
|
41
43
|
requestBody: 'request_body',
|
|
44
|
+
cookies: 'cookies',
|
|
42
45
|
duration: 'duration',
|
|
43
46
|
error: 'error',
|
|
44
47
|
description: 'description'
|
|
@@ -74,6 +77,7 @@ class ResponseV2 {
|
|
|
74
77
|
responseBody: 'response_body',
|
|
75
78
|
requestHeaders: 'request_headers',
|
|
76
79
|
requestBody: 'request_body',
|
|
80
|
+
cookies: 'cookies',
|
|
77
81
|
duration: 'duration',
|
|
78
82
|
error: 'error',
|
|
79
83
|
description: 'description'
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ResponseValue } from
|
|
2
|
-
import { Endpoint } from
|
|
3
|
-
import { Scenario } from
|
|
4
|
-
import {TrafficConfig} from
|
|
5
|
-
import { Protocol } from
|
|
6
|
-
import { AsyncScenario } from
|
|
7
|
-
import { LoadTestConfig } from
|
|
8
|
-
import
|
|
9
|
-
import { MultipartParam } from
|
|
1
|
+
import { ResponseValue } from "..";
|
|
2
|
+
import { Endpoint } from "./Endpoint";
|
|
3
|
+
import { Scenario } from "./Scenario";
|
|
4
|
+
import { TrafficConfig } from "./TrafficConfig";
|
|
5
|
+
import { Protocol } from "./Protocol";
|
|
6
|
+
import { AsyncScenario } from "./AsyncScenario";
|
|
7
|
+
import { LoadTestConfig } from "./LoadTestConfig";
|
|
8
|
+
import AsyncTestStatus = require("./AsyncTestStatus");
|
|
9
|
+
import { MultipartParam } from "./MultipartParam";
|
|
10
|
+
import { MockV2 } from "./MockV2";
|
|
10
11
|
|
|
11
12
|
export enum Language {
|
|
12
|
-
PYTHON =
|
|
13
|
+
PYTHON = "python",
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
interface testerStartV1Options {
|
|
@@ -20,8 +21,8 @@ interface testerStartV1Options {
|
|
|
20
21
|
address?: string;
|
|
21
22
|
scenario: Scenario | [Scenario];
|
|
22
23
|
testName: string;
|
|
23
|
-
globalHeaders?: {[headerName: string]: string};
|
|
24
|
-
globalVars?: {[variableName: string]: string};
|
|
24
|
+
globalHeaders?: { [headerName: string]: string };
|
|
25
|
+
globalVars?: { [variableName: string]: string };
|
|
25
26
|
generateTestReport?: boolean;
|
|
26
27
|
isDockerenv?: boolean;
|
|
27
28
|
}
|
|
@@ -39,12 +40,20 @@ interface SendRequestV2Options {
|
|
|
39
40
|
path: string;
|
|
40
41
|
method: string;
|
|
41
42
|
body?: string;
|
|
42
|
-
headers?: {[headerName: string]: string};
|
|
43
|
-
cookies?: {[cookieName: string]: string};
|
|
44
|
-
dataOverride?: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
headers?: { [headerName: string]: string };
|
|
44
|
+
cookies?: { [cookieName: string]: string };
|
|
45
|
+
dataOverride?: {
|
|
46
|
+
[dataName: string]: string | number | boolean | object | null;
|
|
47
|
+
};
|
|
48
|
+
pathParams?: {
|
|
49
|
+
[pathName: string]: string | number | boolean | object | null;
|
|
50
|
+
};
|
|
51
|
+
queryParams?: {
|
|
52
|
+
[queryName: string]: string | number | boolean | object | null;
|
|
53
|
+
};
|
|
54
|
+
formParams?: {
|
|
55
|
+
[formParamName: string]: string | number | boolean | object | null;
|
|
56
|
+
};
|
|
48
57
|
multipartParams?: Array<MultipartParam>;
|
|
49
58
|
expectedCode?: string;
|
|
50
59
|
description?: string;
|
|
@@ -77,6 +86,7 @@ interface TraceCollectOptions {
|
|
|
77
86
|
workerContainerName?: string;
|
|
78
87
|
playwright?: boolean;
|
|
79
88
|
playwrightOutput?: string;
|
|
89
|
+
outputDir?: string;
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
interface GenerateRestTestOptions {
|
|
@@ -113,14 +123,18 @@ interface GenerateRestTestOptions {
|
|
|
113
123
|
playwright?: boolean;
|
|
114
124
|
playwrightOutput?: string;
|
|
115
125
|
playwrightInput?: string;
|
|
126
|
+
playwrightViewportSize?: string;
|
|
127
|
+
playwrightStoragePath?: string;
|
|
116
128
|
loadCount?: string;
|
|
117
129
|
loadDuration?: string;
|
|
118
130
|
loadNumThreads?: string;
|
|
119
131
|
loadRampupDuration?: string;
|
|
120
132
|
loadRampupInterval?: string;
|
|
121
133
|
loadTargetRPS?: string;
|
|
134
|
+
rawTrace?: string;
|
|
122
135
|
unblock?: boolean;
|
|
123
136
|
entrypoint?: string;
|
|
137
|
+
chainingKey?: string;
|
|
124
138
|
}
|
|
125
139
|
|
|
126
140
|
interface SendScenarioOptions {
|
|
@@ -133,35 +147,97 @@ interface SendScenarioOptions {
|
|
|
133
147
|
}
|
|
134
148
|
|
|
135
149
|
export declare class SkyrampClient {
|
|
136
|
-
constructor(
|
|
150
|
+
constructor(
|
|
151
|
+
kubeconfigPath?: string,
|
|
152
|
+
clusterName?: string,
|
|
153
|
+
context?: string,
|
|
154
|
+
userToken?: string
|
|
155
|
+
);
|
|
137
156
|
constructor(options: SkyrampClientOptions);
|
|
138
157
|
login(): Promise<string>;
|
|
139
158
|
logout(): Promise<string>;
|
|
140
159
|
applyLocal(): Promise<void>;
|
|
141
|
-
addKubeconfig(
|
|
160
|
+
addKubeconfig(
|
|
161
|
+
context: string,
|
|
162
|
+
clusterName: string,
|
|
163
|
+
kubeconfigPath: string
|
|
164
|
+
): Promise<void>;
|
|
142
165
|
removeLocal(): Promise<void>;
|
|
143
166
|
removeCluster(clusterName?: string): Promise<void>;
|
|
144
|
-
mockerApply(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
167
|
+
mockerApply(
|
|
168
|
+
namespace: string,
|
|
169
|
+
kubePath: string,
|
|
170
|
+
kubeContext: string,
|
|
171
|
+
clusterName: string,
|
|
172
|
+
address: string,
|
|
173
|
+
endpoint: Endpoint
|
|
174
|
+
): Promise<void>;
|
|
175
|
+
deploySkyrampWorker(
|
|
176
|
+
namespace?: string,
|
|
177
|
+
workerImage?: string,
|
|
178
|
+
localImage?: boolean,
|
|
179
|
+
kubePath?: string,
|
|
180
|
+
kubeContext?: string,
|
|
181
|
+
clusterName?: string
|
|
182
|
+
): Promise<void>;
|
|
183
|
+
deleteSkyrampWorker(
|
|
184
|
+
namespace?: string,
|
|
185
|
+
kubePath?: string,
|
|
186
|
+
kubeContext?: string,
|
|
187
|
+
clusterName?: string
|
|
188
|
+
): Promise<void>;
|
|
189
|
+
runDockerSkyrampWorker(
|
|
190
|
+
workerImage?: string,
|
|
191
|
+
workerTag?: string,
|
|
192
|
+
hostPost?: number,
|
|
193
|
+
targetNetworkName?: string
|
|
194
|
+
): Promise<void>;
|
|
195
|
+
removeDockerSkyrampWorker(): Promise<void>;
|
|
149
196
|
mockerApplyV1(options: MockerApplyV1Options): Promise<void>;
|
|
150
|
-
mockerApplyV1(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
197
|
+
mockerApplyV1(
|
|
198
|
+
namespace: string,
|
|
199
|
+
kubePath: string,
|
|
200
|
+
kubeContext: string,
|
|
201
|
+
clusterName: string,
|
|
202
|
+
address: string,
|
|
203
|
+
response: ResponseValue | ResponseValue[],
|
|
204
|
+
trafficConfig: TrafficConfig
|
|
205
|
+
): Promise<void>;
|
|
206
|
+
mockerApplyFromFile(
|
|
207
|
+
namespace: string,
|
|
208
|
+
kubePath: string,
|
|
209
|
+
kubeContext: string,
|
|
210
|
+
clusterName: string,
|
|
211
|
+
address: string,
|
|
212
|
+
filePath: string
|
|
213
|
+
): Promise<void>;
|
|
214
|
+
applyMockDescription(
|
|
215
|
+
namespace: string,
|
|
216
|
+
address: string,
|
|
217
|
+
mockYamlContent: string
|
|
218
|
+
): Promise<void>;
|
|
219
|
+
applyMock(mock: MockV2 | MockV2[]): Promise<void>;
|
|
220
|
+
testerStart(
|
|
221
|
+
namespace: string,
|
|
222
|
+
kubePath: string,
|
|
223
|
+
kubeContext: string,
|
|
224
|
+
clusterName: string,
|
|
225
|
+
address: string,
|
|
226
|
+
scenario: Scenario
|
|
227
|
+
): Promise<void>;
|
|
228
|
+
testerStartV1(
|
|
229
|
+
namespace: string,
|
|
155
230
|
kubePath: string,
|
|
156
231
|
kubeContext: string,
|
|
157
232
|
clusterName: string,
|
|
158
233
|
address: string,
|
|
159
234
|
scenario: Scenario,
|
|
160
235
|
testName: string,
|
|
161
|
-
globalHeaders: {[headerName: string]: string},
|
|
236
|
+
globalHeaders: { [headerName: string]: string },
|
|
162
237
|
generateTestReport: boolean,
|
|
163
|
-
isDockerenv: boolean
|
|
164
|
-
|
|
238
|
+
isDockerenv: boolean
|
|
239
|
+
): Promise<void>;
|
|
240
|
+
|
|
165
241
|
testerStartV1(options: testerStartV1Options): Promise<void>;
|
|
166
242
|
|
|
167
243
|
testerGenerate(
|
|
@@ -175,9 +251,10 @@ export declare class SkyrampClient {
|
|
|
175
251
|
port: int,
|
|
176
252
|
generateRobot: boolean,
|
|
177
253
|
functionalScenario: boolean,
|
|
178
|
-
negativeScenario: boolean
|
|
254
|
+
negativeScenario: boolean
|
|
255
|
+
): Promise<string[]>;
|
|
179
256
|
|
|
180
|
-
sendRequest(options: SendRequestV2Options): Promise<
|
|
257
|
+
sendRequest(options: SendRequestV2Options): Promise<ResponseV2>;
|
|
181
258
|
deployDashboard(network: string): Promise<void>;
|
|
182
259
|
|
|
183
260
|
generateRestTest(options: GenerateRestTestOptions): Promise<string>;
|
|
@@ -189,5 +266,15 @@ export declare class SkyrampClient {
|
|
|
189
266
|
* @param scenario The scenario object or array of scenarios to run
|
|
190
267
|
* @param options Additional options for the load test
|
|
191
268
|
*/
|
|
192
|
-
sendScenario(
|
|
269
|
+
sendScenario(
|
|
270
|
+
scenario: AsyncScenario | AsyncScenario[],
|
|
271
|
+
options?: SendScenarioOptions
|
|
272
|
+
): Promise<AsyncTestStatus>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Fetches OTP from Skyramp email
|
|
276
|
+
*/
|
|
277
|
+
fetchLatestOtp(
|
|
278
|
+
email: string
|
|
279
|
+
): string;
|
|
193
280
|
}
|
|
@@ -3,6 +3,7 @@ const koffi = require('koffi');
|
|
|
3
3
|
const TrafficConfig = require('./TrafficConfig');
|
|
4
4
|
const RequestV2 = require('./RequestV2');
|
|
5
5
|
const ResponseV2 = require('./ResponseV2');
|
|
6
|
+
const utils = require('../utils');
|
|
6
7
|
|
|
7
8
|
const workerInfoType = koffi.struct({
|
|
8
9
|
container_name: 'char*',
|
|
@@ -32,8 +33,8 @@ const CONTAINER_PORT = 35142;
|
|
|
32
33
|
const loginWrapper = lib.func('loginWrapper', 'string', []);
|
|
33
34
|
const logoutWrapper = lib.func('logoutWrapper', 'string', []);
|
|
34
35
|
|
|
36
|
+
const { createTestDescriptionFromScenario, getYamlBytes, readDataFromFile, checkForUpdate, SKYRAMP_YAML_VERSION } = require('../utils');
|
|
35
37
|
// k8s related
|
|
36
|
-
const { createTestDescriptionFromScenario, getYamlBytes, readDataFromFile, SKYRAMP_YAML_VERSION } = require('../utils');
|
|
37
38
|
const applyLocalWrapper = lib.func('applyLocalWrapper', 'string', []);
|
|
38
39
|
const addKubeconfigWrapper = lib.func('addKubeconfigWrapper', 'string', ['string', 'string', 'string']);
|
|
39
40
|
const deleteSkyrampWorkerWrapper = lib.func('deleteSkyrampWorkerWrapper', 'string', ['string', 'string', 'string', 'string'])
|
|
@@ -49,14 +50,15 @@ const runTesterStartWrapper = lib.func('runTesterStartWrapper', testerInfoType,
|
|
|
49
50
|
// mocker related
|
|
50
51
|
const runTesterStartWrapperv1 = lib.func('runTesterStartWrapperWithGlobalHeaders', testerInfoType, ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'bool', 'string', 'string', 'string']);
|
|
51
52
|
const applyMockDescriptionWrapper = lib.func('applyMockDescriptionWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string']);
|
|
53
|
+
const applyMockObjectWrapper = lib.func('applyMockObjectWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool']);
|
|
52
54
|
// NPM only: for VS code extension use
|
|
53
55
|
const initTargetWrapper = lib.func('initTargetWrapper', 'string', ['string']);
|
|
54
56
|
const deployTargetWrapper = lib.func('deployTargetWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'bool']);
|
|
55
57
|
const deleteTargetWrapper = lib.func('deleteTargetWrapper', 'string', ['string', 'string', 'string', 'string', 'string']);
|
|
56
58
|
const runTesterGenerateRestWrapper = lib.func('runTesterGenerateRestWrapper', testerGenerateType, ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'int', 'bool', 'bool', 'bool']);
|
|
57
59
|
|
|
58
|
-
const generateRestTestWrapper = lib.func('generateRestTestWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'bool', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'string', 'bool', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'string']);
|
|
59
|
-
const traceCollectWrapper = lib.func('traceCollectWrapper', 'string', ['string', 'string', 'bool', 'string']);
|
|
60
|
+
const generateRestTestWrapper = lib.func('generateRestTestWrapper', 'string', ['string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'bool', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'string', 'bool', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'string', 'bool', 'string', 'string']);
|
|
61
|
+
const traceCollectWrapper = lib.func('traceCollectWrapper', 'string', ['string', 'string', 'bool', 'string', 'string']);
|
|
60
62
|
const analyzeOpenapiWrapper = lib.func('analyzeOpenapiWrapper', 'string', ['string', 'string']);
|
|
61
63
|
|
|
62
64
|
// Load test scenario support
|
|
@@ -98,6 +100,10 @@ class SkyrampClient {
|
|
|
98
100
|
*/
|
|
99
101
|
constructor(kubeconfigPathOrOptions, clusterName, context, userToken, directory = process.cwd()) {
|
|
100
102
|
this.local_image = false;
|
|
103
|
+
this.timestamp = Date.now();
|
|
104
|
+
|
|
105
|
+
checkForUpdate("npm")
|
|
106
|
+
|
|
101
107
|
if (typeof kubeconfigPathOrOptions === 'object') {
|
|
102
108
|
const options = kubeconfigPathOrOptions;
|
|
103
109
|
this.workerNamespaces = [];
|
|
@@ -106,7 +112,12 @@ class SkyrampClient {
|
|
|
106
112
|
// set docker params
|
|
107
113
|
if (options.runtime == "docker") {
|
|
108
114
|
if (options.dockerSkyrampPort) {
|
|
109
|
-
|
|
115
|
+
var hostname = "localhost";
|
|
116
|
+
const skyramp_in_docker = process.env.SKYRAMP_IN_DOCKER;
|
|
117
|
+
if (skyramp_in_docker) {
|
|
118
|
+
hostname = "host.docker.internal";
|
|
119
|
+
}
|
|
120
|
+
this.address = `${hostname}:${options.dockerSkyrampPort}`;
|
|
110
121
|
}
|
|
111
122
|
if (options.dockerNetwork) {
|
|
112
123
|
this.dockerNetwork = options.dockerNetwork;
|
|
@@ -425,6 +436,47 @@ class SkyrampClient {
|
|
|
425
436
|
});
|
|
426
437
|
}
|
|
427
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Applies MockV2 configuration to K8s if namespace is provided, or to docker if address is provided.
|
|
441
|
+
* @param {MockV2|MockV2[]} mock - The MockV2 instance or array of MockV2 instances to apply
|
|
442
|
+
* @returns {Promise} A promise that resolves when the mock is applied successfully
|
|
443
|
+
*/
|
|
444
|
+
async applyMock(mock) {
|
|
445
|
+
// Convert single MockV2 to array
|
|
446
|
+
if (!Array.isArray(mock)) {
|
|
447
|
+
mock = [mock];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Convert MockV2 objects to dictionary format
|
|
451
|
+
const mockList = mock.map(m => m.toDict());
|
|
452
|
+
|
|
453
|
+
// Convert to JSON string
|
|
454
|
+
const mockJson = JSON.stringify(mockList);
|
|
455
|
+
|
|
456
|
+
return new Promise((resolve, reject) => {
|
|
457
|
+
applyMockObjectWrapper.async(
|
|
458
|
+
this.address || '',
|
|
459
|
+
this.dockerNetwork || '',
|
|
460
|
+
this.namespace || '',
|
|
461
|
+
this.kubeconfigPath || '',
|
|
462
|
+
this.context || '',
|
|
463
|
+
this.clusterName || '',
|
|
464
|
+
mockJson,
|
|
465
|
+
this.workerImage || '',
|
|
466
|
+
this.local_image || false,
|
|
467
|
+
(err, res) => {
|
|
468
|
+
if (err) {
|
|
469
|
+
reject(err);
|
|
470
|
+
} else if (res) {
|
|
471
|
+
reject(new Error(res));
|
|
472
|
+
} else {
|
|
473
|
+
resolve();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
428
480
|
async testerStart(namespace, kubePath, kubeContext, clusterName, address, scenario) {
|
|
429
481
|
const preparedScenario = scenario.prepareTestDescription();
|
|
430
482
|
const testDescription = createTestDescriptionFromScenario({ scenario: preparedScenario });
|
|
@@ -763,6 +815,7 @@ class SkyrampClient {
|
|
|
763
815
|
options.workerContainerName || "",
|
|
764
816
|
options.playwright || false,
|
|
765
817
|
options.playwrightOutput || "",
|
|
818
|
+
options.outputDir || "",
|
|
766
819
|
(err, res) => {
|
|
767
820
|
if (err) {
|
|
768
821
|
reject(err);
|
|
@@ -810,14 +863,18 @@ class SkyrampClient {
|
|
|
810
863
|
options.playwright || false,
|
|
811
864
|
options.playwrightOutput || "",
|
|
812
865
|
options.playwrightInput || "",
|
|
866
|
+
options.playwrightViewportSize || "",
|
|
867
|
+
options.playwrightStoragePath || "",
|
|
813
868
|
options.loadCount || "0",
|
|
814
869
|
options.loadDuration || "0",
|
|
815
870
|
options.loadNumThreads || "0",
|
|
816
871
|
options.loadRampupDuration || "0",
|
|
817
872
|
options.loadRampupInterval || "0",
|
|
818
873
|
options.loadTargetRPS || "0",
|
|
874
|
+
options.rawTrace || "",
|
|
819
875
|
options.unblock || false,
|
|
820
876
|
options.entrypoint || "",
|
|
877
|
+
options.chainingKey || "",
|
|
821
878
|
(err, res) => {
|
|
822
879
|
if (err) {
|
|
823
880
|
reject(err);
|
|
@@ -917,6 +974,38 @@ class SkyrampClient {
|
|
|
917
974
|
);
|
|
918
975
|
});
|
|
919
976
|
}
|
|
977
|
+
|
|
978
|
+
async fetchLatestOtp(email) {
|
|
979
|
+
var latestGetResponse
|
|
980
|
+
// we use the time that this client was instantiated
|
|
981
|
+
let timestamp = this.timestamp;
|
|
982
|
+
|
|
983
|
+
if (!email.includes("@otp.skyramp.dev")) {
|
|
984
|
+
throw new Error("non-Skyramp email is not supported")
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
const username = email.replace("@otp.skyramp.dev", "")
|
|
988
|
+
|
|
989
|
+
for (let i = 0; i < 10; i ++) {
|
|
990
|
+
// Execute Request
|
|
991
|
+
latestGetResponse = await this.sendRequest({
|
|
992
|
+
url: "https://tokenize.skyramp.dev",
|
|
993
|
+
path: `/msg/${username}/latest`,
|
|
994
|
+
method: "GET"
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
if (latestGetResponse.statusCode != 200) {
|
|
998
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
999
|
+
continue
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
let codeTime = new Date(utils.getValue(latestGetResponse.responseBody, "timestamp"));
|
|
1003
|
+
if (codeTime > timestamp) {
|
|
1004
|
+
return utils.getValue(latestGetResponse.responseBody, "otp")
|
|
1005
|
+
}
|
|
1006
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
920
1009
|
}
|
|
921
1010
|
|
|
922
1011
|
module.exports = SkyrampClient;
|