-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with importing Storage Emulator data with nested directory …
…structure (#4358) * Flatten imported emulator data directory structure * Add integration tests for importing emulator data * Add CHANGELOG entry * Add test for importing exported Storage Emulator data
- Loading branch information
1 parent
7757ea1
commit 3d1dd7e
Showing
12 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
7 changes: 7 additions & 0 deletions
7
...storage-emulator-integration/import/flattened-emulator-data/firebase-export-metadata.json
This file contains 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,7 @@ | ||
{ | ||
"version": "10.4.2", | ||
"storage": { | ||
"version": "10.4.2", | ||
"path": "storage_export" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
...s/storage-emulator-integration/import/flattened-emulator-data/storage_export/buckets.json
This file contains 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,7 @@ | ||
{ | ||
"buckets": [ | ||
{ | ||
"id": "fake-project-id.appspot.com" | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
...-emulator-data/storage_export/metadata/fake-project-id.appspot.com%2Ftest_upload.jpg.json
This file contains 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,20 @@ | ||
{ | ||
"name": "test_upload.jpg", | ||
"bucket": "fake-project-id.appspot.com", | ||
"contentType": "application/octet-stream", | ||
"metageneration": 1, | ||
"generation": 1648084940926, | ||
"storageClass": "STANDARD", | ||
"contentDisposition": "inline", | ||
"cacheControl": "public, max-age=3600", | ||
"contentEncoding": "identity", | ||
"downloadTokens": [ | ||
"c3c71086-95a8-445d-96e7-f625972de4b0" | ||
], | ||
"etag": "PQJQBXRweACX9yRsBEInQjOJ/0s", | ||
"timeCreated": "2022-03-24T01:22:20.926Z", | ||
"updated": "2022-03-24T01:22:20.926Z", | ||
"size": 0, | ||
"md5Hash": "1B2M2Y8AsgTpgAmY7PhCfg==", | ||
"crc32c": "0" | ||
} |
7 changes: 7 additions & 0 deletions
7
...ts/storage-emulator-integration/import/nested-emulator-data/firebase-export-metadata.json
This file contains 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,7 @@ | ||
{ | ||
"version": "10.4.2", | ||
"storage": { | ||
"version": "10.4.2", | ||
"path": "storage_export" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
scripts/storage-emulator-integration/import/nested-emulator-data/storage_export/buckets.json
This file contains 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,7 @@ | ||
{ | ||
"buckets": [ | ||
{ | ||
"id": "fake-project-id.appspot.com" | ||
} | ||
] | ||
} |
20 changes: 20 additions & 0 deletions
20
...ed-emulator-data/storage_export/metadata/fake-project-id.appspot.com/test_upload.jpg.json
This file contains 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,20 @@ | ||
{ | ||
"name": "test_upload.jpg", | ||
"bucket": "fake-project-id.appspot.com", | ||
"contentType": "application/octet-stream", | ||
"metageneration": 1, | ||
"generation": 1648084940926, | ||
"storageClass": "STANDARD", | ||
"contentDisposition": "inline", | ||
"cacheControl": "public, max-age=3600", | ||
"contentEncoding": "identity", | ||
"downloadTokens": [ | ||
"c3c71086-95a8-445d-96e7-f625972de4b0" | ||
], | ||
"etag": "PQJQBXRweACX9yRsBEInQjOJ/0s", | ||
"timeCreated": "2022-03-24T01:22:20.926Z", | ||
"updated": "2022-03-24T01:22:20.926Z", | ||
"size": 0, | ||
"md5Hash": "1B2M2Y8AsgTpgAmY7PhCfg==", | ||
"crc32c": "0" | ||
} |
This file contains 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,90 @@ | ||
import * as path from "path"; | ||
import supertest = require("supertest"); | ||
|
||
import { createTmpDir } from "../../../src/test/emulators/fixtures"; | ||
import { Emulators } from "../../../src/emulator/types"; | ||
import { TriggerEndToEndTest } from "../../integration-helpers/framework"; | ||
import { | ||
EMULATORS_SHUTDOWN_DELAY_MS, | ||
FIREBASE_EMULATOR_CONFIG, | ||
getStorageEmulatorHost, | ||
readEmulatorConfig, | ||
TEST_SETUP_TIMEOUT, | ||
} from "../utils"; | ||
|
||
describe("Import Emulator Data", () => { | ||
const FIREBASE_PROJECT = "fake-project-id"; | ||
const BUCKET = `${FIREBASE_PROJECT}.appspot.com`; | ||
const EMULATOR_CONFIG = readEmulatorConfig(FIREBASE_EMULATOR_CONFIG); | ||
const STORAGE_EMULATOR_HOST = getStorageEmulatorHost(EMULATOR_CONFIG); | ||
const test = new TriggerEndToEndTest(FIREBASE_PROJECT, __dirname, EMULATOR_CONFIG); | ||
|
||
it("retrieves file from imported flattened emulator data", async function (this) { | ||
this.timeout(TEST_SETUP_TIMEOUT); | ||
await test.startEmulators([ | ||
"--only", | ||
Emulators.STORAGE, | ||
"--import", | ||
path.join(__dirname, "flattened-emulator-data"), | ||
"--export-on-exit", | ||
path.join(__dirname, "other-emulator-data"), | ||
]); | ||
|
||
await supertest(STORAGE_EMULATOR_HOST) | ||
.get(`/v0/b/${BUCKET}/o/test_upload.jpg`) | ||
.set({ Authorization: "Bearer owner" }) | ||
.expect(200); | ||
}); | ||
|
||
it("retrieves file from imported nested emulator data", async function (this) { | ||
this.timeout(TEST_SETUP_TIMEOUT); | ||
await test.startEmulators([ | ||
"--only", | ||
Emulators.STORAGE, | ||
"--import", | ||
path.join(__dirname, "flattened-emulator-data"), | ||
]); | ||
|
||
await supertest(STORAGE_EMULATOR_HOST) | ||
.get(`/v0/b/${BUCKET}/o/test_upload.jpg`) | ||
.set({ Authorization: "Bearer owner" }) | ||
.expect(200); | ||
}); | ||
|
||
it("retrieves file from importing previously exported emulator data", async function (this) { | ||
this.timeout(TEST_SETUP_TIMEOUT); | ||
const tmpDir = createTmpDir("exported-emulator-data"); | ||
|
||
// Upload file to Storage and export emulator data to tmp directory | ||
await test.startEmulators(["--only", Emulators.STORAGE, "--export-on-exit", tmpDir]); | ||
const uploadURL = await supertest(STORAGE_EMULATOR_HOST) | ||
.post(`/v0/b/${BUCKET}/o/test_upload.jpg?uploadType=resumable&name=test_upload.jpg`) | ||
.set({ | ||
Authorization: "Bearer owner", | ||
"X-Goog-Upload-Protocol": "resumable", | ||
"X-Goog-Upload-Command": "start", | ||
}) | ||
.then((res) => new URL(res.header["x-goog-upload-url"])); | ||
|
||
await supertest(STORAGE_EMULATOR_HOST) | ||
.put(uploadURL.pathname + uploadURL.search) | ||
.set({ | ||
"X-Goog-Upload-Protocol": "resumable", | ||
"X-Goog-Upload-Command": "upload, finalize", | ||
}); | ||
|
||
await test.stopEmulators(); | ||
|
||
// Import emulator data from tmp directory and retrieve file from Storage | ||
await test.startEmulators(["--only", Emulators.STORAGE, "--import", tmpDir]); | ||
await supertest(STORAGE_EMULATOR_HOST) | ||
.get(`/v0/b/${BUCKET}/o/test_upload.jpg`) | ||
.set({ Authorization: "Bearer owner" }) | ||
.expect(200); | ||
}); | ||
|
||
afterEach(async function (this) { | ||
this.timeout(EMULATORS_SHUTDOWN_DELAY_MS); | ||
await test.stopEmulators(); | ||
}); | ||
}); |
This file contains 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 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