1
- import util from 'node:util' ;
2
- import path from 'node:path' ;
3
- import assert from 'node:assert' ;
1
+ import * as util from 'node:util' ;
2
+ import * as path from 'node:path' ;
4
3
import test from 'ava' ;
5
4
import { Subject , firstValueFrom , skip } from 'rxjs' ;
6
5
import * as grpc from '@grpc/grpc-js' ;
@@ -9,19 +8,6 @@ import { NativeConnection } from '@temporalio/worker';
9
8
import { temporal } from '@temporalio/proto' ;
10
9
import { Worker } from './helpers' ;
11
10
12
- const workflowServicePackageDefinition = protoLoader . loadSync (
13
- path . resolve (
14
- __dirname ,
15
- '../../core-bridge/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto'
16
- ) ,
17
- { includeDirs : [ path . resolve ( __dirname , '../../core-bridge/sdk-core/sdk-core-protos/protos/api_upstream' ) ] }
18
- ) ;
19
- const workflowServiceProtoDescriptor = grpc . loadPackageDefinition ( workflowServicePackageDefinition ) as any ;
20
-
21
- async function bindLocalhost ( server : grpc . Server ) : Promise < number > {
22
- return await util . promisify ( server . bindAsync . bind ( server ) ) ( '127.0.0.1:0' , grpc . ServerCredentials . createInsecure ( ) ) ;
23
- }
24
-
25
11
test ( 'NativeConnection passes headers provided in options' , async ( t ) => {
26
12
const packageDefinition = protoLoader . loadSync (
27
13
path . resolve (
@@ -103,44 +89,3 @@ test('NativeConnection passes headers provided in options', async (t) => {
103
89
} ) ;
104
90
await Promise . all ( [ firstValueFrom ( newValuesSubject . pipe ( skip ( 1 ) ) ) . then ( ( ) => worker . shutdown ( ) ) , worker . run ( ) ] ) ;
105
91
} ) ;
106
-
107
- test ( 'apiKey sets temporal-namespace header appropriately' , async ( t ) => {
108
- let getSystemInfoHeaders : grpc . Metadata = new grpc . Metadata ( ) ;
109
- let startWorkflowExecutionHeaders : grpc . Metadata = new grpc . Metadata ( ) ;
110
-
111
- const server = new grpc . Server ( ) ;
112
- server . addService ( workflowServiceProtoDescriptor . temporal . api . workflowservice . v1 . WorkflowService . service , {
113
- getSystemInfo (
114
- call : grpc . ServerUnaryCall <
115
- temporal . api . workflowservice . v1 . IGetSystemInfoRequest ,
116
- temporal . api . workflowservice . v1 . IGetSystemInfoResponse
117
- > ,
118
- callback : grpc . sendUnaryData < temporal . api . workflowservice . v1 . IGetSystemInfoResponse >
119
- ) {
120
- getSystemInfoHeaders = call . metadata . clone ( ) ;
121
- callback ( null , { } ) ;
122
- } ,
123
- startWorkflowExecution ( call : grpc . ServerUnaryCall < any , any > , callback : grpc . sendUnaryData < any > ) {
124
- startWorkflowExecutionHeaders = call . metadata . clone ( ) ;
125
- callback ( null , { } ) ;
126
- } ,
127
- } ) ;
128
- const port = await bindLocalhost ( server ) ;
129
- const conn = await NativeConnection . connect ( {
130
- address : `127.0.0.1:${ port } ` ,
131
- metadata : { staticKey : 'set' } ,
132
- apiKey : 'test-token' ,
133
- } ) ;
134
-
135
- await conn . workflowService . startWorkflowExecution ( { namespace : 'test-namespace' } ) ;
136
-
137
- assert ( getSystemInfoHeaders !== undefined ) ;
138
- t . deepEqual ( getSystemInfoHeaders . get ( 'temporal-namespace' ) , [ ] ) ;
139
- t . deepEqual ( getSystemInfoHeaders . get ( 'authorization' ) , [ 'Bearer test-token' ] ) ;
140
- t . deepEqual ( getSystemInfoHeaders . get ( 'staticKey' ) , [ 'set' ] ) ;
141
-
142
- assert ( startWorkflowExecutionHeaders ) ;
143
- t . deepEqual ( startWorkflowExecutionHeaders . get ( 'temporal-namespace' ) , [ 'test-namespace' ] ) ;
144
- t . deepEqual ( startWorkflowExecutionHeaders . get ( 'authorization' ) , [ 'Bearer test-token' ] ) ;
145
- t . deepEqual ( startWorkflowExecutionHeaders . get ( 'staticKey' ) , [ 'set' ] ) ;
146
- } ) ;
0 commit comments