@@ -53,103 +53,139 @@ 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 , new RegExp ( `Inserted data.` ) ) ;
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 , new RegExp ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
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 , new RegExp ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
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 , new RegExp ( `Waiting for operation to complete...` ) ) ;
88
+ t . regex ( output , new RegExp ( `Added the MarketingBudget column.` ) ) ;
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 , new RegExp ( `Updated data.` ) ) ;
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 , reject ) => {
104
+ setTimeout ( async ( ) => {
105
+ const results = await tools . runAsyncWithIO ( `${ crudCmd } read-stale ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
106
+ const output = results . stdout + results . stderr ;
107
+ try {
108
+ t . regex ( output , new RegExp ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go, MarketingBudget: 100000` ) ) ;
109
+ t . regex ( output , new RegExp ( `SingerId: 2, AlbumId: 2, AlbumTitle: Forever Hold your Peace, MarketingBudget: 500000` ) ) ;
110
+ resolve ( ) ;
111
+ } catch ( err ) {
112
+ reject ( err ) ;
113
+ }
114
+ } , 11000 ) ;
115
+ } ) ;
90
116
} ) ;
91
117
92
118
// query_data_with_new_column
93
119
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` ) ) ;
120
+ const results = await tools . runAsyncWithIO ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
121
+ const output = results . stdout + results . stderr ;
122
+ t . regex ( output , new RegExp ( `SingerId: 1, AlbumId: 1, MarketingBudget: 100000` ) ) ;
123
+ t . regex ( output , new RegExp ( `SingerId: 2, AlbumId: 2, MarketingBudget: 500000` ) ) ;
97
124
} ) ;
98
125
99
126
// create_index
100
127
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.` ) ) ;
128
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } createIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
129
+ const output = results . stdout + results . stderr ;
130
+ t . regex ( output , new RegExp ( `Waiting for operation to complete...` ) ) ;
131
+ t . regex ( output , new RegExp ( `Added the AlbumsByAlbumTitle index.` ) ) ;
104
132
} ) ;
105
133
106
134
// create_storing_index
107
135
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.` ) ) ;
136
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } createStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
137
+ const output = results . stdout + results . stderr ;
138
+ t . regex ( output , new RegExp ( `Waiting for operation to complete...` ) ) ;
139
+ t . regex ( output , new RegExp ( `Added the AlbumsByAlbumTitle2 index.` ) ) ;
111
140
} ) ;
112
141
113
142
// query_data_with_index
114
143
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:` ) ) ;
144
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
145
+ const output = results . stdout + results . stderr ;
146
+ t . regex ( output , new RegExp ( `AlbumId: 1, AlbumTitle: Go, Go, Go, MarketingBudget:` ) ) ;
117
147
t . false ( output . includes ( `AlbumId: 2, AlbumTitle: Total Junk, MarketingBudget:` ) ) ;
118
148
} ) ;
119
149
120
150
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:` ) ) ;
151
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } queryIndex ${ INSTANCE_ID } ${ DATABASE_ID } -s Ardvark -e Zoo` , cwd ) ;
152
+ const output = results . stdout + results . stderr ;
153
+ t . regex ( output , new RegExp ( `AlbumId: 1, AlbumTitle: Go, Go, Go, MarketingBudget:` ) ) ;
154
+ t . regex ( output , new RegExp ( `AlbumId: 2, AlbumTitle: Total Junk, MarketingBudget:` ) ) ;
124
155
} ) ;
125
156
126
157
// read_data_with_index
127
158
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` ) ) ;
159
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } readIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
160
+ const output = results . stdout + results . stderr ;
161
+ t . regex ( output , new RegExp ( `AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
130
162
} ) ;
131
163
132
164
// read_data_with_storing_index
133
165
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` ) ) ;
166
+ const results = await tools . runAsyncWithIO ( `${ indexingCmd } readStoringIndex ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
167
+ const output = results . stdout + results . stderr ;
168
+ t . regex ( output , new RegExp ( `AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
136
169
} ) ;
137
170
138
171
// read_only_transaction
139
172
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.` ) ) ;
173
+ const results = await tools . runAsyncWithIO ( `${ transactionCmd } readOnly ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
174
+ const output = results . stdout + results . stderr ;
175
+ t . regex ( output , new RegExp ( `SingerId: 1, AlbumId: 1, AlbumTitle: Go, Go, Go` ) ) ;
176
+ t . regex ( output , new RegExp ( `Successfully executed read-only transaction.` ) ) ;
143
177
} ) ;
144
178
145
179
// read_write_transaction
146
180
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` ) ) ;
181
+ let results = await tools . runAsyncWithIO ( `${ transactionCmd } readWrite ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
182
+ let output = results . stdout + results . stderr ;
183
+ t . regex ( output , new RegExp ( `The first album's marketing budget: 100000` ) ) ;
184
+ t . regex ( output , new RegExp ( `The second album's marketing budget: 500000` ) ) ;
185
+ t . regex ( output , new RegExp ( `Successfully executed read-write transaction to transfer 200000 from Album 2 to Album 1.` ) ) ;
186
+
187
+ results = await tools . runAsyncWithIO ( `${ schemaCmd } queryNewColumn ${ INSTANCE_ID } ${ DATABASE_ID } ` , cwd ) ;
188
+ output = results . stdout + results . stderr ;
189
+ t . regex ( output , new RegExp ( `SingerId: 1, AlbumId: 1, MarketingBudget: 300000` ) ) ;
190
+ t . regex ( output , new RegExp ( `SingerId: 2, AlbumId: 2, MarketingBudget: 300000` ) ) ;
155
191
} ) ;
0 commit comments