@adpt/cloud
Version:
AdaptJS cloud component library
77 lines • 3.41 kB
JavaScript
"use strict";
/*
* Copyright 2019 Unbounded Systems, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = tslib_1.__importStar(require("@adpt/core"));
const Container_1 = require("../Container");
const NetworkService_1 = require("../NetworkService");
const Service_1 = require("../Service");
const PreloadedPostgresImage_1 = require("./PreloadedPostgresImage");
/**
* A component suitable for creating test scenarios that creates a simple,
* temporary Postgres database that loads test data from a .sql file and
* which implements the abstract {@link postgres.Postgres} interface.
*
* @remarks
*
* Implements the {@link ConnectToInstance} interface.
*
* Instance methods:
*
* - `connectEnv(scope?: NetworkScope): Environment | undefined`
*
* Returns the set of environment variables that have all the information
* needed for a Postgres client to connect to this database. The
* returned environment variables are named such that some common Postgres
* clients can use them directly:
*
* `PGHOST`: The host to connect to.
*
* `PGDATABASE`: The name of the database.
*
* `PGUSER`: Username to use to authenticate to the database server or service.
*
* `PGPASSWORD`: Password to use to authenticate to the database server or service.
*
* @public
*/
function TestPostgres(props) {
const bProps = props;
const dbCtr = core_1.handle();
const svc = core_1.handle();
core_1.useImperativeMethods(() => ({
connectEnv: (scope) => {
const svcHostname = core_1.callInstanceMethod(svc, undefined, "hostname", scope);
if (!svcHostname)
return undefined;
return [
{ name: "PGHOST", value: svcHostname },
{ name: "PGDATABASE", value: bProps.mockDbName },
{ name: "PGUSER", value: "postgres" },
{ name: "PGPASSWORD", value: "hello" }
];
}
}));
const img = core_1.handle();
return core_1.default.createElement(core_1.Sequence, { key: bProps.key },
core_1.default.createElement(PreloadedPostgresImage_1.PreloadedPostgresImage, { key: bProps.key + "-img", handle: img, mockDbName: bProps.mockDbName, mockDataPath: bProps.mockDataPath }),
core_1.default.createElement(Service_1.Service, { key: bProps.key },
core_1.default.createElement(NetworkService_1.NetworkService, { key: bProps.key + "-netsvc", handle: svc, scope: "cluster-internal", endpoint: dbCtr, port: 5432 }),
core_1.default.createElement(Container_1.Container, { key: bProps.key, name: "db", handle: dbCtr, image: img, environment: { POSTGRES_PASSWORD: "hello" }, imagePullPolicy: "Never", ports: [5432] })));
}
exports.TestPostgres = TestPostgres;
//# sourceMappingURL=TestPostgres.js.map