Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest # Or specify a version like "1.1.0"
bun-version: ^1.3.9

- name: Install dependencies
run: bun install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
bun-version: ^1.3.9

- name: Setup Node.js for npm publishing
uses: actions/setup-node@v4
Expand Down
2 changes: 0 additions & 2 deletions test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ beforeAll(() => {
const originalConsole = { ...console };
console.log = () => {};
console.warn = () => {};
console.error = () => {};

// Restore console after tests
afterAll(() => {
console.log = originalConsole.log;
console.warn = originalConsole.warn;
console.error = originalConsole.error;
});
});
8 changes: 4 additions & 4 deletions test/cex-broker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ describe("CEXBroker", () => {
delete process.env.CEX_BROKER_BINANCE_API_SECRET_1;
});

afterEach(() => {
afterEach(async () => {
if (broker) {
broker.stop();
await broker.stop();
}
});

Expand Down Expand Up @@ -209,9 +209,9 @@ describe("CEXBroker", () => {
expect(startedBroker).toBe(broker);
});

test("should stop server successfully", () => {
test("should stop server successfully", async () => {
broker = new CEXBroker({}, testPolicy);
broker.stop();
await broker.stop();
expect(broker).toBeDefined();
});

Expand Down
14 changes: 5 additions & 9 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { readFileSync } from "node:fs";
import { describe, expect, test } from "bun:test";

describe("Integration Tests", () => {
describe("Policy Integration", () => {
test("should load and validate policy correctly", () => {
// Test that the policy file can be loaded
const fs = require("bun:fs");
const path = require("bun:path");
const policyPath = path.join(__dirname, "../policy/policy.json");
const policyPath = new URL("../policy/policy.json", import.meta.url);

expect(() => {
const policyData = fs.readFileSync(policyPath, "utf8");
const policyData = readFileSync(policyPath, "utf8");
const policy = JSON.parse(policyData);
return policy;
}).not.toThrow();
});

test("should have correct policy structure", () => {
const fs = require("bun:fs");
const path = require("bun:path");
const policyPath = path.join(__dirname, "../policy/policy.json");
const policyData = fs.readFileSync(policyPath, "utf8");
const policyPath = new URL("../policy/policy.json", import.meta.url);
const policyData = readFileSync(policyPath, "utf8");
const policy = JSON.parse(policyData);

// Check withdraw policy
Expand Down
21 changes: 14 additions & 7 deletions test/otel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,65 +27,72 @@ describe("OtelMetrics", () => {
});

describe("Initialization", () => {
test("should be enabled when hostname is provided", () => {
test("should be enabled when hostname is provided", async () => {
const config: OtelConfig = {
host: "localhost",
port: 8123,
};
const metrics = new OtelMetrics(config);
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});

test("should use default values when optional config is missing", () => {
test("should use default values when optional config is missing", async () => {
const config: OtelConfig = {
host: "localhost",
};
const metrics = new OtelMetrics(config);
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});

test("should handle initialization errors gracefully", () => {
test("should handle initialization errors gracefully", async () => {
const config: OtelConfig = {
host: "invalid://host",
port: 8123,
};
const metrics = new OtelMetrics(config);
expect(metrics).toBeDefined();
await metrics.close();
});
});

describe("createOtelMetricsFromEnv", () => {
test("should create metrics from CEX_BROKER_OTEL_* env vars", () => {
test("should create metrics from CEX_BROKER_OTEL_* env vars", async () => {
process.env.CEX_BROKER_OTEL_HOST = "localhost";
process.env.CEX_BROKER_OTEL_PORT = "8123";
process.env.CEX_BROKER_OTEL_PROTOCOL = "https";

const metrics = createOtelMetricsFromEnv();
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});

test("should create metrics from legacy CEX_BROKER_CLICKHOUSE_* env vars", () => {
test("should create metrics from legacy CEX_BROKER_CLICKHOUSE_* env vars", async () => {
process.env.CEX_BROKER_CLICKHOUSE_HOST = "localhost";
process.env.CEX_BROKER_CLICKHOUSE_PORT = "8123";
process.env.CEX_BROKER_CLICKHOUSE_PROTOCOL = "https";

const metrics = createOtelMetricsFromEnv();
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});

test("should use default values for optional env vars", () => {
test("should use default values for optional env vars", async () => {
process.env.CEX_BROKER_OTEL_HOST = "localhost";

const metrics = createOtelMetricsFromEnv();
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});

test("should prefer OTEL_EXPORTER_OTLP_ENDPOINT when set", () => {
test("should prefer OTEL_EXPORTER_OTLP_ENDPOINT when set", async () => {
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "http://collector:4318";
process.env.CEX_BROKER_OTEL_HOST = "legacy-host";

const metrics = createOtelMetricsFromEnv();
expect(metrics.isOtelEnabled()).toBe(true);
await metrics.close();
});
});

Expand Down
Loading