kontena-cli 0.12.3 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/kontena +6 -4
  4. data/lib/kontena/cli/apps/common.rb +21 -7
  5. data/lib/kontena/cli/apps/deploy_command.rb +11 -4
  6. data/lib/kontena/cli/apps/docker_helper.rb +12 -0
  7. data/lib/kontena/cli/apps/logs_command.rb +0 -2
  8. data/lib/kontena/cli/apps/remove_command.rb +23 -14
  9. data/lib/kontena/cli/bytes_helper.rb +40 -0
  10. data/lib/kontena/cli/container_command.rb +0 -1
  11. data/lib/kontena/cli/grid_command.rb +4 -6
  12. data/lib/kontena/cli/grids/logs_command.rb +0 -2
  13. data/lib/kontena/cli/grids/trusted_subnet_command.rb +12 -0
  14. data/lib/kontena/cli/grids/trusted_subnets/add_command.rb +16 -0
  15. data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +17 -0
  16. data/lib/kontena/cli/grids/trusted_subnets/remove_command.rb +20 -0
  17. data/lib/kontena/cli/grids/user_command.rb +12 -0
  18. data/lib/kontena/cli/grids/{add_user_command.rb → users/add_command.rb} +4 -4
  19. data/lib/kontena/cli/grids/{list_users_command.rb → users/list_command.rb} +4 -4
  20. data/lib/kontena/cli/grids/{remove_user_command.rb → users/remove_command.rb} +4 -4
  21. data/lib/kontena/cli/login_command.rb +4 -3
  22. data/lib/kontena/cli/master/aws/create_command.rb +3 -1
  23. data/lib/kontena/cli/master/current_command.rb +17 -0
  24. data/lib/kontena/cli/master/digital_ocean/create_command.rb +5 -3
  25. data/lib/kontena/cli/master/users/role_command.rb +10 -0
  26. data/lib/kontena/cli/master/users/{add_role_command.rb → roles/add_command.rb} +4 -4
  27. data/lib/kontena/cli/master/users/{remove_role_command.rb → roles/remove_command.rb} +4 -4
  28. data/lib/kontena/cli/master/users_command.rb +2 -4
  29. data/lib/kontena/cli/master_command.rb +2 -0
  30. data/lib/kontena/cli/node_command.rb +2 -4
  31. data/lib/kontena/cli/nodes/label_command.rb +14 -0
  32. data/lib/kontena/cli/nodes/{add_label_command.rb → labels/add_command.rb} +2 -2
  33. data/lib/kontena/cli/nodes/{remove_label_command.rb → labels/remove_command.rb} +2 -2
  34. data/lib/kontena/cli/nodes/list_command.rb +2 -1
  35. data/lib/kontena/cli/nodes/show_command.rb +19 -2
  36. data/lib/kontena/cli/registry_command.rb +0 -1
  37. data/lib/kontena/cli/service_command.rb +4 -11
  38. data/lib/kontena/cli/services/create_command.rb +10 -2
  39. data/lib/kontena/cli/services/env_command.rb +12 -0
  40. data/lib/kontena/cli/services/{add_env_command.rb → envs/add_command.rb} +4 -4
  41. data/lib/kontena/cli/services/{envs_command.rb → envs/list_command.rb} +5 -5
  42. data/lib/kontena/cli/services/{remove_env_command.rb → envs/remove_command.rb} +4 -4
  43. data/lib/kontena/cli/services/list_command.rb +3 -2
  44. data/lib/kontena/cli/services/logs_command.rb +0 -2
  45. data/lib/kontena/cli/services/secret_command.rb +10 -0
  46. data/lib/kontena/cli/services/{add_secret_command.rb → secrets/link_command.rb} +4 -4
  47. data/lib/kontena/cli/services/{remove_secret_command.rb → secrets/unlink_command.rb} +4 -4
  48. data/lib/kontena/cli/services/services_helper.rb +35 -8
  49. data/lib/kontena/cli/services/stats_command.rb +6 -1
  50. data/lib/kontena/cli/services/update_command.rb +4 -0
  51. data/lib/kontena/cli/user/forgot_password_command.rb +16 -0
  52. data/lib/kontena/cli/user/reset_password_command.rb +23 -0
  53. data/lib/kontena/cli/user/verify_command.rb +22 -0
  54. data/lib/kontena/cli/user_command.rb +13 -0
  55. data/lib/kontena/cli/vault/list_command.rb +1 -1
  56. data/lib/kontena/cli/vpn_command.rb +0 -1
  57. data/lib/kontena/cli/whoami_command.rb +17 -3
  58. data/lib/kontena/machine/aws/cloudinit_master.yml +13 -4
  59. data/lib/kontena/machine/aws/common.rb +8 -13
  60. data/lib/kontena/machine/aws/master_provisioner.rb +6 -5
  61. data/lib/kontena/machine/azure/cloudinit_master.yml +0 -2
  62. data/lib/kontena/machine/digital_ocean.rb +1 -0
  63. data/lib/kontena/machine/digital_ocean/cloudinit.yml +0 -22
  64. data/lib/kontena/machine/digital_ocean/cloudinit_master.yml +14 -4
  65. data/lib/kontena/machine/digital_ocean/master_provisioner.rb +12 -9
  66. data/lib/kontena/machine/vagrant/cloudinit.yml +2 -0
  67. data/lib/kontena/scripts/completer +4 -4
  68. data/spec/kontena/cli/app/common_spec.rb +55 -7
  69. data/spec/kontena/cli/app/docker_helper_spec.rb +74 -0
  70. data/spec/kontena/cli/grids/trusted_subnets/add_command_spec.rb +38 -0
  71. data/spec/kontena/cli/grids/trusted_subnets/list_command_spec.rb +31 -0
  72. data/spec/kontena/cli/grids/trusted_subnets/remove_command_spec.rb +38 -0
  73. data/spec/kontena/cli/master/current_command_spec.rb +57 -0
  74. data/spec/kontena/cli/master/users/{add_role_command_spec.rb → roles/add_command_spec.rb} +3 -3
  75. data/spec/kontena/cli/master/users/{remove_role_command_spec.rb → roles/remove_command_spec.rb} +3 -3
  76. data/spec/kontena/cli/services/{add_secret_command_spec.rb → secrets/link_command_spec.rb} +4 -3
  77. data/spec/kontena/cli/services/{remove_secret_command_spec.rb → secrets/unlink_command_spec.rb} +4 -3
  78. data/spec/kontena/cli/services/services_helper_spec.rb +44 -0
  79. metadata +45 -26
  80. data/lib/kontena/cli/forgot_password_command.rb +0 -13
  81. data/lib/kontena/cli/reset_password_command.rb +0 -19
  82. data/lib/kontena/cli/users_command.rb +0 -15
  83. data/lib/kontena/cli/verify_account_command.rb +0 -13
