Skip to content

Commit

Permalink
Fix issues with GCS datastore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjap committed Jun 9, 2021
1 parent 698918b commit 6e3473c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
9 changes: 5 additions & 4 deletions test/Test-EndToEnd.js
Expand Up @@ -431,10 +431,11 @@ describe('EndToEnd', () => {
}).catch(done);
});

// The pipe method must not call the end function or otherwise
// we cannot inject the callback into the end function for write_stream
// which is needed for supertest.
read_stream.pipe(write_stream, { end: false });
// Using .pipe() broke when upgrading to Superagent 3.0+,
// so now we use data events to read the file to the agent.
read_stream.on('data', (chunk) => {
write_stream.write(chunk);
});
read_stream.on("end", () => {
write_stream.end(() => {});
});
Expand Down
22 changes: 12 additions & 10 deletions test/Test-GCSDataStore.js
Expand Up @@ -139,7 +139,7 @@ describe('GCSDataStore', () => {
assert.equal(file instanceof File, true);
assert.equal(file.upload_length, TEST_FILE_SIZE);
return done();
}).catch(console.log);
}).catch(done);
});

it(`should fire the ${EVENTS.EVENT_FILE_CREATED} event`, (done) => {
Expand All @@ -158,7 +158,7 @@ describe('GCSDataStore', () => {
.then((file) => {
files_created.push(file.id);
})
.catch(console.log);
.catch(done);
});
});

Expand All @@ -181,7 +181,7 @@ describe('GCSDataStore', () => {
assert.equal(offset, TEST_FILE_SIZE);
return done();
})
.catch(console.log);
.catch(done);
});

it('should open a stream and resolve the new offset with continuation', (done) => {
Expand All @@ -205,7 +205,7 @@ describe('GCSDataStore', () => {
return done();
})
})
.catch(console.log);
.catch(done);
});

it(`should fire the ${EVENTS.EVENT_UPLOAD_COMPLETE} event`, (done) => {
Expand All @@ -226,7 +226,7 @@ describe('GCSDataStore', () => {
const write_stream = fs.createReadStream(TEST_FILE_PATH);
return server.datastore.write(write_stream, file.id, 0)
})
.catch(console.log);
.catch(done);
});
});

Expand All @@ -236,7 +236,7 @@ describe('GCSDataStore', () => {
.should.be.rejectedWith(ERRORS.FILE_NOT_FOUND);
});

it('should resolve existing files with the metadata', () => {
it('should resolve existing files with the metadata', (done) => {
const req = {
headers: {
'upload-length': TEST_FILE_SIZE,
Expand All @@ -252,10 +252,12 @@ describe('GCSDataStore', () => {
return server.datastore.getOffset(file.id)
})
})
.should.be.fulfilledWith({
size: TEST_FILE_SIZE,
upload_length: TEST_FILE_SIZE,
});
.then((offset) => {
assert.equal(offset.size, TEST_FILE_SIZE);
assert.equal(offset.upload_length, TEST_FILE_SIZE);
done();
})
.catch(done)
});
});
});

0 comments on commit 6e3473c

Please sign in to comment.