@@ -24,19 +24,17 @@ var prop = require('propprop');
2424var proxyquire = require ( 'proxyquire' ) ;
2525var stream = require ( 'stream' ) ;
2626
27- var File = require ( '@google-cloud/storage' ) . File ;
2827var ServiceObject = require ( '@google-cloud/common' ) . ServiceObject ;
2928var util = require ( '@google-cloud/common' ) . util ;
3029
31- function FakeFile ( a , b ) {
32- this . request = util . noop ;
33- File . call ( this , a , b ) ;
34- }
35-
3630var makeWritableStreamOverride ;
31+ var isCustomTypeOverride ;
3732var fakeUtil = extend ( { } , util , {
33+ isCustomType : function ( ) {
34+ return ( isCustomTypeOverride || util . isCustomType ) . apply ( null , arguments ) ;
35+ } ,
3836 makeWritableStream : function ( ) {
39- var args = [ ] . slice . call ( arguments ) ;
37+ var args = arguments ;
4038 ( makeWritableStreamOverride || util . makeWritableStream ) . apply ( null , args ) ;
4139 }
4240} ) ;
@@ -70,7 +68,8 @@ describe('BigQuery/Table', function() {
7068 projectId : 'project-id' ,
7169 job : function ( id ) {
7270 return { id : id } ;
73- }
71+ } ,
72+ request : util . noop
7473 }
7574 } ;
7675
@@ -98,9 +97,6 @@ describe('BigQuery/Table', function() {
9897
9998 before ( function ( ) {
10099 Table = proxyquire ( '../src/table.js' , {
101- '@google-cloud/storage' : {
102- File : FakeFile
103- } ,
104100 '@google-cloud/common' : {
105101 ServiceObject : FakeServiceObject ,
106102 streamRouter : fakeStreamRouter ,
@@ -125,9 +121,11 @@ describe('BigQuery/Table', function() {
125121 } ) ;
126122
127123 beforeEach ( function ( ) {
124+ isCustomTypeOverride = null ;
128125 makeWritableStreamOverride = null ;
129126 tableOverrides = { } ;
130127 table = new Table ( DATASET , TABLE_ID ) ;
128+ table . bigQuery . request = util . noop ;
131129 } ) ;
132130
133131 describe ( 'instantiation' , function ( ) {
@@ -480,12 +478,18 @@ describe('BigQuery/Table', function() {
480478 } ) ;
481479
482480 describe ( 'export' , function ( ) {
483- var FILE = new FakeFile ( {
484- name : 'bucket-name' ,
485- makeReq_ : util . noop ,
486- } , 'file.json' ) ;
481+ var FILE = {
482+ name : 'file-name.json' ,
483+ bucket : {
484+ name : 'bucket-name'
485+ }
486+ } ;
487487
488488 beforeEach ( function ( ) {
489+ isCustomTypeOverride = function ( ) {
490+ return true ;
491+ } ;
492+
489493 table . bigQuery . job = function ( id ) {
490494 return { id : id } ;
491495 } ;
@@ -555,10 +559,25 @@ describe('BigQuery/Table', function() {
555559 done ( ) ;
556560 } ;
557561
558- table . export ( FILE , done ) ;
562+ table . export ( FILE , assert . ifError ) ;
563+ } ) ;
564+
565+ it ( 'should check if a destination is a File' , function ( done ) {
566+ isCustomTypeOverride = function ( dest , type ) {
567+ assert . strictEqual ( dest , FILE ) ;
568+ assert . strictEqual ( type , 'storage/file' ) ;
569+ setImmediate ( done ) ;
570+ return true ;
571+ } ;
572+
573+ table . export ( FILE , assert . ifError ) ;
559574 } ) ;
560575
561576 it ( 'should throw if a destination is not a File' , function ( ) {
577+ isCustomTypeOverride = function ( ) {
578+ return false ;
579+ } ;
580+
562581 assert . throws ( function ( ) {
563582 table . export ( { } , util . noop ) ;
564583 } , / D e s t i n a t i o n m u s t b e a F i l e o b j e c t / ) ;
@@ -794,10 +813,18 @@ describe('BigQuery/Table', function() {
794813
795814 describe ( 'import' , function ( ) {
796815 var FILEPATH = require . resolve ( './testdata/testfile.json' ) ;
797- var FILE = new FakeFile ( {
798- name : 'bucket-name' ,
799- makeReq_ : util . noop
800- } , 'file.json' ) ;
816+ var FILE = {
817+ name : 'file-name.json' ,
818+ bucket : {
819+ name : 'bucket-name'
820+ }
821+ } ;
822+
823+ beforeEach ( function ( ) {
824+ isCustomTypeOverride = function ( ) {
825+ return true ;
826+ } ;
827+ } ) ;
801828
802829 it ( 'should accept just a File and a callback' , function ( done ) {
803830 var mockJob = { id : 'foo' } ;
@@ -873,7 +900,22 @@ describe('BigQuery/Table', function() {
873900 table . import ( FILEPATH , { sourceFormat : 'CSV' } , done ) ;
874901 } ) ;
875902
903+ it ( 'should check if a destination is a File' , function ( done ) {
904+ isCustomTypeOverride = function ( dest , type ) {
905+ assert . strictEqual ( dest , FILE ) ;
906+ assert . strictEqual ( type , 'storage/file' ) ;
907+ setImmediate ( done ) ;
908+ return true ;
909+ } ;
910+
911+ table . export ( FILE , assert . ifError ) ;
912+ } ) ;
913+
876914 it ( 'should throw if a File object is not provided' , function ( ) {
915+ isCustomTypeOverride = function ( ) {
916+ return false ;
917+ } ;
918+
877919 assert . throws ( function ( ) {
878920 table . import ( { } ) ;
879921 } , / S o u r c e m u s t b e a F i l e o b j e c t / ) ;
0 commit comments