Skip to content

Commit

Permalink
test: debug
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Nov 13, 2024
1 parent da0032d commit a2f9225
Showing 1 changed file with 86 additions and 86 deletions.
172 changes: 86 additions & 86 deletions packages/grpc/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
IClientOptions
} from '../src';

import { Metadata } from '@grpc/grpc-js';
import { hello } from './fixtures/base-app-multiple-package/src/interface';
// import { Metadata } from '@grpc/grpc-js';
// import { hello } from './fixtures/base-app-multiple-package/src/interface';

export namespace hero {
export interface HeroServiceClient {
Expand Down Expand Up @@ -84,77 +84,77 @@ describe('/test/index.test.ts', function () {
await closeApp(app);
});

it('should create gRPC server', async () => {
const app = await createServer('base-app');

const service = await createGRPCConsumer<helloworld.GreeterClient>({
package: 'helloworld',
protoPath: join(__dirname, 'fixtures/proto/helloworld.proto'),
url: 'localhost:6565'
});

const meta = new Metadata();
meta.add('key', 'value');

const result = await service.sayHello({
metadata: meta,
}).sendMessage({
name: 'harry'
});

expect(result).toEqual({ message: 'Hello harry' });

const serverMetadata = await new Promise<Metadata>((resolve, reject) => {
const call = service.sayHello().sendMessageWithCallback({
name: 'zhangting'
}, (err) => {
if (err) {
reject(err);
}
});
call.on('metadata', (meta) => {
resolve(meta);
});
})

expect(serverMetadata.get('Set-Cookie')[0]).toEqual('yummy_cookie=choco');
await closeApp(app);
});

it('should create multiple grpc service in one server', async () => {
const app = await createServer('base-app-multiple-service');
const opts = {
package: 'hero',
protoPath: join(__dirname, 'fixtures/proto/hero.proto'),
url: 'localhost:6575'
}
const service = await createGRPCConsumer<hero.HeroServiceClient>({ ...opts, });
const result = await service.findOne().sendMessage({ id: 123 });
expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' })
await closeApp(app);
});

it('should create multiple grpc service in one server 2', async () => {
const app = await createServer('base-app-multiple-service-2');
const opts = {
package: 'hero2',
protoPath: join(__dirname, 'fixtures/proto/hero2.proto'),
url: 'localhost:6566'
}

const service = await createGRPCConsumer<hero2.HeroServiceClient>({ ...opts, });
const result = await service.findOne().sendMessage({ id: 123 });
expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' })

const service2 = await createGRPCConsumer<hero2.HeroService2Client>({ service: 'HeroService2', ...opts, });
const result2 = await service2.findOne2().sendMessage({ id: 123 });
expect(result2).toEqual({ id: 1, name: 'bbbb-Hello harry' })

const service3 = await createGRPCConsumer<hero2.HeroService2Client>({ ...opts, service: 'hero2.HeroService2' });
const result3 = await service3.findOne2().sendMessage({ id: 123 });
expect(result3).toEqual({ id: 1, name: 'bbbb-Hello harry' })
await closeApp(app);
});
// it('should create gRPC server', async () => {
// const app = await createServer('base-app');

// const service = await createGRPCConsumer<helloworld.GreeterClient>({
// package: 'helloworld',
// protoPath: join(__dirname, 'fixtures/proto/helloworld.proto'),
// url: 'localhost:6565'
// });

// const meta = new Metadata();
// meta.add('key', 'value');

// const result = await service.sayHello({
// metadata: meta,
// }).sendMessage({
// name: 'harry'
// });

// expect(result).toEqual({ message: 'Hello harry' });

// const serverMetadata = await new Promise<Metadata>((resolve, reject) => {
// const call = service.sayHello().sendMessageWithCallback({
// name: 'zhangting'
// }, (err) => {
// if (err) {
// reject(err);
// }
// });
// call.on('metadata', (meta) => {
// resolve(meta);
// });
// })

// expect(serverMetadata.get('Set-Cookie')[0]).toEqual('yummy_cookie=choco');
// await closeApp(app);
// });

// it('should create multiple grpc service in one server', async () => {
// const app = await createServer('base-app-multiple-service');
// const opts = {
// package: 'hero',
// protoPath: join(__dirname, 'fixtures/proto/hero.proto'),
// url: 'localhost:6575'
// }
// const service = await createGRPCConsumer<hero.HeroServiceClient>({ ...opts, });
// const result = await service.findOne().sendMessage({ id: 123 });
// expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' })
// await closeApp(app);
// });

// it('should create multiple grpc service in one server 2', async () => {
// const app = await createServer('base-app-multiple-service-2');
// const opts = {
// package: 'hero2',
// protoPath: join(__dirname, 'fixtures/proto/hero2.proto'),
// url: 'localhost:6566'
// }

// const service = await createGRPCConsumer<hero2.HeroServiceClient>({ ...opts, });
// const result = await service.findOne().sendMessage({ id: 123 });
// expect(result).toEqual({ id: 1, name: 'bbbb-Hello harry' })

// const service2 = await createGRPCConsumer<hero2.HeroService2Client>({ service: 'HeroService2', ...opts, });
// const result2 = await service2.findOne2().sendMessage({ id: 123 });
// expect(result2).toEqual({ id: 1, name: 'bbbb-Hello harry' })

// const service3 = await createGRPCConsumer<hero2.HeroService2Client>({ ...opts, service: 'hero2.HeroService2' });
// const result3 = await service3.findOne2().sendMessage({ id: 123 });
// expect(result3).toEqual({ id: 1, name: 'bbbb-Hello harry' })
// await closeApp(app);
// });

it('should support publish stream gRPC server', async () => {
const app = await createServer('base-app-stream');
Expand Down Expand Up @@ -352,20 +352,20 @@ describe('/test/index.test.ts', function () {
await closeApp(app);
});

it('should test multi-package service', async () => {
const app = await createServer('base-app-multiple-package');
// it('should test multi-package service', async () => {
// const app = await createServer('base-app-multiple-package');

const service = await createGRPCConsumer<hello.world.GreeterClient>({
package: 'hello.world',
protoPath: join(__dirname, 'fixtures/proto/hello_world.proto'),
url: 'localhost:6569'
});
// const service = await createGRPCConsumer<hello.world.GreeterClient>({
// package: 'hello.world',
// protoPath: join(__dirname, 'fixtures/proto/hello_world.proto'),
// url: 'localhost:6569'
// });

const result = await service.sayHello().sendMessage({
name: 'harry'
});
// const result = await service.sayHello().sendMessage({
// name: 'harry'
// });

expect(result).toEqual({ message: 'Hello harry' });
await closeApp(app);
});
// expect(result).toEqual({ message: 'Hello harry' });
// await closeApp(app);
// });
});

0 comments on commit a2f9225

Please sign in to comment.