Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.9 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { defaultMqPolicyForms, policyAccessFromEffectivePolicies, policyFormsFromEffectivePolicies } from "@/lib/mq/mqPolicyForms";

describe("mqPolicyForms", () => {
  it("keeps ordinary policy responses available", () => {
    expect(policyAccessFromEffectivePolicies({ configs: {} })).toEqual({
      readable: true,
      unsupportedReason: undefined,
    });
  });

  it("marks legacy Kafka configuration responses as unavailable with a reason", () => {
    expect(
      policyAccessFromEffectivePolicies({
        configs: {},
        configSupported: false,
        unsupportedReason: "The broker does not support DescribeConfigs.",
      }),
    ).toEqual({
      readable: false,
      unsupportedReason: "The broker does not support DescribeConfigs.",
    });
  });

  it("hydrates forms from topic effective policies", () => {
    const forms = policyFormsFromEffectivePolicies(
      {
        level: "topic",
        topicPolicies: {
          publishRate: {
            publishThrottlingRateInMsg: 100,
            publishThrottlingRateInByte: 2048,
          },
          dispatchRate: {
            dispatchThrottlingRateInMsg: 50,
            dispatchThrottlingRateInByte: 1024,
            ratePeriodInSecond: 5,
          },
          backlogQuota: {
            limitSize: 4096,
            limitTime: 60,
            policy: "producer_exception",
            quotaType: "message_age",
          },
          retention: {
            retentionTimeInMinutes: 120,
            retentionSizeInMB: 512,
          },
        },
      },
      defaultMqPolicyForms(),
    );

    expect(forms.publishForm.publishThrottlingRateInMsg).toBe(100);
    expect(forms.dispatchForm.ratePeriodInSecond).toBe(5);
    expect(forms.backlogForm.quotaType).toBe("message_age");
    expect(forms.retentionForm.retentionSizeInMb).toBe(512);
  });

  it("hydrates forms from namespace Pulsar policies shape", () => {
    const forms = policyFormsFromEffectivePolicies(
      {
        publishRate: {
          publishThrottlingRateInMsg: 20,
          publishThrottlingRateInByte: 3000,
        },
        subscribeRate: {
          subscribeThrottlingRatePerConsumer: 12,
          ratePeriodInSecond: 3,
        },
        backlog_quota_map: {
          destination_storage: {
            limitSize: 999,
            limitTime: 10,
            policy: "consumer_backlog_eviction",
          },
        },
        retention_policies: {
          retentionTimeInMinutes: 30,
          retentionSizeInMB: 64,
        },
      },
      defaultMqPolicyForms(),
    );

    expect(forms.publishForm.publishThrottlingRateInByte).toBe(3000);
    expect(forms.subscribeForm.ratePeriodInSecond).toBe(3);
    expect(forms.backlogForm.limitSize).toBe(999);
    expect(forms.backlogForm.quotaType).toBe("destination_storage");
    expect(forms.retentionForm.retentionTimeInMinutes).toBe(30);
  });
});