-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
S3 Improvements #738
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
S3 Improvements #738
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -1,29 +1,33 @@ | ||
var FilesController = require('../src/Controllers/FilesController').FilesController; | ||
var GridStoreAdapter = require("../src/Adapters/Files/GridStoreAdapter").GridStoreAdapter; | ||
var S3Adapter = require("../src/Adapters/Files/S3Adapter").S3Adapter; | ||
var Config = require("../src/Config"); | ||
|
||
var FCTestFactory = require("./FilesControllerTestFactory"); | ||
|
||
|
||
// Small additional tests to improve overall coverage | ||
describe("FilesController",()=>{ | ||
|
||
it("should properly expand objects", (done) => { | ||
var config = new Config(Parse.applicationId); | ||
var adapter = new GridStoreAdapter(); | ||
var filesController = new FilesController(adapter); | ||
var result = filesController.expandFilesInObject(config, function(){}); | ||
// Test the grid store adapter | ||
var gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse'); | ||
FCTestFactory.testAdapter("GridStoreAdapter", gridStoreAdapter); | ||
|
||
if (process.env.S3_ACCESS_KEY && process.env.S3_SECRET_KEY) { | ||
|
||
// Test the S3 Adapter | ||
var s3Adapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests'); | ||
|
||
expect(result).toBeUndefined(); | ||
FCTestFactory.testAdapter("S3Adapter",s3Adapter); | ||
|
||
var fullFile = { | ||
type: '__type', | ||
url: "http://an.url" | ||
} | ||
// Test S3 with direct access | ||
var s3DirectAccessAdapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests', { | ||
directAccess: true | ||
}); | ||
|
||
var anObject = { | ||
aFile: fullFile | ||
} | ||
filesController.expandFilesInObject(config, anObject); | ||
expect(anObject.aFile.url).toEqual("http://an.url"); | ||
FCTestFactory.testAdapter("S3AdapterDirect", s3DirectAccessAdapter); | ||
|
||
done(); | ||
}) | ||
}) | ||
} else if (!process.env.TRAVIS) { | ||
console.log("set S3_ACCESS_KEY and S3_SECRET_KEY to test S3Adapter") | ||
} | ||
}); |
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,73 @@ | ||
|
||
var FilesController = require('../src/Controllers/FilesController').FilesController; | ||
var Config = require("../src/Config"); | ||
|
||
var testAdapter = function(name, adapter) { | ||
// Small additional tests to improve overall coverage | ||
|
||
var config = new Config(Parse.applicationId); | ||
var filesController = new FilesController(adapter); | ||
|
||
describe("FilesController with "+name,()=>{ | ||
|
||
it("should properly expand objects", (done) => { | ||
|
||
var result = filesController.expandFilesInObject(config, function(){}); | ||
|
||
expect(result).toBeUndefined(); | ||
|
||
var fullFile = { | ||
type: '__type', | ||
url: "http://an.url" | ||
} | ||
|
||
var anObject = { | ||
aFile: fullFile | ||
} | ||
filesController.expandFilesInObject(config, anObject); | ||
expect(anObject.aFile.url).toEqual("http://an.url"); | ||
|
||
done(); | ||
}) | ||
|
||
it("should properly create, read, delete files", (done) => { | ||
var filename; | ||
filesController.createFile(config, "file.txt", "hello world").then( (result) => { | ||
ok(result.url); | ||
ok(result.name); | ||
filename = result.name; | ||
expect(result.name.match(/file.txt/)).not.toBe(null); | ||
return filesController.getFileData(config, filename); | ||
}, (err) => { | ||
fail("The adapter should create the file"); | ||
console.error(err); | ||
done(); | ||
}).then((result) => { | ||
expect(result instanceof Buffer).toBe(true); | ||
expect(result.toString('utf-8')).toEqual("hello world"); | ||
return filesController.deleteFile(config, filename); | ||
}, (err) => { | ||
fail("The adapter should get the file"); | ||
console.error(err); | ||
done(); | ||
}).then((result) => { | ||
|
||
filesController.getFileData(config, filename).then((res) => { | ||
fail("the file should be deleted"); | ||
done(); | ||
}, (err) => { | ||
done(); | ||
}); | ||
|
||
}, (err) => { | ||
fail("The adapter should delete the file"); | ||
console.error(err); | ||
done(); | ||
}); | ||
}, 5000); // longer tests | ||
}); | ||
} | ||
|
||
module.exports = { | ||
testAdapter: testAdapter | ||
} |
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.
Since this is sort of breaking - can we add this to the docs on FilesAdapter?
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.
yeppa