github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/redux/apiReducers.spec.ts (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import { assert } from "chai";
    12  import { generateTableID, databaseRequestToID, tableRequestToID } from "./apiReducers";
    13  import * as protos from "src/js/protos";
    14  
    15  describe("table id generator", function () {
    16    it("generates encoded db/table id", function () {
    17      const db = "&a.a.a/a.a/";
    18      const table = "/a.a/a.a.a&";
    19      assert.equal(generateTableID(db, table), encodeURIComponent(db) + "/" + encodeURIComponent(table));
    20      assert.equal(decodeURIComponent(generateTableID(db, table).split("/")[0]), db);
    21      assert.equal(decodeURIComponent(generateTableID(db, table).split("/")[1]), table);
    22    });
    23  });
    24  
    25  describe("request to string functions", function () {
    26    it("correctly generates a string from a database details request", function () {
    27      const database = "testDatabase";
    28      const databaseRequest = new protos.cockroach.server.serverpb.DatabaseDetailsRequest({ database });
    29      assert.equal(databaseRequestToID(databaseRequest), database);
    30    });
    31    it("correctly generates a string from a table details request", function () {
    32      const database = "testDatabase";
    33      const table = "testTable";
    34      const tableRequest = new protos.cockroach.server.serverpb.TableDetailsRequest({ database, table });
    35      assert.equal(tableRequestToID(tableRequest), generateTableID(database, table));
    36    });
    37  });