@@ -29,9 +29,8 @@ write_files:
29
29
  -e SSL_CERT="$SSL_CERT" \
30
30
  -p 80:80 -p 443:443 kontena/haproxy:latest
31
31
  coreos:
32
- update:
33
- reboot-strategy: off
34
32
  units:
33
+ <% unless mongodb_uri -%>
35
34
  - name: kontena-server-mongo.service
36
35
  command: start
37
36
  enable: true
@@ -55,7 +54,7 @@ coreos:
55
54
  ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
56
55
  --volumes-from=kontena-server-mongo-data \
57
56
  mongo:3.0 mongod --smallfiles
58
-
57
+ <% end -%>
59
58
  - name: kontena-server-api.service
60
59
  command: start
61
60
  enable: true
@@ -67,9 +66,13 @@ coreos:
67
66
  After=kontena-server-mongo.service
68
67
  Description=Kontena Master
69
68
  Documentation=http://www.kontena.io/
69
+ Before=kontena-server-haproxy.service
70
+ Wants=kontena-server-haproxy.service
70
71
  Requires=network-online.target
71
72
  Requires=docker.service
73
+ <% unless mongodb_uri -%>
72
74
  Requires=kontena-server-mongo.service
75
+ <% end %>
73
76
 
74
77
  [Service]
75
78
  Restart=always
@@ -79,10 +82,16 @@ coreos:
79
82
  ExecStartPre=-/usr/bin/docker rm kontena-server-api
80
83
  ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
81
84
  ExecStart=/usr/bin/docker run --name kontena-server-api \
85
+ <% if mongodb_uri -%>
86
+ -e MONGODB_URI=<%= mongodb_uri %> \
87
+ <% else -%>
82
88
  --link kontena-server-mongo:mongodb \
