Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/modules/nats/src/nats-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,41 @@ describe("NatsContainer", { timeout: 180_000 }, () => {
});
// }

it("should start, connect and close using scratch image", async () => {
const container = await new NatsContainer("nats:2.11").start();

// establish connection
const nc = await connect(container.getConnectionOptions());
// close the connection
await nc.close();
// check if the close was OK
const err = await nc.closed();
expect(err).toBe(undefined);

await container.stop();
});

// pubsub {
it("should subscribe and receive one published message", async () => {
const SUBJECT = "HELLO";
const PAYLOAD = "WORLD";

const container = await new NatsContainer().start();
const nc = await connect(container.getConnectionOptions());
const TE = new TextEncoder();
const TD = new TextDecoder();

//----------------
const sub = nc.subscribe(SUBJECT);
(async () => {
for await (const m of sub) {
const actual: string = m.string();
const actual = TD.decode(m.data);
expect(actual).toEqual(PAYLOAD);
}
})().then();

//----------------
nc.publish(SUBJECT, PAYLOAD);
nc.publish(SUBJECT, TE.encode(PAYLOAD));

//----------------
await nc.drain();
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/nats/src/nats-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class NatsContainer extends GenericContainer {
}

private getNormalizedCommand(): string[] {
const result: string[] = ["nats-server"];
const result: string[] = [];
for (const arg of this.args) {
result.push(arg);
if (this.values.has(arg)) {
Expand Down