mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Cosmetic clean-up of GCS Persistor & tests
This commit is contained in:
@@ -139,11 +139,11 @@ async function getFileStream(bucketName, key, opts = {}) {
|
||||
|
||||
async function getFileSize(bucketName, key) {
|
||||
try {
|
||||
const metadata = await storage
|
||||
const [metadata] = await storage
|
||||
.bucket(bucketName)
|
||||
.file(key)
|
||||
.getMetadata()
|
||||
return metadata[0].size
|
||||
return metadata.size
|
||||
} catch (err) {
|
||||
throw PersistorHelper.wrapError(
|
||||
err,
|
||||
@@ -156,11 +156,11 @@ async function getFileSize(bucketName, key) {
|
||||
|
||||
async function getFileMd5Hash(bucketName, key) {
|
||||
try {
|
||||
const metadata = await storage
|
||||
const [metadata] = await storage
|
||||
.bucket(bucketName)
|
||||
.file(key)
|
||||
.getMetadata()
|
||||
return PersistorHelper.base64ToHex(metadata[0].md5Hash)
|
||||
return PersistorHelper.base64ToHex(metadata.md5Hash)
|
||||
} catch (err) {
|
||||
throw PersistorHelper.wrapError(
|
||||
err,
|
||||
@@ -194,10 +194,10 @@ async function deleteDirectory(bucketName, key) {
|
||||
let files
|
||||
|
||||
try {
|
||||
const response = await storage
|
||||
const [response] = await storage
|
||||
.bucket(bucketName)
|
||||
.getFiles({ directory: key })
|
||||
files = response[0]
|
||||
files = response
|
||||
} catch (err) {
|
||||
const error = PersistorHelper.wrapError(
|
||||
err,
|
||||
@@ -232,10 +232,10 @@ async function directorySize(bucketName, key) {
|
||||
let files
|
||||
|
||||
try {
|
||||
const response = await storage
|
||||
const [response] = await storage
|
||||
.bucket(bucketName)
|
||||
.getFiles({ directory: key })
|
||||
files = response[0]
|
||||
files = response
|
||||
} catch (err) {
|
||||
throw PersistorHelper.wrapError(
|
||||
err,
|
||||
@@ -250,11 +250,11 @@ async function directorySize(bucketName, key) {
|
||||
|
||||
async function checkIfFileExists(bucketName, key) {
|
||||
try {
|
||||
const response = await storage
|
||||
const [response] = await storage
|
||||
.bucket(bucketName)
|
||||
.file(key)
|
||||
.exists()
|
||||
return response[0]
|
||||
return response
|
||||
} catch (err) {
|
||||
throw PersistorHelper.wrapError(
|
||||
err,
|
||||
|
||||
@@ -21,7 +21,7 @@ describe('GcsPersistorTests', function() {
|
||||
Logger,
|
||||
Storage,
|
||||
Fs,
|
||||
NotFoundError,
|
||||
GcsNotFoundError,
|
||||
Meter,
|
||||
MeteredStream,
|
||||
ReadStream,
|
||||
@@ -94,8 +94,8 @@ describe('GcsPersistorTests', function() {
|
||||
}
|
||||
Storage.prototype.bucket = sinon.stub().returns(GcsBucket)
|
||||
|
||||
NotFoundError = new Error('File not found')
|
||||
NotFoundError.code = 404
|
||||
GcsNotFoundError = new Error('File not found')
|
||||
GcsNotFoundError.code = 404
|
||||
|
||||
Fs = {
|
||||
createReadStream: sinon.stub().returns(ReadStream)
|
||||
@@ -199,7 +199,7 @@ describe('GcsPersistorTests', function() {
|
||||
|
||||
beforeEach(async function() {
|
||||
ReadStream.on = sinon.stub()
|
||||
ReadStream.on.withArgs('error').yields(NotFoundError)
|
||||
ReadStream.on.withArgs('error').yields(GcsNotFoundError)
|
||||
try {
|
||||
stream = await GcsPersistor.promises.getFileStream(bucket, key)
|
||||
} catch (err) {
|
||||
@@ -278,7 +278,7 @@ describe('GcsPersistorTests', function() {
|
||||
let error
|
||||
|
||||
beforeEach(async function() {
|
||||
GcsFile.getMetadata = sinon.stub().rejects(NotFoundError)
|
||||
GcsFile.getMetadata = sinon.stub().rejects(GcsNotFoundError)
|
||||
try {
|
||||
await GcsPersistor.promises.getFileSize(bucket, key)
|
||||
} catch (err) {
|
||||
@@ -291,7 +291,7 @@ describe('GcsPersistorTests', function() {
|
||||
})
|
||||
|
||||
it('should wrap the error', function() {
|
||||
expect(error.cause).to.equal(NotFoundError)
|
||||
expect(error.cause).to.equal(GcsNotFoundError)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -443,10 +443,10 @@ describe('GcsPersistorTests', function() {
|
||||
})
|
||||
|
||||
describe('copyFile', function() {
|
||||
const DestinationFile = 'destFile'
|
||||
const destinationFile = 'destFile'
|
||||
|
||||
beforeEach(function() {
|
||||
GcsBucket.file.withArgs(destKey).returns(DestinationFile)
|
||||
GcsBucket.file.withArgs(destKey).returns(destinationFile)
|
||||
})
|
||||
|
||||
describe('with valid parameters', function() {
|
||||
@@ -457,7 +457,7 @@ describe('GcsPersistorTests', function() {
|
||||
it('should copy the object', function() {
|
||||
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
|
||||
expect(GcsBucket.file).to.have.been.calledWith(key)
|
||||
expect(GcsFile.copy).to.have.been.calledWith(DestinationFile)
|
||||
expect(GcsFile.copy).to.have.been.calledWith(destinationFile)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -465,7 +465,7 @@ describe('GcsPersistorTests', function() {
|
||||
let error
|
||||
|
||||
beforeEach(async function() {
|
||||
GcsFile.copy = sinon.stub().rejects(NotFoundError)
|
||||
GcsFile.copy = sinon.stub().rejects(GcsNotFoundError)
|
||||
try {
|
||||
await GcsPersistor.promises.copyFile(bucket, key, destKey)
|
||||
} catch (err) {
|
||||
@@ -496,7 +496,7 @@ describe('GcsPersistorTests', function() {
|
||||
let error
|
||||
|
||||
beforeEach(async function() {
|
||||
GcsFile.delete = sinon.stub().rejects(NotFoundError)
|
||||
GcsFile.delete = sinon.stub().rejects(GcsNotFoundError)
|
||||
try {
|
||||
await GcsPersistor.promises.deleteFile(bucket, key)
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user