-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathdeploy.spec.ts
More file actions
95 lines (86 loc) · 3.15 KB
/
Copy pathdeploy.spec.ts
File metadata and controls
95 lines (86 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { expect } from "chai";
import * as sinon from "sinon";
import nock from "../../test/helpers/nock";
import * as deploy from "./deploy";
import * as utils from "../../utils";
import * as projectUtils from "../../projectUtils";
import * as provisionCloudSql from "../../dataconnect/provisionCloudSql";
import * as ensureApiEnabled from "../../ensureApiEnabled";
import * as poller from "../../operation-poller";
import { dataconnectOrigin } from "../../api";
import { initDeployStats } from "./context";
describe("dataconnect deploy", () => {
let sandbox: sinon.SinonSandbox;
let setupCloudSqlStub: sinon.SinonStub;
let pollOperationStub: sinon.SinonStub;
beforeEach(() => {
sandbox = sinon.createSandbox();
setupCloudSqlStub = sandbox.stub(provisionCloudSql, "setupCloudSql").resolves();
sandbox.stub(projectUtils, "needProjectId").returns("test-project");
sandbox.stub(ensureApiEnabled, "ensure").resolves();
sandbox.stub(utils, "logLabeledSuccess");
pollOperationStub = sandbox.stub(poller, "pollOperation").resolves();
});
afterEach(() => {
sandbox.restore();
nock.cleanAll();
});
it("should create a new service", async () => {
nock(dataconnectOrigin())
.get("/v1/projects/test-project/locations/-/services")
.reply(200, { services: [] });
nock(dataconnectOrigin())
.post("/v1/projects/test-project/locations/l/services?service_id=s1")
.reply(200, { name: "op-name" });
const serviceInfos = [
{
serviceName: "projects/test-project/locations/l/services/s1",
deploymentMetadata: {},
schemas: [
{
name: "projects/test-project/locations/l/services/s1/schemas/main",
datasources: [],
},
],
dataConnectYaml: { serviceId: "s1" },
},
];
const context = { dataconnect: { serviceInfos, deployStats: initDeployStats() } };
const options = {} as any;
await deploy.default(context as any, options);
expect(pollOperationStub.calledOnce).to.be.true;
expect(nock.isDone()).to.be.true;
});
it("should provision cloud sql", async () => {
nock(dataconnectOrigin())
.get("/v1/projects/test-project/locations/-/services")
.reply(200, { services: [] });
nock(dataconnectOrigin())
.post("/v1/projects/test-project/locations/l/services?service_id=s1")
.reply(200, { name: "op-name" });
const serviceInfos = [
{
serviceName: "projects/test-project/locations/l/services/s1",
schemas: [
{
name: "projects/test-project/locations/l/services/s1/schemas/main",
datasources: [
{
postgresql: {
cloudSql: { instance: "projects/p/locations/l/instances/i" },
database: "db",
},
},
],
},
],
deploymentMetadata: {},
dataConnectYaml: { serviceId: "s1" },
},
];
const context = { dataconnect: { serviceInfos, deployStats: initDeployStats() } };
const options = {} as any;
await deploy.default(context as any, options);
expect(setupCloudSqlStub.calledOnce).to.be.true;
});
});