Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ jobs:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn run test:e2e:anonymous

test_e2e_instance:
name: E2E Tests
docker:
- image: circleci/node:latest

working_directory: ~/repo/packages/cli

steps:
- restore_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn run test:e2e:instance

test_e2e_deploy:
name: E2E Tests
docker:
Expand Down Expand Up @@ -373,6 +385,9 @@ workflows:
- test_e2e_client:
requires:
- build
- test_e2e_instance:
requires:
- build
- test_e2e_deploy:
requires:
- build
Expand All @@ -398,6 +413,7 @@ workflows:
- deploy_docs:
requires:
- build
- test_e2e_instance
- test_e2e_validate
- test_e2e_client
- test_e2e_registry
Expand All @@ -414,6 +430,7 @@ workflows:
only: master
- publish:
requires:
- test_e2e_instance
- test_e2e_validate
- test_e2e_client
- test_e2e_registry
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"test:e2e:registry": "yarn run test:e2e-single tests/e2e/registry.test-e2e.js",
"test:e2e:hosting": "yarn run test:e2e-single tests/e2e/hosting.test-e2e.js",
"test:e2e:socket": "yarn run test:e2e-single tests/e2e/socket.test-e2e.js",
"test:e2e:instance": "yarn run test:e2e-single tests/e2e/instance.test-e2e.js",
"test:e2e-single": "mocha --require babel-register --timeout 100000 --slow 8000",
"test:unit": "yarn run unit",
"lint": "standard --fix --env mocha",
Expand Down
52 changes: 52 additions & 0 deletions packages/cli/src/cli-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
import program from './program'
import commands from './commands'
import session from './utils/session'
import context from './utils/context'
import validateCommands from './utils/validate-commands'
import { echo } from './utils/print-tools'

const setup = async () => {
await context.session.load()

program
.command('list')
.group('Instance')
.description('List all your instances')
.action(async (...options) => {
session.isAuthenticated()
echo()
new commands.InstanceList(context).run(options)
})

program
.command('create <instanceName>')
.group('Instance')
.description('Create an Instance')
.action(async (...options) => {
session.isAuthenticated()
echo()
new commands.InstanceCreate(context).run(options)
})

program
.command('delete <instanceName>')
.group('Instance')
.description('Create an Instance')
.action(async (...options) => {
session.isAuthenticated()
echo()
new commands.InstanceDelete(context).run(options)
})

program
.on('*', (commandsArr) => validateCommands(commandsArr))

if (!process.argv.slice(2).length) {
program.outputHelp()
}

program.parse(process.argv)
}

setup()
4 changes: 4 additions & 0 deletions packages/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ const setup = async () => {
.command('component', 'Manage your Socket components')
.on('*', (commandsArr) => validateCommands(commandsArr))

program
.command('instance', 'Manage your instances')
.on('*', (commandsArr) => validateCommands(commandsArr))

context.session.loadPlugins(program, context)
program.parse(process.argv)

Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import SocketCreate from './socket-create'
import SocketUninstall from './socket-uninstall'
import ComponentList from './component-list'
import ComponentLink from './component-link'
import InstanceList from './instance-list'
import InstanceCreate from './instance-create'
import InstanceDelete from './instance-delete'

export default {
Attach,
Expand Down Expand Up @@ -51,5 +54,8 @@ export default {
SocketCreate,
SocketUninstall,
ComponentList,
ComponentLink
ComponentLink,
InstanceList,
InstanceCreate,
InstanceDelete
}
17 changes: 17 additions & 0 deletions packages/cli/src/commands/instance-create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logger from '../utils/debug'
import { createInstance } from './helpers/create-instance'

const { debug } = logger('cmd-instance-create')

export default class InstanceCreateCmd {
constructor (context) {
debug('InstanceCreateCmd.constructor')
this.context = context
this.session = context.session
this.Init = context.Init
}

async run ([instanceName]) {
return createInstance(instanceName, this.session)
}
}
24 changes: 24 additions & 0 deletions packages/cli/src/commands/instance-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logger from '../utils/debug'
import { echo, error } from '../utils/print-tools'

const { debug } = logger('cmd-instance-create')

export default class InstanceCreateCmd {
constructor (context) {
debug('InstanceCreateCmd.constructor')
this.context = context
this.session = context.session
this.Init = context.Init
}

async run ([instanceName]) {
try {
await this.session.deleteInstance(instanceName)
echo()
echo(4)('Instance was deleted successfully!')
echo()
} catch (err) {
error('Deleting instance failed!')
}
}
}
29 changes: 29 additions & 0 deletions packages/cli/src/commands/instance-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import logger from '../utils/debug'
import { echo } from '../utils/print-tools'

const { debug } = logger('cmd-instance-list')

export default class InstanceCreateCmd {
constructor (context) {
debug('InstanceCreateCmd.constructor')
this.context = context
this.session = context.session
this.Init = context.Init
}

async run ([cmd]) {
const instances = await this.session.getInstances()
if (instances.length < 1) {
echo()
echo(4)('You don\'t have any instances!')
echo()
} else {
echo()
echo(4)('Instances:')
instances.forEach(instance => {
echo(6)(`- ${instance.name}`)
})
echo()
}
}
}
6 changes: 5 additions & 1 deletion packages/cli/src/utils/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class Session {
} catch (err) {}
}

async deleteInstance (name) {
return this.connection.instance.delete(name)
}

async createInstance (name = genUniqueName()) {
return this.connection.instance.create({ name })
}
Expand All @@ -115,7 +119,7 @@ export class Session {
}

async getInstances () {
return this.connection.Instance.please().list()
return this.connection.instance.list()
}

async checkAuth () {
Expand Down
75 changes: 75 additions & 0 deletions packages/cli/tests/e2e/instance.test-e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* global describe it */
import path from 'path'
import {
nixt,
deleteInstance,
createInstance,
uniqueInstance
} from '@syncano/test-tools'

const cliLocation = path.join(process.cwd(), 'lib/cli.js')

describe('[E2E] CLI Instance', function () {
const testNixt = () => nixt()
.env('SYNCANO_AUTH_KEY', process.env.E2E_CLI_ACCOUNT_KEY)

it.only('can create an instance', function (done) {
const testInstance = uniqueInstance()

testNixt()
.before(() => createInstance(testInstance))
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} instance create ${testInstance}`)
.stdout(/Instance already exist!/)
.end(done)
})

it('can\'t create an instance if already exist', function (done) {
const testInstance = uniqueInstance()

testNixt()
.after(() => deleteInstance(testInstance))
.run(`${cliLocation} instance create ${testInstance}`)
.stdout(/has been created/)
.end(done)
})

it('can list if there is no instances', function (done) {
testNixt()
.run(`${cliLocation} instance list`)
.stdout(/You don't have any instances!/)
.end(done)
})

it('can list instances', function (done) {
const testInstance1 = uniqueInstance()
const testInstance2 = uniqueInstance()

testNixt()
.before(async () => {
await createInstance(testInstance1)
await createInstance(testInstance2)
})
.after(async () => {
await deleteInstance(testInstance1)
await deleteInstance(testInstance2)
})
.run(`${cliLocation} instance list`)
.stdout(/Instances:/)
.stdout(new RegExp(testInstance1))
.stdout(new RegExp(testInstance2))
.end(done)
})

it('can delete instance', function (done) {
const testInstance = uniqueInstance()

testNixt()
.before(async () => {
await createInstance(testInstance)
})
.run(`${cliLocation} instance delete ${testInstance}`)
.stdout(/Instance was deleted successfully!/)
.end(done)
})
})