Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage emulator env formatting #1257

Merged
merged 6 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ export class Storage implements StorageInterface {
}

if (!process.env.STORAGE_EMULATOR_HOST && process.env.FIREBASE_STORAGE_EMULATOR_HOST) {
process.env.STORAGE_EMULATOR_HOST = process.env.FIREBASE_STORAGE_EMULATOR_HOST;
const firebaseStorageEmulatorHost = process.env.FIREBASE_STORAGE_EMULATOR_HOST;

if (firebaseStorageEmulatorHost.match(/https?:\/\//)) {
throw new FirebaseError({
code: 'storage/invalid-emulator-host',
message: 'FIREBASE_STORAGE_EMULATOR_HOST should not contain a protocol (http or https).',
});
}

process.env.STORAGE_EMULATOR_HOST = `http://${process.env.FIREBASE_STORAGE_EMULATOR_HOST}`;
}

let storage: typeof StorageClient;
Expand Down
11 changes: 7 additions & 4 deletions test/unit/storage/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,20 @@ describe('Storage', () => {
});

describe('Emulator mode', () => {
const EMULATOR_HOST = 'http://localhost:9199';
const EMULATOR_HOST = 'localhost:9199';

before(() => {
delete process.env.STORAGE_EMULATOR_HOST;
process.env.FIREBASE_STORAGE_EMULATOR_HOST = EMULATOR_HOST;
});

it('sets STORAGE_EMULATOR_HOST if FIREBASE_STORAGE_EMULATOR_HOST is set', () => {
new Storage(mockApp);

expect(process.env.STORAGE_EMULATOR_HOST).to.equal(EMULATOR_HOST);
new Storage(mockApp)
expect(process.env.STORAGE_EMULATOR_HOST).to.equal(`http://${EMULATOR_HOST}`);
});

it('throws if FIREBASE_STORAGE_EMULATOR_HOST has a protocol', () => {
abeisgoat marked this conversation as resolved.
Show resolved Hide resolved
expect(() => new Storage(mockApp)).to.throw;
});

after(() => {
Expand Down