|
21 | 21 | // SOFTWARE. |
22 | 22 |
|
23 | 23 | import { expect } from "chai"; |
24 | | -import * as fs from "fs"; |
25 | | -import * as process from "process"; |
26 | | -import * as sinon from "sinon"; |
27 | 24 |
|
28 | | -import { config, resetCache } from "../../src/v1/config"; |
| 25 | +import { config } from "../../src/v1/config"; |
29 | 26 |
|
30 | 27 | describe("config()", () => { |
31 | | - let readFileSync: sinon.SinonStub; |
32 | | - let cwdStub: sinon.SinonStub; |
33 | | - |
34 | | - before(() => { |
35 | | - readFileSync = sinon.stub(fs, "readFileSync"); |
36 | | - readFileSync.throws("Unexpected call"); |
37 | | - cwdStub = sinon.stub(process, "cwd"); |
38 | | - cwdStub.returns("/srv"); |
39 | | - }); |
40 | | - |
41 | | - after(() => { |
42 | | - sinon.verifyAndRestore(); |
43 | | - }); |
44 | | - |
45 | | - afterEach(() => { |
46 | | - resetCache(); |
47 | | - delete process.env.FIREBASE_CONFIG; |
48 | | - delete process.env.CLOUD_RUNTIME_CONFIG; |
49 | | - delete process.env.K_CONFIGURATION; |
50 | | - }); |
51 | | - |
52 | | - it("will never load in GCFv2", () => { |
53 | | - const json = JSON.stringify({ |
54 | | - foo: "bar", |
55 | | - firebase: {}, |
56 | | - }); |
57 | | - readFileSync.withArgs("/srv/.runtimeconfig.json").returns(Buffer.from(json)); |
58 | | - |
59 | | - process.env.K_CONFIGURATION = "my-service"; |
60 | | - expect(config).to.throw(Error, /transition to using environment variables/); |
61 | | - }); |
62 | | - |
63 | | - it("loads config values from .runtimeconfig.json", () => { |
64 | | - const json = JSON.stringify({ |
65 | | - foo: "bar", |
66 | | - firebase: {}, |
67 | | - }); |
68 | | - readFileSync.withArgs("/srv/.runtimeconfig.json").returns(Buffer.from(json)); |
69 | | - const loaded = config(); |
70 | | - expect(loaded).to.not.have.property("firebase"); |
71 | | - expect(loaded).to.have.property("foo", "bar"); |
| 28 | + it("throws an error with migration guidance", () => { |
| 29 | + expect(config).to.throw( |
| 30 | + Error, |
| 31 | + "functions.config() has been removed in firebase-functions v7. " + |
| 32 | + "Migrate to environment parameters using the params module. " + |
| 33 | + "Migration guide: https://firebase.google.com/docs/functions/config-env#migrate-config" |
| 34 | + ); |
72 | 35 | }); |
73 | 36 | }); |
0 commit comments