-
Notifications
You must be signed in to change notification settings - Fork 933
Add Storage Integration tests #3414
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
25dc07c
Add Storage Integration tests
schmidt-sebastian 1a07d8d
Create strange-lions-dress.md
schmidt-sebastian 19c0e18
Cleanup
schmidt-sebastian 9b8faed
Merge branch 'mrschmidt/storagetest' of github.com:firebase/firebase-…
schmidt-sebastian 6dca9b0
Lint
schmidt-sebastian 1024015
Update base64.ts
schmidt-sebastian 9b92abb
Fix build
schmidt-sebastian a2bc97a
Merge branch 'mrschmidt/storagetest' of github.com:firebase/firebase-…
schmidt-sebastian 088b404
Next round
schmidt-sebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@firebase/storage": patch | ||
--- | ||
|
||
Error messages for backend errors now include the backend's reponse message. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,11 @@ export class FirebaseStorageError implements Error { | |
} | ||
|
||
get message(): string { | ||
return this.message_; | ||
if (this.serverResponse_) { | ||
return this.message_ + '\n' + this.serverResponse_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this so that the server response shows up in the error message for "unknown" errors. |
||
} else { | ||
return this.message_; | ||
} | ||
} | ||
|
||
get serverResponse(): null | string { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import firebase from '@firebase/app'; | ||
import '@firebase/auth'; | ||
|
||
// See https://github.com/typescript-eslint/typescript-eslint/issues/363 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import * as storage from '@firebase/storage-types'; | ||
|
||
import { expect } from 'chai'; | ||
import '../../index'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const PROJECT_CONFIG = require('../../../../config/project.json'); | ||
|
||
export const PROJECT_ID = PROJECT_CONFIG.projectId; | ||
export const STORAGE_BUCKET = PROJECT_CONFIG.storageBucket; | ||
export const API_KEY = PROJECT_CONFIG.apiKey; | ||
|
||
let appCount = 0; | ||
|
||
export async function withTestInstance( | ||
fn: (storage: storage.FirebaseStorage) => void | Promise<void> | ||
): Promise<void> { | ||
const app = firebase.initializeApp( | ||
{ apiKey: API_KEY, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET }, | ||
'test-app-' + appCount++ | ||
); | ||
await firebase.auth!(app).signInAnonymously(); | ||
const storage = firebase.storage!(app); | ||
return fn(storage); | ||
} | ||
|
||
describe('FirebaseStorage', () => { | ||
it('can upload bytes', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/bytes'); | ||
await ref.put(new Uint8Array([0, 1, 3])); | ||
}); | ||
}); | ||
|
||
it('can upload string', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/string'); | ||
await ref.putString('foo'); | ||
}); | ||
}); | ||
|
||
it('validates operations on root', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref(''); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
ref.putString('foo'); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e.message).to.satisfy((v: string) => | ||
v.match( | ||
/The operation 'putString' cannot be performed on a root reference/ | ||
) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
it('can delete object ', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/delete'); | ||
await ref.putString('foo'); | ||
|
||
// getDownloadURL() succeeds for an existing object | ||
await ref.getDownloadURL(); | ||
|
||
await ref.delete(); | ||
try { | ||
// getDownloadURL() fails for a deleted object | ||
await ref.getDownloadURL(); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e.message).to.satisfy((v: string) => | ||
v.match(/Object 'public\/delete' does not exist/) | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
it('can get download URL', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/downloadurl'); | ||
await ref.put(new Uint8Array([0, 1, 3])); | ||
const url = await ref.getDownloadURL(); | ||
expect(url).to.satisfy((v: string) => | ||
v.match( | ||
/https:\/\/firebasestorage\.googleapis\.com\/v0\/b\/.*\/o\/public%2Fdownloadurl/ | ||
) | ||
); | ||
}); | ||
}); | ||
|
||
it('can get metadata', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/getmetadata'); | ||
await ref.put(new Uint8Array([0, 1, 3])); | ||
const metadata = await ref.getMetadata(); | ||
expect(metadata.name).to.equal('getmetadata'); | ||
}); | ||
}); | ||
|
||
it('can update metadata', () => { | ||
return withTestInstance(async storage => { | ||
const ref = storage.ref('public/updatemetadata'); | ||
await ref.put(new Uint8Array([0, 1, 3])); | ||
const metadata = await ref.updateMetadata({ | ||
customMetadata: { foo: 'bar' } | ||
}); | ||
expect(metadata.customMetadata).to.deep.equal({ foo: 'bar' }); | ||
}); | ||
}); | ||
|
||
it('can list files', () => { | ||
return withTestInstance(async storage => { | ||
await storage.ref('public/list/a').putString(''); | ||
await storage.ref('public/list/b').putString(''); | ||
await storage.ref('public/list/c/d').putString(''); | ||
const listResult = await storage.ref('public/list').listAll(); | ||
expect(listResult.items.map(v => v.name)).to.have.members(['a', 'b']); | ||
expect(listResult.prefixes.map(v => v.name)).to.have.members(['c']); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see Github Actions has inlined this ts error from the build log ('uint8ArrayFromBinaryString' is defined but never used) so that's cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this line.