@@ -63,17 +63,22 @@ test.beforeEach(tools.stubConsole);
6363test . afterEach . always ( tools . restoreConsole ) ;
6464
6565test . serial ( `should create a subscription` , async ( t ) => {
66+ t . plan ( 1 ) ;
6667 const output = await tools . runAsync ( `${ cmd } create ${ topicNameOne } ${ subscriptionNameOne } ` , cwd ) ;
6768 t . is ( output , `Subscription ${ fullSubscriptionNameOne } created.` ) ;
68- const results = await pubsub . subscription ( subscriptionNameOne ) . exists ( ) ;
69- t . true ( results [ 0 ] ) ;
69+ await tools . tryTest ( async ( assert ) => {
70+ const [ subscriptions ] = await pubsub . topic ( topicNameOne ) . getSubscriptions ( ) ;
71+ assert . equal ( subscriptions [ 0 ] . name , fullSubscriptionNameOne ) ;
72+ } ) . start ( ) ;
7073} ) ;
7174
7275test . serial ( `should create a push subscription` , async ( t ) => {
7376 const output = await tools . runAsync ( `${ cmd } create-push ${ topicNameOne } ${ subscriptionNameTwo } ` , cwd ) ;
7477 t . is ( output , `Subscription ${ fullSubscriptionNameTwo } created.` ) ;
75- const results = await pubsub . subscription ( subscriptionNameTwo ) . exists ( ) ;
76- t . true ( results [ 0 ] ) ;
78+ await tools . tryTest ( async ( assert ) => {
79+ const [ subscriptions ] = await pubsub . topic ( topicNameOne ) . getSubscriptions ( ) ;
80+ assert ( subscriptions . some ( ( s ) => s . name === fullSubscriptionNameTwo ) ) ;
81+ } ) . start ( ) ;
7782} ) ;
7883
7984test . serial ( `should get metadata for a subscription` , async ( t ) => {
@@ -86,52 +91,60 @@ test.serial(`should get metadata for a subscription`, async (t) => {
8691} ) ;
8792
8893test . serial ( `should list all subscriptions` , async ( t ) => {
89- await tools . tryTest ( async ( ) => {
94+ t . plan ( 0 ) ;
95+ await tools . tryTest ( async ( assert ) => {
9096 const output = await tools . runAsync ( `${ cmd } list` , cwd ) ;
91- t . true ( output . includes ( `Subscriptions:` ) ) ;
92- t . true ( output . includes ( fullSubscriptionNameOne ) ) ;
93- t . true ( output . includes ( fullSubscriptionNameTwo ) ) ;
97+ assert ( output . includes ( `Subscriptions:` ) ) ;
98+ assert ( output . includes ( fullSubscriptionNameOne ) ) ;
99+ assert ( output . includes ( fullSubscriptionNameTwo ) ) ;
94100 } ) . start ( ) ;
95101} ) ;
96102
97103test . serial ( `should list subscriptions for a topic` , async ( t ) => {
98- const output = await tools . runAsync ( `${ cmd } list ${ topicNameOne } ` , cwd ) ;
99- t . true ( output . includes ( `Subscriptions for ${ topicNameOne } :` ) ) ;
100- t . true ( output . includes ( fullSubscriptionNameOne ) ) ;
101- t . true ( output . includes ( fullSubscriptionNameTwo ) ) ;
104+ t . plan ( 0 ) ;
105+ await tools . tryTest ( async ( assert ) => {
106+ const output = await tools . runAsync ( `${ cmd } list ${ topicNameOne } ` , cwd ) ;
107+ assert ( output . includes ( `Subscriptions for ${ topicNameOne } :` ) ) ;
108+ assert ( output . includes ( fullSubscriptionNameOne ) ) ;
109+ assert ( output . includes ( fullSubscriptionNameTwo ) ) ;
110+ } ) . start ( ) ;
102111} ) ;
103112
104- test . serial ( `should pull messages` , async ( t ) => {
113+ test . serial ( `should listen for messages` , async ( t ) => {
105114 const expected = `Hello, world!` ;
106- const results = await pubsub . topic ( topicNameOne ) . publish ( expected ) ;
107- const messageIds = results [ 0 ] ;
108- const expectedOutput = `Received ${ messageIds . length } messages.\n* ${ messageIds [ 0 ] } "${ expected } " {}` ;
109- const output = await tools . runAsync ( `${ cmd } pull ${ subscriptionNameOne } ` , cwd ) ;
110- t . is ( output , expectedOutput ) ;
115+ const messageIds = await pubsub . topic ( topicNameOne ) . publisher ( ) . publish ( Buffer . from ( expected ) ) ;
116+ const output = await tools . runAsync ( `${ cmd } listen ${ subscriptionNameOne } ` , cwd ) ;
117+ t . true ( output . includes ( `Received message ${ messageIds [ 0 ] } :` ) ) ;
111118} ) ;
112119
113- test . serial ( `should pull ordered messages` , async ( t ) => {
120+ test . serial ( `should listen for ordered messages` , async ( t ) => {
121+ const timeout = 5 ;
114122 const subscriptions = require ( '../subscriptions' ) ;
115123 const expected = `Hello, world!` ;
124+ const expectedBuffer = Buffer . from ( expected ) ;
116125 const publishedMessageIds = [ ] ;
117- await pubsub . topic ( topicNameTwo ) . subscribe ( subscriptionNameThree ) ;
118- let results = await pubsub . topic ( topicNameTwo ) . publish ( { data : expected , attributes : { counterId : '3' } } , { raw : true } ) ;
119- publishedMessageIds . push ( results [ 0 ] [ 0 ] ) ;
120- await subscriptions . pullOrderedMessages ( subscriptionNameThree ) ;
126+ const publisherTwo = pubsub . topic ( topicNameTwo ) . publisher ( ) ;
127+
128+ await pubsub . topic ( topicNameTwo ) . createSubscription ( subscriptionNameThree ) ;
129+ let [ result ] = await publisherTwo . publish ( expectedBuffer , { counterId : '3' } ) ;
130+ publishedMessageIds . push ( result ) ;
131+ await subscriptions . listenForOrderedMessages ( subscriptionNameThree , timeout ) ;
121132 t . is ( console . log . callCount , 0 ) ;
122- results = await pubsub . topic ( topicNameTwo ) . publish ( { data : expected , attributes : { counterId : '1' } } , { raw : true } ) ;
123- publishedMessageIds . push ( results [ 0 ] [ 0 ] ) ;
124- await subscriptions . pullOrderedMessages ( subscriptionNameThree ) ;
133+
134+ [ result ] = await publisherTwo . publish ( expectedBuffer , { counterId : '1' } ) ;
135+ publishedMessageIds . push ( result ) ;
136+ await subscriptions . listenForOrderedMessages ( subscriptionNameThree , timeout ) ;
125137 t . is ( console . log . callCount , 1 ) ;
126138 t . deepEqual ( console . log . firstCall . args , [ `* %d %j %j` , publishedMessageIds [ 1 ] , expected , { counterId : '1' } ] ) ;
127- results = await pubsub . topic ( topicNameTwo ) . publish ( { data : expected , attributes : { counterId : '1' } } , { raw : true } ) ;
128- results = await pubsub . topic ( topicNameTwo ) . publish ( { data : expected , attributes : { counterId : '2' } } , { raw : true } ) ;
129- publishedMessageIds . push ( results [ 0 ] [ 0 ] ) ;
130- await tools . tryTest ( async ( ) => {
131- await subscriptions . pullOrderedMessages ( subscriptionNameThree ) ;
132- t . is ( console . log . callCount , 3 ) ;
133- t . deepEqual ( console . log . secondCall . args , [ `* %d %j %j` , publishedMessageIds [ 2 ] , expected , { counterId : '2' } ] ) ;
134- t . deepEqual ( console . log . thirdCall . args , [ `* %d %j %j` , publishedMessageIds [ 0 ] , expected , { counterId : '3' } ] ) ;
139+
140+ [ result ] = await publisherTwo . publish ( expectedBuffer , { counterId : '1' } ) ;
141+ [ result ] = await publisherTwo . publish ( expectedBuffer , { counterId : '2' } ) ;
142+ publishedMessageIds . push ( result ) ;
143+ await tools . tryTest ( async ( assert ) => {
144+ await subscriptions . listenForOrderedMessages ( subscriptionNameThree , timeout ) ;
145+ assert . equal ( console . log . callCount , 3 ) ;
146+ assert . deepEqual ( console . log . secondCall . args , [ `* %d %j %j` , publishedMessageIds [ 2 ] , expected , { counterId : '2' } ] ) ;
147+ assert . deepEqual ( console . log . thirdCall . args , [ `* %d %j %j` , publishedMessageIds [ 0 ] , expected , { counterId : '3' } ] ) ;
135148 } ) ;
136149} ) ;
137150
@@ -163,8 +176,12 @@ test.serial(`should test permissions for a subscription`, async (t) => {
163176} ) ;
164177
165178test . serial ( `should delete a subscription` , async ( t ) => {
179+ t . plan ( 1 ) ;
166180 const output = await tools . runAsync ( `${ cmd } delete ${ subscriptionNameOne } ` , cwd ) ;
167181 t . is ( output , `Subscription ${ fullSubscriptionNameOne } deleted.` ) ;
168- const results = await pubsub . subscription ( subscriptionNameOne ) . exists ( ) ;
169- t . false ( results [ 0 ] , false ) ;
182+ await tools . tryTest ( async ( assert ) => {
183+ const [ subscriptions ] = await pubsub . getSubscriptions ( ) ;
184+ assert . ok ( subscriptions ) ;
185+ assert ( subscriptions . every ( ( s ) => s . name !== fullSubscriptionNameOne ) ) ;
186+ } ) . start ( ) ;
170187} ) ;
0 commit comments