Skip to content

Commit 0a6fec7

Browse files
tests: fix snippet tests in sandbox env (#2199)
1 parent b410e30 commit 0a6fec7

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

handwritten/logging/src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ Logging.prototype.getEntries = function(options, callback) {
346346
Logging.prototype.getEntriesStream = function(options) {
347347
var self = this;
348348

349+
options = options || {};
350+
349351
var requestStream;
350352

351353
var userStream = streamEvents(pumpify.obj());
@@ -616,6 +618,10 @@ Logging.prototype.request = function(config, callback) {
616618
}
617619

618620
function makeRequestCallback() {
621+
if (global.GCLOUD_SANDBOX_ENV) {
622+
return;
623+
}
624+
619625
prepareGaxRequest(function(err, requestFn) {
620626
if (err) {
621627
callback(err);
@@ -627,6 +633,10 @@ Logging.prototype.request = function(config, callback) {
627633
}
628634

629635
function makeRequestStream() {
636+
if (global.GCLOUD_SANDBOX_ENV) {
637+
return through.obj();
638+
}
639+
630640
prepareGaxRequest(function(err, requestFn) {
631641
if (err) {
632642
stream.destroy(err);

handwritten/logging/test/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ describe('Logging', function() {
591591

592592
stream.abort();
593593
});
594+
595+
it('should not require an options object', function() {
596+
assert.doesNotThrow(function() {
597+
var stream = logging.getEntriesStream();
598+
stream.emit('reading');
599+
});
600+
});
594601
});
595602

596603
describe('getSinks', function() {
@@ -889,6 +896,19 @@ describe('Logging', function() {
889896
});
890897

891898
describe('makeRequestCallback', function() {
899+
it('should return if in snippet sandbox', function(done) {
900+
logging.auth.getProjectId = function() {
901+
done(new Error('Should not have gotten project ID.'));
902+
};
903+
904+
global.GCLOUD_SANDBOX_ENV = true;
905+
var returnValue = logging.request(CONFIG, assert.ifError);
906+
delete global.GCLOUD_SANDBOX_ENV;
907+
908+
assert.strictEqual(returnValue, undefined);
909+
done();
910+
});
911+
892912
it('should prepare the request', function(done) {
893913
logging.api[CONFIG.client][CONFIG.method] = {
894914
bind: function(gaxClient, reqOpts, gaxOpts) {
@@ -944,6 +964,20 @@ describe('Logging', function() {
944964
};
945965
});
946966

967+
it('should return if in snippet sandbox', function(done) {
968+
logging.auth.getProjectId = function() {
969+
done(new Error('Should not have gotten project ID.'));
970+
};
971+
972+
global.GCLOUD_SANDBOX_ENV = true;
973+
var returnValue = logging.request(CONFIG);
974+
returnValue.emit('reading');
975+
delete global.GCLOUD_SANDBOX_ENV;
976+
977+
assert(returnValue instanceof require('stream'));
978+
done();
979+
});
980+
947981
it('should expose an abort function', function(done) {
948982
GAX_STREAM.cancel = done;
949983

0 commit comments

Comments
 (0)