|
| 1 | +import { expect } from "chai"; |
| 2 | +import * as sinon from "sinon"; |
| 3 | +import * as yaml from "js-yaml"; |
| 4 | + |
| 5 | +import * as exportIac from "./export"; |
| 6 | +import * as runtimes from "../../deploy/functions/runtimes"; |
| 7 | +import * as supported from "../../deploy/functions/runtimes/supported"; |
| 8 | +import * as functionsConfig from "../../functionsConfig"; |
| 9 | +import * as functionsEnv from "../../functions/env"; |
| 10 | +import * as projectUtils from "../../projectUtils"; |
| 11 | +import * as projectConfig from "../projectConfig"; |
| 12 | +describe("export", () => { |
| 13 | + let needProjectIdStub: sinon.SinonStub; |
| 14 | + |
| 15 | + const mockDelegate = { |
| 16 | + language: "nodejs", |
| 17 | + runtime: "nodejs18", |
| 18 | + validate: sinon.stub(), |
| 19 | + build: sinon.stub(), |
| 20 | + discoverBuild: sinon.stub(), |
| 21 | + }; |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + sinon.stub(functionsConfig, "getFirebaseConfig").resolves({ projectId: "my-project" }); |
| 25 | + sinon.stub(functionsEnv, "loadFirebaseEnvs").returns({}); |
| 26 | + sinon.stub(runtimes, "getRuntimeDelegate").resolves(mockDelegate as any); |
| 27 | + sinon.stub(supported, "guardVersionSupport"); |
| 28 | + needProjectIdStub = sinon.stub(projectUtils, "needProjectId").returns("my-project"); |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(() => { |
| 32 | + sinon.restore(); |
| 33 | + mockDelegate.validate.reset(); |
| 34 | + mockDelegate.build.reset(); |
| 35 | + mockDelegate.discoverBuild.reset(); |
| 36 | + }); |
| 37 | + |
| 38 | + describe("getInternalIac", () => { |
| 39 | + it("should return functions.yaml with discovered build", async () => { |
| 40 | + const mockBuild = { endpoints: { "my-func": { platform: "gcfv1" } } }; |
| 41 | + mockDelegate.discoverBuild.resolves(mockBuild); |
| 42 | + |
| 43 | + const options = { config: { path: (s: string) => s, projectDir: "dir" } }; |
| 44 | + const codebase: projectConfig.ValidatedSingle = { |
| 45 | + source: "src", |
| 46 | + codebase: "default", |
| 47 | + runtime: "nodejs18", |
| 48 | + }; |
| 49 | + |
| 50 | + const result = await exportIac.getInternalIac(options, codebase); |
| 51 | + |
| 52 | + expect(needProjectIdStub.calledOnce).to.be.true; |
| 53 | + expect(mockDelegate.validate.calledOnce).to.be.true; |
| 54 | + expect(mockDelegate.build.calledOnce).to.be.true; |
| 55 | + expect(mockDelegate.discoverBuild.calledOnce).to.be.true; |
| 56 | + expect(result).to.deep.equal({ |
| 57 | + "functions.yaml": yaml.dump(mockBuild), |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments