import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export default function ( { getService } ) { const supertest = getService ( 'supertest' ) ; const es = getService ( 'es' ) ; const CLOUD_SNAPSHOT_REPOSITORY = 'found-snapshots' ; const createCloudRepository = ( ) => { return es . snapshot . createRepository ( { name : CLOUD_SNAPSHOT_REPOSITORY , body : { type : 'fs' , settings : { location : '/tmp/cloud-snapshots/' , } , } , verify : false , } ) ; } ; const createCloudSnapshot = ( snapshotName ) => { return es . snapshot . create ( { repository : CLOUD_SNAPSHOT_REPOSITORY , snapshot : snapshotName , wait_for_completion : true , body : { indices : 'this_index_doesnt_exist' , ignore_unavailable : true , include_global_state : false , } , } ) ; } ; const deleteCloudSnapshot = ( snapshotName ) => { return es . snapshot . delete ( { repository : CLOUD_SNAPSHOT_REPOSITORY , snapshot : snapshotName , } ) ; } ; describe ( 'Cloud backup status' , function ( ) { this . tags ( [ 'skipCloud' ] ) ; describe ( 'get' , ( ) => { describe ( 'with backups present' , ( ) => { let mostRecentSnapshot ; before ( async ( ) => { await createCloudRepository ( ) ; await createCloudSnapshot ( 'test_snapshot_1' ) ; mostRecentSnapshot = ( await createCloudSnapshot ( 'test_snapshot_2' ) ) . snapshot ; } ) ; after ( async ( ) => { await deleteCloudSnapshot ( 'test_snapshot_1' ) ; await deleteCloudSnapshot ( 'test_snapshot_2' ) ; } ) ; it ( 'returns status based on most recent snapshot' , async ( ) => { const { body : cloudBackupStatus } = await supertest . get ( '/api/upgrade_assistant/cloud_backup_status' ) . set ( 'kbn-xsrf' , 'xxx' ) . expect ( 200 ) ; expect ( cloudBackupStatus . isBackedUp ) . to . be ( true ) ; expect ( cloudBackupStatus . lastBackupTime ) . to . be ( mostRecentSnapshot . start_time ) ; } ) ; } ) ; describe ( 'without backups present' , ( ) => { it ( 'returns not-backed-up status' , async ( ) => { const { body : cloudBackupStatus } = await supertest . get ( '/api/upgrade_assistant/cloud_backup_status' ) . set ( 'kbn-xsrf' , 'xxx' ) . expect ( 200 ) ; expect ( cloudBackupStatus . isBackedUp ) . to . be ( false ) ; expect ( cloudBackupStatus . lastBackupTime ) . to . be ( undefined ) ; } ) ; } ) ; } ) ; } ) ; }