83
89
  -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
90
+ <% end -%>
91
+ <% if auth_server %>
92
+ -e AUTH_API_URL=<%= auth_server %> \
93
+ <% end -%>
84
94
  -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
85
- <% if auth_server %>-e AUTH_API_URL=<%= auth_server %><% end %> \
86
95
  kontena/server:${KONTENA_VERSION}
87
96
 
88
97
  - name: kontena-server-haproxy.service
@@ -97,6 +106,7 @@ coreos:
97
106
  Documentation=http://www.kontena.io/
98
107
  Requires=network-online.target
99
108
  Requires=docker.service
109
+ Requires=kontena-server-api.service
100
110
 
101
111
  [Service]
102
112
  Restart=always
@@ -8,6 +8,7 @@ module Kontena
8
8
  module DigitalOcean
9
9
  class MasterProvisioner
10
10
  include RandomName
11
+ include Machine::CertHelper
11
12
 
12
13
  attr_reader :client, :http_client
13
14
 
@@ -25,6 +26,10 @@ module Kontena
25
26
  if opts[:ssl_cert]
26
27
  abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
27
28
  ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
29
+ else
30
+ ShellSpinner "Generating self-signed SSL certificate" do
31
+ ssl_cert = generate_self_signed_cert
32
+ end
28
33
  end
29
34
 
30
35
  userdata_vars = {
@@ -32,7 +37,8 @@ module Kontena
32
37
  auth_server: opts[:auth_server],
33
38
  version: opts[:version],
34
39
  vault_secret: opts[:vault_secret],
35
- vault_iv: opts[:vault_iv]
40
+ vault_iv: opts[:vault_iv],
41
+ mongodb_uri: opts[:mongodb_uri]
36
42
  }
37
43
 
38
44
  droplet = DropletKit::Droplet.new(
@@ -52,11 +58,8 @@ module Kontena
52
58
  sleep 5
53
59
  end
54
60
  end
55
- if opts[:ssl_cert]
56
- master_url = "https://#{droplet.public_ip}"
57
- else
58
- master_url = "http://#{droplet.public_ip}"
59
- end
61
+
62
+ master_url = "https://#{droplet.public_ip}"
60
63
  Excon.defaults[:ssl_verify_peer] = false
61
64
  @http_client = Excon.new("#{master_url}", :connect_timeout => 10)
62
65
 
@@ -65,7 +68,7 @@ module Kontena
65
68
  end
66
69
 
67
70
  puts "Kontena Master is now running at #{master_url}"
68
- puts "Use #{"kontena login #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
71
+ puts "Use #{"kontena login --name=#{droplet.name.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
69
72
  end
70
73
 
71
74
  def user_data(vars)
@@ -74,7 +77,7 @@ module Kontena
74
77
  end
75
78
 
76
79
  def generate_name
77
- "kontena-master-#{super}-#{rand(1..99)}"
80
+ "kontena-master-#{super}-#{rand(1..9)}"
78
81
  end
79
82
 
80
83
  def ssh_key(public_key)
@@ -88,7 +91,7 @@ module Kontena
88
91
  end
89
92
 
90
93
  def erb(template, vars)
91
- ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
94
+ ERB.new(template, nil, '%<>-').result(OpenStruct.new(vars).instance_eval { binding })
92
95
  end
93
96
  end
94
97
  end
@@ -18,6 +18,8 @@ write_files:
18
18
  content: |
19
19
  fs.inotify.max_user_instances = 8192
20
20
  coreos:
21
+ update:
22
+ reboot-strategy: off
21
23
  units:
22
24
  - name: 00-eth.network
23
25
  runtime: true
@@ -86,7 +86,7 @@ if words.size > 0
86
86
  case words[0]
87
87
  when 'grid'
88
88
  completion.clear
89
- sub_commands = %w(add-user audit-log create current list list-users remove remove-user show use)
89
+ sub_commands = %w(add-user audit-log create current list user remove show use)
90
90
  if words[1]
91
91
  completion.push(sub_commands) unless sub_commands.include?(words[1])
92
92
  completion.push helper.grids
@@ -108,7 +108,7 @@ if words.size > 0
108
108
  if words[1] && words[1] == 'use'
109
109
  completion.push helper.master_names
110
110
  elsif words[1] && words[1] == 'users'
111
- users_sub_commands = %(invite list add-role remove-role)
111
+ users_sub_commands = %(invite list role)
112
112
  completion.push users_sub_commands
113
113
  elsif words[1]
114
114
  completion.push(sub_commands) unless sub_commands.include?(words[1])
@@ -119,8 +119,8 @@ if words.size > 0
119
119
  when 'service'
120
120
  completion.clear
121
121
  sub_commands = %w(containers create delete deploy list logs restart
122
- scale show start stats stop update monitor envs
123
- add-env remove-env add-secret remove-secret)
122
+ scale show start stats stop update monitor env
123
+ secret link unlink)
124
124
  if words[1]
