diff --git a/src/firestore/api-types.ts b/src/firestore/api-types.ts index 701d7e4097c..826cc1ff401 100644 --- a/src/firestore/api-types.ts +++ b/src/firestore/api-types.ts @@ -121,6 +121,12 @@ export enum PointInTimeRecoveryEnablement { DISABLED = "POINT_IN_TIME_RECOVERY_DISABLED", } +export enum DatabaseEdition { + DATABASE_EDITION_UNSPECIFIED = "DATABASE_EDITION_UNSPECIFIED", + STANDARD = "STANDARD", + ENTERPRISE = "ENTERPRISE", +} + export interface DatabaseReq { locationId?: string; type?: DatabaseType; @@ -155,6 +161,7 @@ export interface DatabaseResp { versionRetentionPeriod: string; earliestVersionTime: string; cmekConfig?: CmekConfig; + databaseEdition?: DatabaseEdition; } export interface RestoreDatabaseReq { diff --git a/src/firestore/pretty-print.spec.ts b/src/firestore/pretty-print.spec.ts index 81b637d902c..17eb755b34c 100644 --- a/src/firestore/pretty-print.spec.ts +++ b/src/firestore/pretty-print.spec.ts @@ -1,6 +1,8 @@ import { expect } from "chai"; +import * as sinon from "sinon"; import * as API from "./api-types"; import { PrettyPrint } from "./pretty-print"; +import { logger } from "../logger"; const printer = new PrettyPrint(); @@ -92,3 +94,77 @@ describe("prettyStringArray", () => { expect(printer.prettyStringArray([])).to.equal(""); }); }); + +describe("prettyPrintDatabase", () => { + let loggerInfoStub: sinon.SinonStub; + + const BASE_DATABASE: API.DatabaseResp = { + name: "projects/my-project/databases/(default)", + uid: "uid", + createTime: "2020-01-01T00:00:00Z", + updateTime: "2020-01-01T00:00:00Z", + locationId: "us-central1", + type: API.DatabaseType.FIRESTORE_NATIVE, + concurrencyMode: "OPTIMISTIC", + appEngineIntegrationMode: "ENABLED", + keyPrefix: "prefix", + deleteProtectionState: API.DatabaseDeleteProtectionState.DISABLED, + pointInTimeRecoveryEnablement: API.PointInTimeRecoveryEnablement.DISABLED, + etag: "etag", + versionRetentionPeriod: "1h", + earliestVersionTime: "2020-01-01T00:00:00Z", + }; + + beforeEach(() => { + loggerInfoStub = sinon.stub(logger, "info"); + }); + + afterEach(() => { + loggerInfoStub.restore(); + }); + + it("should display STANDARD edition when databaseEdition is not provided", () => { + const database: API.DatabaseResp = { ...BASE_DATABASE }; + + printer.prettyPrintDatabase(database); + + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); + }); + + it("should display STANDARD edition when databaseEdition is UNSPECIFIED", () => { + const database: API.DatabaseResp = { + ...BASE_DATABASE, + databaseEdition: API.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED, + }; + + printer.prettyPrintDatabase(database); + + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); + }); + + it("should display ENTERPRISE edition when databaseEdition is ENTERPRISE", () => { + const database: API.DatabaseResp = { + ...BASE_DATABASE, + databaseEdition: API.DatabaseEdition.ENTERPRISE, + }; + + printer.prettyPrintDatabase(database); + + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); + expect(loggerInfoStub.firstCall.args[0]).to.include("ENTERPRISE"); + }); + + it("should display STANDARD edition when databaseEdition is STANDARD", () => { + const database: API.DatabaseResp = { + ...BASE_DATABASE, + databaseEdition: API.DatabaseEdition.STANDARD, + }; + + printer.prettyPrintDatabase(database); + + expect(loggerInfoStub.firstCall.args[0]).to.include("Edition"); + expect(loggerInfoStub.firstCall.args[0]).to.include("STANDARD"); + }); +}); diff --git a/src/firestore/pretty-print.ts b/src/firestore/pretty-print.ts index e285a1c8b5f..f3f265ea93b 100644 --- a/src/firestore/pretty-print.ts +++ b/src/firestore/pretty-print.ts @@ -59,11 +59,17 @@ export class PrettyPrint { colWidths: [30, colValueWidth], }); + const edition = + !database.databaseEdition || + database.databaseEdition === types.DatabaseEdition.DATABASE_EDITION_UNSPECIFIED + ? types.DatabaseEdition.STANDARD + : database.databaseEdition; table.push( ["Name", clc.yellow(database.name)], ["Create Time", clc.yellow(database.createTime)], ["Last Update Time", clc.yellow(database.updateTime)], ["Type", clc.yellow(database.type)], + ["Edition", clc.yellow(edition)], ["Location", clc.yellow(database.locationId)], ["Delete Protection State", clc.yellow(database.deleteProtectionState)], ["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)],