@@ -63,6 +63,8 @@ describe('PubSub', function() {
63
63
var pubsub ;
64
64
var OPTIONS = { projectId : PROJECT_ID } ;
65
65
66
+ var PUBSUB_EMULATOR_HOST = process . env . PUBSUB_EMULATOR_HOST ;
67
+
66
68
before ( function ( ) {
67
69
mockery . registerMock ( '../../lib/common/grpc-service.js' , FakeGrpcService ) ;
68
70
mockery . registerMock ( '../../lib/common/stream-router.js' , fakeStreamRouter ) ;
@@ -75,10 +77,15 @@ describe('PubSub', function() {
75
77
warnOnUnregistered : false
76
78
} ) ;
77
79
80
+ delete process . env . PUBSUB_EMULATOR_HOST ;
78
81
PubSub = require ( '../../lib/pubsub' ) ;
79
82
} ) ;
80
83
81
84
after ( function ( ) {
85
+ if ( PUBSUB_EMULATOR_HOST ) {
86
+ process . env . PUBSUB_EMULATOR_HOST = PUBSUB_EMULATOR_HOST ;
87
+ }
88
+
82
89
mockery . deregisterAll ( ) ;
83
90
mockery . disable ( ) ;
84
91
} ) ;
@@ -127,6 +134,10 @@ describe('PubSub', function() {
127
134
] ) ;
128
135
} ) ;
129
136
137
+ it ( 'should set the defaultBaseUrl_' , function ( ) {
138
+ assert . strictEqual ( pubsub . defaultBaseUrl_ , 'pubsub.googleapis.com' ) ;
139
+ } ) ;
140
+
130
141
it ( 'should use the PUBSUB_EMULATOR_HOST env var' , function ( ) {
131
142
var pubSubHost = 'pubsub-host' ;
132
143
process . env . PUBSUB_EMULATOR_HOST = pubSubHost ;
@@ -719,39 +730,40 @@ describe('PubSub', function() {
719
730
delete process . env . PUBSUB_EMULATOR_HOST ;
720
731
} ) ;
721
732
722
- it ( 'should default to pubsub.googleapis.com' , function ( ) {
723
- pubsub . determineBaseUrl_ ( ) ;
733
+ it ( 'should default to defaultBaseUrl_' , function ( ) {
734
+ var defaultBaseUrl_ = 'defaulturl' ;
735
+ pubsub . defaultBaseUrl_ = defaultBaseUrl_ ;
724
736
725
- var expectedBaseUrl = ' pubsub.googleapis.com' ;
726
- assert . strictEqual ( pubsub . baseUrl , expectedBaseUrl ) ;
737
+ pubsub . determineBaseUrl_ ( ) ;
738
+ assert . strictEqual ( pubsub . baseUrl_ , defaultBaseUrl_ ) ;
727
739
} ) ;
728
740
729
741
it ( 'should remove slashes from the baseUrl' , function ( ) {
730
742
var expectedBaseUrl = 'localhost:8080' ;
731
743
732
744
setHost ( 'localhost:8080/' ) ;
733
745
pubsub . determineBaseUrl_ ( ) ;
734
- assert . strictEqual ( pubsub . baseUrl , expectedBaseUrl ) ;
746
+ assert . strictEqual ( pubsub . baseUrl_ , expectedBaseUrl ) ;
735
747
736
748
setHost ( 'localhost:8080//' ) ;
737
749
pubsub . determineBaseUrl_ ( ) ;
738
- assert . strictEqual ( pubsub . baseUrl , expectedBaseUrl ) ;
750
+ assert . strictEqual ( pubsub . baseUrl_ , expectedBaseUrl ) ;
739
751
} ) ;
740
752
741
753
it ( 'should remove the protocol if specified' , function ( ) {
742
754
setHost ( 'http://localhost:8080' ) ;
743
755
pubsub . determineBaseUrl_ ( ) ;
744
- assert . strictEqual ( pubsub . baseUrl , 'localhost:8080' ) ;
756
+ assert . strictEqual ( pubsub . baseUrl_ , 'localhost:8080' ) ;
745
757
746
758
setHost ( 'https://localhost:8080' ) ;
747
759
pubsub . determineBaseUrl_ ( ) ;
748
- assert . strictEqual ( pubsub . baseUrl , 'localhost:8080' ) ;
760
+ assert . strictEqual ( pubsub . baseUrl_ , 'localhost:8080' ) ;
749
761
} ) ;
750
762
751
- it ( 'should not set customEndpoint when using default endpoint ' , function ( ) {
763
+ it ( 'should not set customEndpoint_ when using default baseurl ' , function ( ) {
752
764
var pubsub = new PubSub ( { projectId : PROJECT_ID } ) ;
753
765
pubsub . determineBaseUrl_ ( ) ;
754
- assert . strictEqual ( pubsub . customEndpoint , undefined ) ;
766
+ assert . strictEqual ( pubsub . customEndpoint_ , undefined ) ;
755
767
} ) ;
756
768
757
769
describe ( 'with PUBSUB_EMULATOR_HOST environment variable' , function ( ) {
@@ -767,12 +779,12 @@ describe('PubSub', function() {
767
779
768
780
it ( 'should use the PUBSUB_EMULATOR_HOST env var' , function ( ) {
769
781
pubsub . determineBaseUrl_ ( ) ;
770
- assert . strictEqual ( pubsub . baseUrl , PUBSUB_EMULATOR_HOST ) ;
782
+ assert . strictEqual ( pubsub . baseUrl_ , PUBSUB_EMULATOR_HOST ) ;
771
783
} ) ;
772
784
773
- it ( 'should set customEndpoint ' , function ( ) {
785
+ it ( 'should set customEndpoint_ ' , function ( ) {
774
786
pubsub . determineBaseUrl_ ( ) ;
775
- assert . strictEqual ( pubsub . customEndpoint , true ) ;
787
+ assert . strictEqual ( pubsub . customEndpoint_ , true ) ;
776
788
} ) ;
777
789
} ) ;
778
790
} ) ;
0 commit comments