125
125
  completion.push(sub_commands) unless sub_commands.include?(words[1])
126
126
  completion.push helper.services
@@ -78,26 +78,74 @@ describe Kontena::Cli::Apps::Common do
78
78
 
79
79
  describe '#extend_env_vars' do
80
80
  it 'inherites env vars from upper level' do
81
- from = {'environment' => ['FOO=bar']}
82
- to = {}
81
+ from = ['FOO=bar']
82
+ to = nil
83
83
  env_vars = subject.extend_env_vars(from, to)
84
84
  expect(env_vars).to eq(['FOO=bar'])
85
85
  end
86
86
 
87
87
  it 'overrides values' do
88
- from = {'environment' => ['FOO=bar']}
89
- to = {'environment' => ['FOO=baz']}
88
+ from = ['FOO=bar']
89
+ to = ['FOO=baz']
90
90
  env_vars = subject.extend_env_vars(from, to)
91
91
  expect(env_vars).to eq(['FOO=baz'])
92
92
  end
93
93
 
94
94
  it 'combines variables' do
95
- from = {'environment' => ['FOO=bar']}
96
- to = {'environment' => ['BAR=baz']}
95
+ from = ['FOO=bar']
96
+ to = ['BAR=baz']
97
97
  env_vars = subject.extend_env_vars(from, to)
98
98
  expect(env_vars).to eq(['BAR=baz', 'FOO=bar'])
99
99
  end
100
+ end
101
+
102
+ describe '#extend_secrets' do
103
+ it 'inherites secrets from upper level' do
104
+ secret = {
105
+ 'secret' => 'CUSTOMER_DB_PASSWORD',
106
+ 'name' => 'MYSQL_PASSWORD',
107
+ 'type' => 'env'
108
+ }
109
+ from = [secret]
110
+ to = nil
111
+ secrets = subject.extend_secrets(from, to)
112
+ expect(secrets).to eq([secret])
113
+ end
114
+
115
+ it 'overrides secrets' do
116
+ from_secret = {
117
+ 'secret' => 'CUSTOMER_DB_PASSWORD',
118
+ 'name' => 'MYSQL_PASSWORD',
119
+ 'type' => 'env'
120
+ }
100
121
 
122
+ to_secret = {
123
+ 'secret' => 'CUSTOMER_DB_PASSWORD',
124
+ 'name' => 'MYSQL_ROOT_PASSWORD',
125
+ 'type' => 'env'
126
+ }
127
+ from = [from_secret]
128
+ to = [to_secret]
129
+ secrets = subject.extend_secrets(from, to)
130
+ expect(secrets).to eq([to_secret])
131
+ end
132
+
133
+ it 'combines secrets' do
134
+ from_secret = {
135
+ 'secret' => 'CUSTOMER_DB_PASSWORD',
136
+ 'name' => 'MYSQL_PASSWORD',
137
+ 'type' => 'env'
138
+ }
101
139
 
140
+ to_secret = {
141
+ 'secret' => 'CUSTOMER_API_TOKEN',
142
+ 'name' => 'API_TOKEN',
143
+ 'type' => 'env'
144
+ }
145
+ from = [from_secret]
146
+ to = [to_secret]
147
+ secrets = subject.extend_secrets(from, to)
148
+ expect(secrets).to eq([to_secret, from_secret])
149
+ end
102
150
  end
103
- end
151
+ end
@@ -7,6 +7,45 @@ describe Kontena::Cli::Apps::DockerHelper do
7
7
  Class.new { include Kontena::Cli::Apps::DockerHelper}.new
8
8
  end
9
9
 
