Skip to content

Commit

Permalink
Revert "fix: correct STORAGE_EMULATOR_HOST handling (#2069, #1314) (#…
Browse files Browse the repository at this point in the history
…2070)"

This reverts commit c75b8b8.
  • Loading branch information
danielbankhead committed Oct 19, 2022
1 parent b9fcc09 commit ff175d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
8 changes: 2 additions & 6 deletions src/storage.ts
Expand Up @@ -664,12 +664,8 @@ export class Storage extends Service {

options = Object.assign({}, options, {apiEndpoint});

// Note: EMULATOR_HOST, if present and not overridden, has been applied to
// `options` at this point. Also, this uses string concatenation because the
// endpoint may contain a base path, and any trailing slash on that will
// have been removed, so using the two-arg URL constructor for relative path
// resolution won't work.
const baseUrl = new URL(options.apiEndpoint + '/storage/v1').href;
// Note: EMULATOR_HOST is an experimental configuration variable. Use apiEndpoint instead.
const baseUrl = EMULATOR_HOST || `${options.apiEndpoint}/storage/v1`;

const config = {
apiEndpoint: options.apiEndpoint!,
Expand Down
22 changes: 5 additions & 17 deletions test/index.ts
Expand Up @@ -435,33 +435,27 @@ describe('Storage', () => {
delete process.env.STORAGE_EMULATOR_HOST;
});

it('should set baseUrl to env var STORAGE_EMULATOR_HOST plus standard path', () => {
it('should set baseUrl to env var STORAGE_EMULATOR_HOST', () => {
const storage = new Storage({
projectId: PROJECT_ID,
});

const calledWith = storage.calledWith_[0];
assert.strictEqual(calledWith.baseUrl, EMULATOR_HOST + '/storage/v1');
assert.strictEqual(calledWith.baseUrl, EMULATOR_HOST);
assert.strictEqual(
calledWith.apiEndpoint,
'https://internal.benchmark.com/path'
);
});

it('should be overridden by apiEndpoint', () => {
it('should be overriden by apiEndpoint', () => {
const storage = new Storage({
projectId: PROJECT_ID,
apiEndpoint: 'https://some.api.com',
});

const calledWith = storage.calledWith_[0];
// NOTE: this used to assert partially the opposite of what the test
// says: it checked that baseUrl was _not_ overridden, but apiEndpoint
// was.
assert.strictEqual(
calledWith.baseUrl,
'https://some.api.com/storage/v1'
);
assert.strictEqual(calledWith.baseUrl, EMULATOR_HOST);
assert.strictEqual(calledWith.apiEndpoint, 'https://some.api.com');
});

Expand All @@ -474,13 +468,7 @@ describe('Storage', () => {
});

const calledWith = storage.calledWith_[0];
// NOTE: this used to assert partially the opposite of what the test
// says: it checked that baseUrl was _not_ overridden, but apiEndpoint
// was.
assert.strictEqual(
calledWith.baseUrl,
'https://internal.benchmark.com/path/storage/v1'
);
assert.strictEqual(calledWith.baseUrl, EMULATOR_HOST);
assert.strictEqual(
calledWith.apiEndpoint,
'https://internal.benchmark.com/path'
Expand Down

0 comments on commit ff175d0

Please sign in to comment.