@@ -37,17 +37,36 @@ describe('backups', async () => {
3737 const backup = cluster . backup ( BACKUP_ID ) ;
3838
3939 async function createTestBackup ( backupId ) {
40- const [ backup , operation ] = await cluster . createBackup ( backupId , {
41- table,
42- expireTime : new Date ( Date . now ( ) + 60 * 60 * 1000 ) , // 1 hour from now
43- } ) ;
44- await operation . promise ( ) ;
40+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
41+ const adminClient = new BigtableTableAdminClient ( ) ;
42+ const projectId = await adminClient . getProjectId ( ) ;
43+ const request = {
44+ parent : adminClient . clusterPath ( projectId , INSTANCE_ID , CLUSTER_ID ) ,
45+ backupId : backupId ,
46+ backup : {
47+ sourceTable : adminClient . tablePath ( projectId , INSTANCE_ID , TABLE_ID ) ,
48+ expireTime : new Date ( Date . now ( ) + 60 * 60 * 1000 ) , // 1 hour from now
49+ } ,
50+ } ;
51+ const [ operation ] = await adminClient . createBackup ( request ) ;
52+ const [ backup ] = await operation . promise ( ) ;
4553 return backup ;
4654 }
4755
4856 before ( async ( ) => {
49- await table . create ( ) ;
50- await table . createFamily ( 'follows' ) ;
57+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
58+ const adminClient = new BigtableTableAdminClient ( ) ;
59+ const projectId = await adminClient . getProjectId ( ) ;
60+ const request = {
61+ parent : adminClient . instancePath ( projectId , INSTANCE_ID ) ,
62+ tableId : TABLE_ID ,
63+ table : {
64+ columnFamilies : {
65+ follows : { } ,
66+ } ,
67+ } ,
68+ } ;
69+ await adminClient . createTable ( request ) ;
5170 await table . insert ( [
5271 {
5372 key : 'alincoln' ,
@@ -71,10 +90,15 @@ describe('backups', async () => {
7190
7291 after ( async ( ) => {
7392 async function reapBackups ( instance ) {
74- const [ backups ] = await instance . getBackups ( ) ;
93+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
94+ const adminClient = new BigtableTableAdminClient ( ) ;
95+ const projectId = await adminClient . getProjectId ( ) ;
96+ const [ backups ] = await adminClient . listBackups ( {
97+ parent : adminClient . instancePath ( projectId , instance . id ) ,
98+ } ) ;
7599 return Promise . all (
76100 backups . map ( backup => {
77- return backup . delete ( { timeout : 50 * 1000 } ) ;
101+ return adminClient . deleteBackup ( { name : backup . name } ) ;
78102 } ) ,
79103 ) ;
80104 }
@@ -103,34 +127,44 @@ describe('backups', async () => {
103127 } ) ;
104128
105129 it ( 'should get an existing backup' , async ( ) => {
106- // Refresh our copy of the backup metadata.
107- const [ metadata ] = await backup . getMetadata ( ) ;
130+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
131+ const adminClient = new BigtableTableAdminClient ( ) ;
132+ const projectId = await adminClient . getProjectId ( ) ;
133+ const request = {
134+ name : adminClient . backupPath (
135+ projectId ,
136+ INSTANCE_ID ,
137+ CLUSTER_ID ,
138+ BACKUP_ID ,
139+ ) ,
140+ } ;
141+ const [ metadata ] = await adminClient . getBackup ( request ) ;
108142
109143 const stdout = execSync (
110144 `node ./backups.get.js ${ INSTANCE_ID } ${ TABLE_ID } ${ CLUSTER_ID } ${ BACKUP_ID } ` ,
111145 ) ;
112146 assert . include ( stdout , `The backup is ${ metadata . sizeBytes } bytes.` ) ;
113147 assert . include (
114148 stdout ,
115- `The backup will auto-delete at ${ metadata . expireDate . toISOString ( ) } ` ,
149+ `The backup will auto-delete at ${ new Date ( metadata . expireTime . seconds * 1000 ) . toISOString ( ) } ` ,
116150 ) ;
117151 assert . include (
118152 stdout ,
119- `The backup finished being created at ${ metadata . endTime . toISOString ( ) } ` ,
153+ `The backup finished being created at ${ new Date ( metadata . endTime . seconds * 1000 ) . toISOString ( ) } ` ,
120154 ) ;
121155 } ) ;
122156
123157 it ( 'should get existing backups' , async ( ) => {
124- const [ backupsFromInstance ] = await instance . listBackups ( ) ;
125- const [ backupsFromCluster ] = await cluster . listBackups ( ) ;
158+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
159+ const adminClient = new BigtableTableAdminClient ( ) ;
160+ const projectId = await adminClient . getProjectId ( ) ;
161+ const [ backupsFromCluster ] = await adminClient . listBackups ( {
162+ parent : adminClient . clusterPath ( projectId , INSTANCE_ID , CLUSTER_ID ) ,
163+ } ) ;
126164
127165 const stdout = execSync (
128166 `node ./backups.list.js ${ INSTANCE_ID } ${ TABLE_ID } ${ CLUSTER_ID } ` ,
129167 ) ;
130- assert . include (
131- stdout ,
132- `${ backupsFromInstance . length } backups returned from the instance.` ,
133- ) ;
134168 assert . include (
135169 stdout ,
136170 `${ backupsFromCluster . length } backups returned from the cluster.` ,
@@ -149,18 +183,33 @@ describe('backups', async () => {
149183 const backupId = generateId ( ) ;
150184 const backup = await createTestBackup ( backupId ) ;
151185
152- const oldExpireTime = backup . expireTime . toISOString ( ) ;
186+ const oldExpireTime = new Date (
187+ backup . expireTime . seconds * 1000 ,
188+ ) . toISOString ( ) ;
153189
154190 const stdout = execSync (
155191 `node ./backups.update.js ${ INSTANCE_ID } ${ TABLE_ID } ${ CLUSTER_ID } ${ backupId } ` ,
156192 ) ;
157193
158- const newExpireTime = backup . expireTime . toISOString ( ) ;
194+ const { BigtableTableAdminClient} = require ( '@google-cloud/bigtable' ) . v2 ;
195+ const adminClient = new BigtableTableAdminClient ( ) ;
196+ const projectId = await adminClient . getProjectId ( ) ;
197+ const [ updatedBackup ] = await adminClient . getBackup ( {
198+ name : adminClient . backupPath (
199+ projectId ,
200+ INSTANCE_ID ,
201+ CLUSTER_ID ,
202+ backupId ,
203+ ) ,
204+ } ) ;
205+ const newExpireTime = new Date (
206+ updatedBackup . expireTime . seconds * 1000 ,
207+ ) . toISOString ( ) ;
159208 assert . notStrictEqual ( oldExpireTime , newExpireTime ) ;
160209
161210 assert . include (
162211 stdout ,
163- `The backup will now auto-delete at ${ backup . metadata . expireDate } .` ,
212+ `The backup will now auto-delete at ${ newExpireTime } .` ,
164213 ) ;
165214 } ) ;
166215} ) ;
0 commit comments