10
+ let(:services_with_valid_hooks) do
11
+ {
12
+ 'test_service' => {
13
+ 'build' => '.',
14
+ 'image' => 'test_service',
15
+ 'hooks' => {
16
+ 'pre_build' => [
17
+ { 'cmd' => "echo PREBUILD1", 'name' => 'hook1' },
18
+ { 'cmd' => "echo PREBUILD2", 'name' => 'hook2' }
19
+ ]
20
+ }
21
+ }
22
+ }
23
+ end
24
+
25
+ let(:services_with_invalid_hook) do
26
+ {
27
+ 'test_service' => {
28
+ 'build' => '.',
29
+ 'image' => 'test_service',
30
+ 'hooks' => {
31
+ 'pre_build' => [
32
+ { 'cmd' => "echo PREBUILD1", 'name' => 'hook1' },
33
+ { 'cmd' => "some_non_existing_command", 'name' => 'failing hook' },
34
+ ]
35
+ }
36
+ }
37
+ }
38
+ end
39
+
40
+ let(:services_with_no_hook) do
41
+ {
42
+ 'test_service' => {
43
+ 'build' => '.',
44
+ 'image' => 'test_service',
45
+ }
46
+ }
47
+ end
48
+
10
49
  describe '#validate_image_name' do
11
50
  context 'when image name is valid' do
12
51
  it 'returns true' do
@@ -29,4 +68,39 @@ describe Kontena::Cli::Apps::DockerHelper do
29
68
  end
30
69
  end
31
70
  end
71
+
72
+ describe '#run_pre_build_hook' do
73
+
74
+ context 'when hook defined' do
75
+ it 'runs the hook' do
76
+ allow(subject).to receive(:build_docker_image)
77
+ allow(subject).to receive(:push_docker_image)
78
+ expect(subject).to receive(:system).with("echo PREBUILD1"). and_return(true)
79
+ expect(subject).to receive(:system).with("echo PREBUILD2"). and_return(true)
80
+
81
+ subject.process_docker_images(services_with_valid_hooks)
82
+ end
83
+
84
+ it 'fails to run the hook' do
85
+ allow(subject).to receive(:build_docker_image)
86
+ allow(subject).to receive(:push_docker_image)
87
+ expect(subject).to receive(:system).with("echo PREBUILD1"). and_return(true)
88
+ expect(subject).to receive(:system).with("some_non_existing_command"). and_return(false)
89
+
90
+ expect {
91
+ subject.process_docker_images(services_with_invalid_hook)
92
+ }.to raise_error(SystemExit)
93
+ end
94
+ end
95
+ context 'when no hook defined' do
96
+ it 'runs no hooks' do
97
+ allow(subject).to receive(:build_docker_image)
98
+ allow(subject).to receive(:push_docker_image)
99
+ expect(subject).not_to receive(:run_pre_build_hook)
100
+
101
+ subject.process_docker_images(services_with_no_hook)
102
+ end
103
+ end
104
+ end
105
+
32
106
  end
