@hatchet-dev/typescript-sdk 0.0.2 → 0.1.0
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/README.md +2 -3
- package/dist/clients/admin/admin-client.d.ts +2 -4
- package/dist/clients/admin/admin-client.js +2 -5
- package/dist/clients/dispatcher/action-listener.d.ts +4 -2
- package/dist/clients/dispatcher/dispatcher-client.d.ts +6 -3
- package/dist/clients/dispatcher/dispatcher-client.js +16 -4
- package/dist/clients/event/event-client.d.ts +4 -2
- package/dist/clients/event/event-client.js +6 -2
- package/dist/clients/hatchet-client/hatchet-client.d.ts +2 -2
- package/dist/clients/hatchet-client/hatchet-client.js +2 -2
- package/dist/clients/worker/worker.d.ts +13 -10
- package/dist/clients/worker/worker.js +117 -28
- package/dist/package.json +73 -0
- package/dist/protoc/dispatcher/dispatcher.d.ts +82 -22
- package/dist/protoc/dispatcher/dispatcher.js +292 -58
- package/dist/protoc/workflows/workflows.d.ts +26 -0
- package/dist/protoc/workflows/workflows.js +138 -1
- package/dist/step.d.ts +3 -0
- package/dist/step.js +2 -0
- package/dist/workflow.d.ts +33 -0
- package/dist/workflow.js +11 -1
- package/package.json +8 -3
- package/dist/clients/admin/admin-client.test.d.ts +0 -1
- package/dist/clients/admin/admin-client.test.js +0 -101
- package/dist/clients/dispatcher/action-listener.test.d.ts +0 -4
- package/dist/clients/dispatcher/action-listener.test.js +0 -277
- package/dist/clients/dispatcher/dispatcher-client.test.d.ts +0 -1
- package/dist/clients/dispatcher/dispatcher-client.test.js +0 -99
- package/dist/clients/event/event-client.test.d.ts +0 -1
- package/dist/clients/event/event-client.test.js +0 -60
- package/dist/clients/hatchet-client/hatchet-client.test.d.ts +0 -2
- package/dist/clients/hatchet-client/hatchet-client.test.js +0 -135
- package/dist/clients/worker/worker.test.d.ts +0 -1
- package/dist/clients/worker/worker.test.js +0 -256
- package/dist/util/config-loader/config-loader.test.d.ts +0 -1
- package/dist/util/config-loader/config-loader.test.js +0 -72
- package/dist/util/hatchet-promise/hatchet-promise.test.d.ts +0 -1
- package/dist/util/hatchet-promise/hatchet-promise.test.js +0 -40
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const hatchet_client_1 = require("../hatchet-client");
|
|
16
|
-
const dispatcher_1 = require("@hatchet/protoc/dispatcher");
|
|
17
|
-
const action_listener_1 = require("../dispatcher/action-listener");
|
|
18
|
-
const nice_grpc_common_1 = require("nice-grpc-common");
|
|
19
|
-
const action_listener_test_1 = require("../dispatcher/action-listener.test");
|
|
20
|
-
const zod_1 = require("zod");
|
|
21
|
-
const sleep_1 = __importDefault(require("../../util/sleep"));
|
|
22
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
23
|
-
const worker_1 = require("./worker");
|
|
24
|
-
const mockStart = {
|
|
25
|
-
tenantId: 'TENANT_ID',
|
|
26
|
-
jobId: 'job1',
|
|
27
|
-
jobName: 'Job One',
|
|
28
|
-
jobRunId: 'run1',
|
|
29
|
-
stepId: 'step1',
|
|
30
|
-
stepRunId: 'runStep1',
|
|
31
|
-
actionId: 'action1',
|
|
32
|
-
actionType: dispatcher_1.ActionType.START_STEP_RUN,
|
|
33
|
-
actionPayload: JSON.stringify('{"input": {"data": 1}}'),
|
|
34
|
-
};
|
|
35
|
-
const mockCancel = Object.assign(Object.assign({}, mockStart), { actionType: dispatcher_1.ActionType.CANCEL_STEP_RUN });
|
|
36
|
-
describe('Worker', () => {
|
|
37
|
-
let hatchet;
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
hatchet = new hatchet_client_1.HatchetClient({
|
|
40
|
-
token: 'TOKEN',
|
|
41
|
-
log_level: 'OFF',
|
|
42
|
-
host_port: 'HOST_PORT',
|
|
43
|
-
tls_config: {
|
|
44
|
-
cert_file: 'TLS_CERT_FILE',
|
|
45
|
-
key_file: 'TLS_KEY_FILE',
|
|
46
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
47
|
-
server_name: 'TLS_SERVER_NAME',
|
|
48
|
-
},
|
|
49
|
-
}, {
|
|
50
|
-
credentials: nice_grpc_1.ChannelCredentials.createInsecure(),
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('register_workflow', () => {
|
|
54
|
-
it('should update the registry', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
56
|
-
const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
|
|
57
|
-
const workflow = {
|
|
58
|
-
id: 'workflow1',
|
|
59
|
-
description: 'test',
|
|
60
|
-
on: {
|
|
61
|
-
event: 'user:create',
|
|
62
|
-
},
|
|
63
|
-
steps: [
|
|
64
|
-
{
|
|
65
|
-
name: 'step1',
|
|
66
|
-
run: (ctx) => {
|
|
67
|
-
return { test: 'test' };
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
yield worker.register_workflow(workflow);
|
|
73
|
-
expect(putWorkflowSpy).toHaveBeenCalledTimes(1);
|
|
74
|
-
expect(worker.action_registry).toEqual({
|
|
75
|
-
[`default:step1`]: workflow.steps[0].run,
|
|
76
|
-
});
|
|
77
|
-
}));
|
|
78
|
-
});
|
|
79
|
-
describe('handle_start_step_run', () => {
|
|
80
|
-
it('should start a step run', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
82
|
-
const putWorkflowSpy = jest.spyOn(worker.client.admin, 'put_workflow').mockResolvedValue();
|
|
83
|
-
const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
|
|
84
|
-
const sendActionEventSpy = jest
|
|
85
|
-
.spyOn(worker.client.dispatcher, 'send_action_event')
|
|
86
|
-
.mockResolvedValue({
|
|
87
|
-
tenantId: 'TENANT_ID',
|
|
88
|
-
workerId: 'WORKER_ID',
|
|
89
|
-
});
|
|
90
|
-
const startSpy = jest.fn().mockReturnValue({ data: 4 });
|
|
91
|
-
worker.action_registry = {
|
|
92
|
-
[mockStart.actionId]: startSpy,
|
|
93
|
-
};
|
|
94
|
-
worker.handle_start_step_run(mockStart);
|
|
95
|
-
yield (0, sleep_1.default)(100);
|
|
96
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_COMPLETED, { data: 4 });
|
|
98
|
-
expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
|
|
99
|
-
expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
|
|
100
|
-
}));
|
|
101
|
-
it('should fail gracefully', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
103
|
-
const getActionEventSpy = jest.spyOn(worker, 'get_action_event');
|
|
104
|
-
const sendActionEventSpy = jest
|
|
105
|
-
.spyOn(worker.client.dispatcher, 'send_action_event')
|
|
106
|
-
.mockResolvedValue({
|
|
107
|
-
tenantId: 'TENANT_ID',
|
|
108
|
-
workerId: 'WORKER_ID',
|
|
109
|
-
});
|
|
110
|
-
const startSpy = jest.fn().mockRejectedValue(new Error('ERROR'));
|
|
111
|
-
worker.action_registry = {
|
|
112
|
-
[mockStart.actionId]: startSpy,
|
|
113
|
-
};
|
|
114
|
-
worker.handle_start_step_run(mockStart);
|
|
115
|
-
yield (0, sleep_1.default)(100);
|
|
116
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
117
|
-
expect(getActionEventSpy).toHaveBeenNthCalledWith(2, expect.anything(), dispatcher_1.ActionEventType.STEP_EVENT_TYPE_FAILED, expect.anything());
|
|
118
|
-
expect(worker.futures[mockStart.stepRunId]).toBeUndefined();
|
|
119
|
-
expect(sendActionEventSpy).toHaveBeenCalledTimes(2);
|
|
120
|
-
}));
|
|
121
|
-
});
|
|
122
|
-
describe('handle_cancel_step_run', () => {
|
|
123
|
-
it('should cancel a step run', () => {
|
|
124
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
125
|
-
const cancelSpy = jest.fn().mockReturnValue(undefined);
|
|
126
|
-
worker.futures = {
|
|
127
|
-
[mockCancel.stepRunId]: {
|
|
128
|
-
cancel: cancelSpy,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
worker.handle_cancel_step_run(mockCancel);
|
|
132
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
133
|
-
expect(worker.futures[mockCancel.stepRunId]).toBeUndefined();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe('exit_gracefully', () => {
|
|
137
|
-
xit('should call exit_gracefully on SIGTERM', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
139
|
-
// the spy is not working and the test is killing the test process
|
|
140
|
-
const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockImplementationOnce(() => {
|
|
141
|
-
throw new Error('Simulated error');
|
|
142
|
-
});
|
|
143
|
-
process.emit('SIGTERM', 'SIGTERM');
|
|
144
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
145
|
-
}));
|
|
146
|
-
xit('should call exit_gracefully on SIGINT', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
148
|
-
// This is killing the process (as it should) fix the spy at some point
|
|
149
|
-
const exitSpy = jest.spyOn(worker, 'exit_gracefully').mockResolvedValue();
|
|
150
|
-
process.emit('SIGINT', 'SIGINT');
|
|
151
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
152
|
-
}));
|
|
153
|
-
xit('should unregister the listener and exit', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
155
|
-
jest.spyOn(process, 'exit').mockImplementation((number) => {
|
|
156
|
-
throw new Error(`EXIT ${number}`);
|
|
157
|
-
}); // This is killing the process (as it should) fix the spy at some point
|
|
158
|
-
const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
159
|
-
mockActionListener.unregister = jest.fn().mockResolvedValue((0, zod_1.never)());
|
|
160
|
-
worker.listener = mockActionListener;
|
|
161
|
-
expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
-
yield worker.exit_gracefully();
|
|
163
|
-
})).toThrow('EXIT 0');
|
|
164
|
-
expect(mockActionListener.unregister).toHaveBeenCalledTimes(1);
|
|
165
|
-
}));
|
|
166
|
-
it('should exit the process if handle_kill is true', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
168
|
-
const exitSpy = jest.spyOn(process, 'exit').mockReturnValue(undefined);
|
|
169
|
-
yield worker.exit_gracefully();
|
|
170
|
-
expect(exitSpy).toHaveBeenCalledTimes(1);
|
|
171
|
-
}));
|
|
172
|
-
});
|
|
173
|
-
describe('start', () => {
|
|
174
|
-
xit('should get actions and start runs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
176
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
177
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
178
|
-
const mockActionListener = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockStart, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
179
|
-
const getActionListenerSpy = jest
|
|
180
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
181
|
-
.mockResolvedValue(mockActionListener);
|
|
182
|
-
yield worker.start();
|
|
183
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
|
|
184
|
-
expect(startSpy).toHaveBeenCalledTimes(2);
|
|
185
|
-
expect(cancelSpy).toHaveBeenCalledTimes(0);
|
|
186
|
-
}));
|
|
187
|
-
it('should get actions and cancel runs', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
189
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
190
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
191
|
-
const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
192
|
-
const getActionListenerSpy = jest
|
|
193
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
194
|
-
.mockResolvedValue(mockActionListner);
|
|
195
|
-
yield worker.start();
|
|
196
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(1);
|
|
197
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
198
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
199
|
-
}));
|
|
200
|
-
it('should retry 5 times to start a worker then throw an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
202
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
203
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
204
|
-
const mockActionListner = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
205
|
-
const getActionListenerSpy = jest
|
|
206
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
207
|
-
.mockImplementationOnce(() => {
|
|
208
|
-
throw new Error('Simulated error');
|
|
209
|
-
})
|
|
210
|
-
.mockImplementationOnce(() => {
|
|
211
|
-
throw new Error('Simulated error');
|
|
212
|
-
})
|
|
213
|
-
.mockImplementationOnce(() => {
|
|
214
|
-
throw new Error('Simulated error');
|
|
215
|
-
})
|
|
216
|
-
.mockImplementationOnce(() => {
|
|
217
|
-
throw new Error('Simulated error');
|
|
218
|
-
})
|
|
219
|
-
.mockImplementationOnce(() => {
|
|
220
|
-
throw new Error('Simulated error');
|
|
221
|
-
})
|
|
222
|
-
.mockImplementationOnce(() => {
|
|
223
|
-
throw new Error('Simulated error');
|
|
224
|
-
});
|
|
225
|
-
yield worker.start();
|
|
226
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
|
|
227
|
-
expect(startSpy).toHaveBeenCalledTimes(0);
|
|
228
|
-
expect(cancelSpy).toHaveBeenCalledTimes(0);
|
|
229
|
-
}));
|
|
230
|
-
it('should successfully run after retrying < 5 times', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
-
const worker = new worker_1.Worker(hatchet, { name: 'WORKER_NAME' });
|
|
232
|
-
const startSpy = jest.spyOn(worker, 'handle_start_step_run').mockReturnValue();
|
|
233
|
-
const cancelSpy = jest.spyOn(worker, 'handle_cancel_step_run').mockReturnValue();
|
|
234
|
-
const mockActionLister = new action_listener_1.ActionListener(hatchet.dispatcher, (0, action_listener_test_1.mockListener)([mockStart, mockCancel, new nice_grpc_common_1.ServerError(nice_grpc_common_1.Status.CANCELLED, 'CANCELLED')]), 'WORKER_ID');
|
|
235
|
-
const getActionListenerSpy = jest
|
|
236
|
-
.spyOn(worker.client.dispatcher, 'get_action_listener')
|
|
237
|
-
.mockImplementationOnce(() => {
|
|
238
|
-
throw new Error('Simulated error');
|
|
239
|
-
})
|
|
240
|
-
.mockImplementationOnce(() => {
|
|
241
|
-
throw new Error('Simulated error');
|
|
242
|
-
})
|
|
243
|
-
.mockImplementationOnce(() => {
|
|
244
|
-
throw new Error('Simulated error');
|
|
245
|
-
})
|
|
246
|
-
.mockImplementationOnce(() => {
|
|
247
|
-
throw new Error('Simulated error');
|
|
248
|
-
})
|
|
249
|
-
.mockImplementationOnce(() => __awaiter(void 0, void 0, void 0, function* () { return mockActionLister; }));
|
|
250
|
-
yield worker.start();
|
|
251
|
-
expect(getActionListenerSpy).toHaveBeenCalledTimes(5);
|
|
252
|
-
expect(startSpy).toHaveBeenCalledTimes(1);
|
|
253
|
-
expect(cancelSpy).toHaveBeenCalledTimes(1);
|
|
254
|
-
}));
|
|
255
|
-
});
|
|
256
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const config_loader_1 = require("./config-loader");
|
|
4
|
-
fdescribe('ConfigLoader', () => {
|
|
5
|
-
beforeEach(() => {
|
|
6
|
-
process.env.HATCHET_CLIENT_HOST_PORT = 'HOST_PORT';
|
|
7
|
-
process.env.HATCHET_CLIENT_TLS_CERT_FILE = 'TLS_CERT_FILE';
|
|
8
|
-
process.env.HATCHET_CLIENT_TLS_KEY_FILE = 'TLS_KEY_FILE';
|
|
9
|
-
process.env.HATCHET_CLIENT_TLS_ROOT_CA_FILE = 'TLS_ROOT_CA_FILE';
|
|
10
|
-
process.env.HATCHET_CLIENT_TLS_SERVER_NAME = 'TLS_SERVER_NAME';
|
|
11
|
-
});
|
|
12
|
-
it('should load from environment variables', () => {
|
|
13
|
-
const config = config_loader_1.ConfigLoader.load_client_config();
|
|
14
|
-
expect(config).toEqual({
|
|
15
|
-
host_port: 'HOST_PORT',
|
|
16
|
-
log_level: 'INFO',
|
|
17
|
-
tls_config: {
|
|
18
|
-
tls_strategy: 'tls',
|
|
19
|
-
cert_file: 'TLS_CERT_FILE',
|
|
20
|
-
key_file: 'TLS_KEY_FILE',
|
|
21
|
-
ca_file: 'TLS_ROOT_CA_FILE',
|
|
22
|
-
server_name: 'TLS_SERVER_NAME',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
it('should throw an error if the file is not found', () => {
|
|
27
|
-
expect(() => config_loader_1.ConfigLoader.load_client_config({
|
|
28
|
-
path: './fixtures/not-found.yaml',
|
|
29
|
-
})).toThrow();
|
|
30
|
-
});
|
|
31
|
-
xit('should throw an error if the yaml file fails validation', () => {
|
|
32
|
-
expect(() =>
|
|
33
|
-
// This test is failing because there is no invalid state of the yaml file, need to update with tls and mtls settings
|
|
34
|
-
config_loader_1.ConfigLoader.load_client_config({
|
|
35
|
-
path: './fixtures/.hatchet-invalid.yaml',
|
|
36
|
-
})).toThrow();
|
|
37
|
-
});
|
|
38
|
-
it('should favor yaml config over env vars', () => {
|
|
39
|
-
const config = config_loader_1.ConfigLoader.load_client_config({
|
|
40
|
-
path: './fixtures/.hatchet.yaml',
|
|
41
|
-
});
|
|
42
|
-
expect(config).toEqual({
|
|
43
|
-
token: 'TOKEN_YAML',
|
|
44
|
-
host_port: 'HOST_PORT_YAML',
|
|
45
|
-
log_level: 'INFO',
|
|
46
|
-
tls_config: {
|
|
47
|
-
tls_strategy: 'tls',
|
|
48
|
-
cert_file: 'TLS_CERT_FILE_YAML',
|
|
49
|
-
key_file: 'TLS_KEY_FILE_YAML',
|
|
50
|
-
ca_file: 'TLS_ROOT_CA_FILE_YAML',
|
|
51
|
-
server_name: 'TLS_SERVER_NAME_YAML',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
xit('should attempt to load the root .hatchet.yaml config', () => {
|
|
56
|
-
// i'm not sure the best way to test this, maybe spy on readFileSync called with
|
|
57
|
-
const config = config_loader_1.ConfigLoader.load_client_config({
|
|
58
|
-
path: './fixtures/.hatchet.yaml',
|
|
59
|
-
});
|
|
60
|
-
expect(config).toEqual({
|
|
61
|
-
token: 'TOKEN_YAML',
|
|
62
|
-
host_port: 'HOST_PORT_YAML',
|
|
63
|
-
tls_config: {
|
|
64
|
-
tls_strategy: 'tls',
|
|
65
|
-
cert_file: 'TLS_CERT_FILE_YAML',
|
|
66
|
-
key_file: 'TLS_KEY_FILE_YAML',
|
|
67
|
-
ca_file: 'TLS_ROOT_CA_FILE_YAML',
|
|
68
|
-
server_name: 'TLS_SERVER_NAME_YAML',
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const hatchet_promise_1 = __importDefault(require("./hatchet-promise"));
|
|
16
|
-
describe('HatchetPromise', () => {
|
|
17
|
-
it('should resolve the original promise if not canceled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
|
|
19
|
-
setTimeout(() => resolve('RESOLVED'), 500);
|
|
20
|
-
}));
|
|
21
|
-
const result = yield hatchetPromise.promise;
|
|
22
|
-
expect(result).toEqual('RESOLVED');
|
|
23
|
-
}));
|
|
24
|
-
it('should resolve the cancel promise if canceled', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
-
const hatchetPromise = new hatchet_promise_1.default(new Promise((resolve) => {
|
|
26
|
-
setTimeout(() => resolve('RESOLVED'), 500);
|
|
27
|
-
}));
|
|
28
|
-
const result = hatchetPromise.promise;
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
hatchetPromise.cancel();
|
|
31
|
-
}, 100);
|
|
32
|
-
try {
|
|
33
|
-
yield result;
|
|
34
|
-
expect(true).toEqual(false); // this should not be reached
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
expect(e).toEqual(undefined);
|
|
38
|
-
}
|
|
39
|
-
}));
|
|
40
|
-
});
|