@@ -53,103 +53,133 @@ test.after.always(async (t) => {
53
53
54
54
// create_database
55
55
test . serial ( `should create an example database` , async ( t ) => {
56
- const output = await tools . runAsync ( `${ schemaCmd } createDatabase "${ INSTANCE_ID } " "${ DATABASE_ID } "` , cwd ) ;
57
- t . true ( output . includes ( `Waiting for operation on ${ DATABASE_ID } to complete...` ) ) ;
58
- t . true ( output . includes ( `Created database ${ DATABASE_ID } on instance ${ INSTANCE_ID } .` ) ) ;
56
+ const results = await tools . runAsyncWithIO ( `${ schemaCmd } createDatabase "${ INSTANCE_ID } " "${ DATABASE_ID } "` , cwd ) ;
57
+ const output = results . stdout + results . stderr ;
58
+ t . regex ( output , new RegExp ( `Waiting for operation on ${ DATABASE_ID } to complete...` ) ) ;
59
+ t . regex ( output , new RegExp ( `Created database ${ DATABASE_ID } on instance ${ INSTANCE_ID } .` ) ) ;
59
60
} ) ;
60
61
61
62
// insert_data
62
63
test . serial ( `should insert rows into an example table` , async ( t ) => {
63
- let output = await tools . runAsync ( `${ crudCmd } insert ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
64
- t . true ( output . includes ( `Inserted data.` ) ) ;
64
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } insert ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
65
+ const output = results . stdout + results . stderr ;
66
+ t . regex ( output , / I n s e r t e d d a t a \. / ) ;
65
67
} ) ;
66
68
67
69
// query_data
68
70
test . serial ( `should query an example table and return matching rows` , async ( t ) => {
69
- const output = await tools . runAsync ( `${ crudCmd } query ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
70
- t . true ( output . includes ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
71
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } query ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
72
+ const output = results . stdout + results . stderr ;
73
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o / ) ;
71
74
} ) ;
72
75
73
76
// read_data
74
77
test . serial ( `should read an example table` , async ( t ) => {
75
- const output = await tools . runAsync ( `${ crudCmd } read ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
76
- t . true ( output . includes ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
78
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } read ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
79
+ const output = results . stdout + results . stderr ;
80
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o / ) ;
77
81
} ) ;
78
82
79
83
// add_column
80
84
test . serial ( `should add a column to a table` , async ( t ) => {
81
- const output = await tools . runAsync ( `${ schemaCmd } addColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
82
- t . true ( output . includes ( `Waiting for operation to complete...` ) ) ;
83
- t . true ( output . includes ( `Added the MarketingBudget column.` ) ) ;
85
+ const results = await tools . runAsyncWithIO ( `${ schemaCmd } addColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
86
+ const output = results . stdout + results . stderr ;
87
+ t . regex ( output , / W a i t i n g f o r o p e r a t i o n t o c o m p l e t e \. \. \. / ) ;
88
+ t . regex ( output , / A d d e d t h e M a r k e t i n g B u d g e t c o l u m n \. / ) ;
84
89
} ) ;
85
90
86
91
// update_data
87
92
test . serial ( `should update existing rows in an example table` , async ( t ) => {
88
- let output = await tools . runAsync ( `${ crudCmd } update ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
89
- t . true ( output . includes ( `Updated data.` ) ) ;
93
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } update ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
94
+ const output = results . stdout + results . stderr ;
95
+ t . regex ( output , / U p d a t e d d a t a \. / ) ;
96
+ } ) ;
97
+
98
+ // read_stale_data
99
+ test . serial ( `should read stale data from an example table` , ( t ) => {
100
+ t . plan ( 2 ) ;
101
+ // read-stale-data reads data that is exactly 10 seconds old. So, make sure
102
+ // 10 seconds have elapsed since the update_data test.
103
+ return ( new Promise ( ( resolve ) => setTimeout ( resolve , 11000 ) ) )
104
+ . then ( async ( ) => {
105
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } read-stale ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
106
+ const output = results . stdout + results . stderr ;
107
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o , M a r k e t i n g B u d g e t : 1 0 0 0 0 0 / ) ;
108
+ t . regex ( output , / S i n g e r I d : 2 , A l b u m I d : 2 , A l b u m T i t l e : F o r e v e r H o l d y o u r P e a c e , M a r k e t i n g B u d g e t : 5 0 0 0 0 0 / ) ;
109
+ } ) ;
90
110
} ) ;
91
111
92
112
// query_data_with_new_column
93
113
test . serial ( `should query an example table with an additional column and return matching rows` , async ( t ) => {
94
- const output = await tools . runAsync ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
95
- t . true ( output . includes ( `SingerId: 1, AlbumId: 1, MarketingBudget: 100000` ) ) ;
96
- t . true ( output . includes ( `SingerId: 2, AlbumId: 2, MarketingBudget: 500000` ) ) ;
114
+ const results = await tools . runAsyncWithIO ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
115
+ const output = results . stdout + results . stderr ;
116
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , M a r k e t i n g B u d g e t : 1 0 0 0 0 0 / ) ;
117
+ t . regex ( output , / S i n g e r I d : 2 , A l b u m I d : 2 , M a r k e t i n g B u d g e t : 5 0 0 0 0 0 / ) ;
97
118
} ) ;
98
119
99
120
// create_index
100
121
test . serial ( `should create an index in an example table` , async ( t ) => {
101
- let output = await tools . runAsync ( `${ indexingCmd } createIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
102
- t . true ( output . includes ( `Waiting for operation to complete...` ) ) ;
103
- t . true ( output . includes ( `Added the AlbumsByAlbumTitle index.` ) ) ;
122
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } createIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
123
+ const output = results . stdout + results . stderr ;
124
+ t . regex ( output , / W a i t i n g f o r o p e r a t i o n t o c o m p l e t e \. \. \. / ) ;
125
+ t . regex ( output , / A d d e d t h e A l b u m s B y A l b u m T i t l e i n d e x \. / ) ;
104
126
} ) ;
105
127
106
128
// create_storing_index
107
129
test . serial ( `should create a storing index in an example table` , async ( t ) => {
108
- const output = await tools . runAsync ( `${ indexingCmd } createStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
109
- t . true ( output . includes ( `Waiting for operation to complete...` ) ) ;
110
- t . true ( output . includes ( `Added the AlbumsByAlbumTitle2 index.` ) ) ;
130
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } createStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
131
+ const output = results . stdout + results . stderr ;
132
+ t . regex ( output , / W a i t i n g f o r o p e r a t i o n t o c o m p l e t e \. \. \. / ) ;
133
+ t . regex ( output , / A d d e d t h e A l b u m s B y A l b u m T i t l e 2 i n d e x \. / ) ;
111
134
} ) ;
112
135
113
136
// query_data_with_index
114
137
test . serial ( `should query an example table with an index and return matching rows` , async ( t ) => {
115
- const output = await tools . runAsync ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
116
- t . true ( output . includes ( `AlbumId: 1, AlbumTitle: Go, Go, Go, MarketingBudget:` ) ) ;
138
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
139
+ const output = results . stdout + results . stderr ;
140
+ t . regex ( output , / A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o , M a r k e t i n g B u d g e t : / ) ;
117
141
t . false ( output . includes ( `AlbumId: 2, AlbumTitle: Total Junk, MarketingBudget:` ) ) ;
118
142
} ) ;
119
143
120
144
test . serial ( `should respect query boundaries when querying an example table with an index` , async ( t ) => {
121
- const output = await tools . runAsync ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } -s Ardvark -e Zoo` , cwd ) ;
122
- t . true ( output . includes ( `AlbumId: 1, AlbumTitle: Go, Go, Go, MarketingBudget:` ) ) ;
123
- t . true ( output . includes ( `AlbumId: 2, AlbumTitle: Total Junk, MarketingBudget:` ) ) ;
145
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } -s Ardvark -e Zoo` , cwd ) ;
146
+ const output = results . stdout + results . stderr ;
147
+ t . regex ( output , / A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o , M a r k e t i n g B u d g e t : / ) ;
148
+ t . regex ( output , / A l b u m I d : 2 , A l b u m T i t l e : T o t a l J u n k , M a r k e t i n g B u d g e t : / ) ;
124
149
} ) ;
125
150
126
151
// read_data_with_index
127
152
test . serial ( `should read an example table with an index` , async ( t ) => {
128
- const output = await tools . runAsync ( `${ indexingCmd } readIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
129
- t . true ( output . includes ( `AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
153
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } readIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
154
+ const output = results . stdout + results . stderr ;
155
+ t . regex ( output , / A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o / ) ;
130
156
} ) ;
131
157
132
158
// read_data_with_storing_index
133
159
test . serial ( `should read an example table with a storing index` , async ( t ) => {
134
- const output = await tools . runAsync ( `${ indexingCmd } readStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
135
- t . true ( output . includes ( `AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
160
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } readStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
161
+ const output = results . stdout + results . stderr ;
162
+ t . regex ( output , / A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o / ) ;
136
163
} ) ;
137
164
138
165
// read_only_transaction
139
166
test . serial ( `should read an example table using transactions` , async ( t ) => {
140
- const output = await tools . runAsync ( `${ transactionCmd } readOnly ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
141
- t . true ( output . includes ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
142
- t . true ( output . includes ( `Successfully executed read-only transaction.` ) ) ;
167
+ const results = await tools . runAsyncWithIO ( `${ transactionCmd } readOnly ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
168
+ const output = results . stdout + results . stderr ;
169
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , A l b u m T i t l e : G o , G o , G o / ) ;
170
+ t . regex ( output , / S u c c e s s f u l l y e x e c u t e d r e a d - o n l y t r a n s a c t i o n \. / ) ;
143
171
} ) ;
144
172
145
173
// read_write_transaction
146
174
test . serial ( `should read from and write to an example table using transactions` , async ( t ) => {
147
- let output = await tools . runAsync ( `${ transactionCmd } readWrite ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
148
- t . true ( output . includes ( `The first album's marketing budget: 100000` ) ) ;
149
- t . true ( output . includes ( `The second album's marketing budget: 500000` ) ) ;
150
- t . true ( output . includes ( `Successfully executed read-write transaction to transfer 200000 from Album 2 to Album 1.` ) ) ;
151
-
152
- output = await tools . runAsync ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
153
- t . true ( output . includes ( `SingerId: 1, AlbumId: 1, MarketingBudget: 300000` ) ) ;
154
- t . true ( output . includes ( `SingerId: 2, AlbumId: 2, MarketingBudget: 300000` ) ) ;
175
+ let results = await tools . runAsyncWithIO ( `${ transactionCmd } readWrite ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
176
+ let output = results . stdout + results . stderr ;
177
+ t . regex ( output , / T h e f i r s t a l b u m ' s m a r k e t i n g b u d g e t : 1 0 0 0 0 0 / ) ;
178
+ t . regex ( output , / T h e s e c o n d a l b u m ' s m a r k e t i n g b u d g e t : 5 0 0 0 0 0 / ) ;
179
+ t . regex ( output , / S u c c e s s f u l l y e x e c u t e d r e a d - w r i t e t r a n s a c t i o n t o t r a n s f e r 2 0 0 0 0 0 f r o m A l b u m 2 t o A l b u m 1 ./ ) ;
180
+
181
+ results = await tools . runAsyncWithIO ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
182
+ output = results . stdout + results . stderr ;
183
+ t . regex ( output , / S i n g e r I d : 1 , A l b u m I d : 1 , M a r k e t i n g B u d g e t : 3 0 0 0 0 0 / ) ;
184
+ t . regex ( output , / S i n g e r I d : 2 , A l b u m I d : 2 , M a r k e t i n g B u d g e t : 3 0 0 0 0 0 / ) ;
155
185
} ) ;
0 commit comments