From 82244edf4962a15e002ffcd54b3faa25459c2510 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 23 Jun 2016 21:46:02 +0200 Subject: [PATCH] Also cleanup the ec2 instances --- test/selfhost-ec2-create-test.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/test/selfhost-ec2-create-test.js b/test/selfhost-ec2-create-test.js index b050927..289eae3 100644 --- a/test/selfhost-ec2-create-test.js +++ b/test/selfhost-ec2-create-test.js @@ -9,6 +9,7 @@ var AppStore = require('../appstore.js'), assert = require('assert'), async = require('async'), + AWS = require('aws-sdk'), child_process = require('child_process'), Cloudron = require('../cloudron.js'), common = require('../common.js'), @@ -53,13 +54,23 @@ describe('Selfhost EC2 Cloudron creation', function () { this.timeout(0); var appStore = new AppStore('https://api.staging.cloudron.io'); + var ec2 = new AWS.Route53({ accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_ACCESS_SECRET, region: EC2_REGION }); var owner = common.getOwner(); - var cloudron, appId, backupInfo; + var cloudron, appId, backupInfo, instanceId, newInstanceId; it('can create a cloudron', function () { var out = machine(util.format('create ec2 --fqdn %s --type %s --region %s --ssh-key %s --access-key-id %s --secret-access-key %s --subnet %s --security-group %s --backup-key %s --backup-bucket %s --release %s', CUSTOM_DOMAIN, EC2_TYPE, EC2_REGION, EC2_SSH_KEY, AWS_ACCESS_KEY, AWS_ACCESS_SECRET, EC2_SUBNET, EC2_SECURITY_GROUP, BACKUP_KEY, BACKUP_BUCKET, BOX_VERSION)); - assert(out.stdout.indexOf('You can now use your Cloudron at') !== -1); + + if (out.stdout.indexOf('You can now use your Cloudron at') === -1) { + console.error(out.stdout, out.stderr); + assert(false, 'Creation failed'); + } + + // Wohooo strings! + instanceId = out.stdout.split('\n').filter(function (l) { return l.indexOf('ID: ') !== -1; })[0].split(':')[1].trim(); + + console.log('New instance created with ID', instanceId); cloudron = new Cloudron({ domain: CUSTOM_DOMAIN, @@ -103,7 +114,15 @@ describe('Selfhost EC2 Cloudron creation', function () { it('can restore the box', function () { var out = machine(util.format('restore ec2 --fqdn %s --type %s --region %s --ssh-key %s --access-key-id %s --secret-access-key %s --subnet %s --security-group %s --backup-key %s --backup-bucket %s --backup %s', CUSTOM_DOMAIN, EC2_TYPE, EC2_REGION, EC2_SSH_KEY, AWS_ACCESS_KEY, AWS_ACCESS_SECRET, EC2_SUBNET, EC2_SECURITY_GROUP, BACKUP_KEY, BACKUP_BUCKET, backupInfo.id)); - assert(out.stdout.indexOf('You can now use your Cloudron at') !== -1); + + if (out.stdout.indexOf('You can now use your Cloudron at') === -1) { + console.error(out.stdout, out.stderr); + assert(false, 'Restore failed'); + } + + newInstanceId = out.stdout.split('\n').filter(function (l) { return l.indexOf('ID: ') !== -1; })[0].split(':')[1].trim(); + + console.log('New instance created with ID', newInstanceId); }); it('wait for app to be ready', function () { @@ -146,6 +165,11 @@ describe('Selfhost EC2 Cloudron creation', function () { ], done); }); - xit('can delete the cloudron', function () { + it('can delete the cloudron', function (done) { + var params = { + InstanceIds: [ instanceId, newInstanceId ] + }; + + ec2.terminateInstances(params, done); }); });