@@ -0,0 +1,38 @@
1
+ require_relative "../../../../spec_helper"
2
+ require "kontena/cli/grids/trusted_subnet_command"
3
+ require "kontena/cli/grids/trusted_subnets/add_command"
4
+
5
+ describe Kontena::Cli::Grids::TrustedSubnets::AddCommand do
6
+
7
+ include ClientHelpers
8
+
9
+ describe '#execute' do
10
+ it 'requires api url' do
11
+ expect(subject).to receive(:require_api_url).once
12
+ subject.run(['grid', 'subnet'])
13
+ end
14
+
15
+ it 'requires token' do
16
+ expect(subject).to receive(:require_token).and_return(token)
17
+ subject.run(['grid', 'subnet'])
18
+ end
19
+
20
+ it 'requires grid as param' do
21
+ expect {
22
+ subject.run([])
23
+ }.to raise_error(Clamp::UsageError)
24
+ end
25
+
26
+ it 'adds subnet to grid' do
27
+ allow(client).to receive(:get).with("grids/my-grid").and_return(
28
+ 'trusted_subnets' => ['192.168.12.0/24']
29
+ )
30
+ expect(client).to receive(:put).with(
31
+ 'grids/my-grid', hash_including({trusted_subnets: [
32
+ '192.168.12.0/24', '10.12.0.0/19'
33
+ ]})
34
+ )
35
+ subject.run(['my-grid', '10.12.0.0/19'])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "../../../../spec_helper"
2
+ require "kontena/cli/grids/trusted_subnet_command"
3
+ require "kontena/cli/grids/trusted_subnets/list_command"
4
+
5
+ describe Kontena::Cli::Grids::TrustedSubnets::ListCommand do
6
+
7
+ include ClientHelpers
8
+
9
+ describe '#execute' do
10
+ it 'requires api url' do
11
+ expect(subject).to receive(:require_api_url).once
12
+ subject.run(['grid'])
13
+ end
14
+
15
+ it 'requires token' do
16
+ expect(subject).to receive(:require_token).and_return(token)
17
+ subject.run(['grid'])
18
+ end
19
+
20
+ it 'requires grid as param' do
21
+ expect {
22
+ subject.run([])
23
+ }.to raise_error(Clamp::UsageError)
24
+ end
25
+
26
+ it 'requests grid details from master' do
27
+ expect(client).to receive(:get).with("grids/test-grid")
28
+ subject.run(['test-grid'])
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ require_relative "../../../../spec_helper"
2
+ require "kontena/cli/grids/trusted_subnet_command"
3
+ require "kontena/cli/grids/trusted_subnets/remove_command"
4
+
5
+ describe Kontena::Cli::Grids::TrustedSubnets::RemoveCommand do
6
+
7
+ include ClientHelpers
8
+
9
+ describe '#execute' do
10
+ it 'requires api url' do
11
+ expect(subject).to receive(:require_api_url).once
12
+ subject.run(['grid', 'subnet'])
13
+ end
14
+
15
+ it 'requires token' do
16
+ expect(subject).to receive(:require_token).and_return(token)
17
+ subject.run(['grid', 'subnet'])
18
+ end
19
+
20
+ it 'requires grid as param' do
21
+ expect {
22
+ subject.run([])
23
+ }.to raise_error(Clamp::UsageError)
24
+ end
25
+
26
+ it 'removes subnet from grid' do
27
+ allow(client).to receive(:get).with("grids/my-grid").and_return(
28
+ 'trusted_subnets' => ['192.168.12.0/24', '192.168.50.0/24']
29
+ )
30
+ expect(client).to receive(:put).with(
31
+ 'grids/my-grid', hash_including({trusted_subnets: [
32
+ '192.168.12.0/24'
33
+ ]})
34
+ )
35
+ subject.run(['my-grid', '192.168.50.0/24'])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,57 @@
1
+ require_relative "../../../spec_helper"
2
+ require 'kontena/cli/master/current_command'
3
+
4
+ describe Kontena::Cli::Master::CurrentCommand do
5
+ let(:settings) do
6
+ {'current_server' => 'alias',
7
+ 'servers' => [
8
+ {'name' => 'some_master', 'url' => 'some_master'},
9
+ {'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
10
+ ]
11
+ }
12
+ end
13
+
14
+ let(:subject) { described_class.new(File.basename($0)) }
15
+
16
+ describe '#execute' do
17
+ it 'puts master name and URL' do
18
+ allow(subject).to receive(:settings).and_return(settings)
19
+
20
+ expect {
21
+ subject.run([])
22
+ }.to output(/alias.*someurl/).to_stdout
23
+ end
24
+
25
+ it 'only outputs name if name-flag is set' do
26
+ allow(subject).to receive(:settings).and_return(settings)
27
+
28
+ expect {
29
+ subject.run(['--name'])
30
+ }.to output("alias\n").to_stdout
31
+ end
32
+
33
+ it 'does not raise error when logged in' do
34
+ allow(subject).to receive(:settings).and_return(settings)
35
+
36
+ expect {
37
+ subject.run([])
38
+ }.to_not raise_error
39
+ end
40
+
41
+ it 'raises error when not logged in' do
42
+ allow(subject).to receive(:settings).and_return(
43
+ {
44
+ 'current_server' => nil,
45
+ 'servers' => [
46
+ {'name' => 'some_master', 'url' => 'some_master'},
47
+ {'name' => 'alias', 'url' => 'someurl', 'token' => '123456'}
48
+ ]
49
+ }
50
+ )
51
+
52
+ expect {
53
+ subject.run([])
54
+ }.to raise_error(ArgumentError)
55
+ end
56
+ end
57
+ end