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: Relax validation of FIRESTORE_EMULATOR_HOST in settings() #703

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ export class Firestore {
if (url.port !== '' && settings.port === undefined) {
settings.port = Number(url.port);
}
// We need to remove the `host` setting, in case a user calls `settings()`,
// which will again enforce that `host` and `servicePath` are not both
// specified.
delete settings.host;
}

if (settings.ssl !== undefined) {
Expand Down
20 changes: 19 additions & 1 deletion dev/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,32 @@ describe('instantiation', () => {
}).to.throw('Cannot set both "settings.host" and "settings.servicePath".');
});

it('FIRESTORE_EMULATOR_HOST ignores servicePath', () => {
const oldValue = process.env.FIRESTORE_EMULATOR_HOST;

try {
process.env.FIRESTORE_EMULATOR_HOST = 'foo';
const firestore = new Firestore.Firestore({servicePath: 'bar'});
// The call to `settings()` used to throw ("Cannot set both 'settings.host' and 'settings.servicePath'").
// See https://github.com/googleapis/nodejs-firestore/pull/696#issuecomment-505822099
firestore.settings({});
} finally {
if (oldValue) {
process.env.FIRESTORE_EMULATOR_HOST = oldValue;
} else {
delete process.env.FIRESTORE_EMULATOR_HOST;
}
}
});

it('FIRESTORE_EMULATOR_HOST overrides other endpoint', done => {
const oldValue = process.env.FIRESTORE_EMULATOR_HOST;

try {
process.env.FIRESTORE_EMULATOR_HOST = 'new';
const firestore = new Firestore.Firestore({servicePath: 'old'});
firestore['validateAndApplySettings'] = settings => {
expect(settings.host).to.equal('new');
expect(settings.servicePath).to.equal('new');
done();
};
firestore.settings({});
Expand Down