morpheus-cli 5.5.2.1 → 5.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Dockerfile +1 -1
  4. data/README.md +57 -4
  5. data/Rakefile +9 -0
  6. data/bin/morpheus +4 -4
  7. data/lib/morpheus/api/api_client.rb +8 -2
  8. data/lib/morpheus/api/archive_buckets_interface.rb +1 -1
  9. data/lib/morpheus/api/archive_files_interface.rb +3 -3
  10. data/lib/morpheus/api/clients_interface.rb +2 -2
  11. data/lib/morpheus/api/clusters_interface.rb +8 -1
  12. data/lib/morpheus/api/containers_interface.rb +29 -16
  13. data/lib/morpheus/api/custom_instance_types_interface.rb +0 -2
  14. data/lib/morpheus/api/doc_interface.rb +8 -6
  15. data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
  16. data/lib/morpheus/api/health_interface.rb +1 -1
  17. data/lib/morpheus/api/image_builder_interface.rb +3 -3
  18. data/lib/morpheus/api/instances_interface.rb +25 -0
  19. data/lib/morpheus/api/logs_interface.rb +2 -4
  20. data/lib/morpheus/api/monitoring_interface.rb +6 -6
  21. data/lib/morpheus/api/packages_interface.rb +1 -1
  22. data/lib/morpheus/api/reports_interface.rb +1 -1
  23. data/lib/morpheus/api/servers_interface.rb +9 -1
  24. data/lib/morpheus/api/storage_providers_interface.rb +2 -2
  25. data/lib/morpheus/api/virtual_images_interface.rb +1 -1
  26. data/lib/morpheus/api.rb +2 -0
  27. data/lib/morpheus/benchmarking.rb +1 -1
  28. data/lib/morpheus/cli/cli_command.rb +69 -36
  29. data/lib/morpheus/cli/cli_registry.rb +19 -10
  30. data/lib/morpheus/cli/commands/access_token_command.rb +1 -1
  31. data/lib/morpheus/cli/commands/apps.rb +1 -1
  32. data/lib/morpheus/cli/commands/archives_command.rb +25 -33
  33. data/lib/morpheus/cli/commands/blueprints_command.rb +10 -21
  34. data/lib/morpheus/cli/commands/boot_scripts_command.rb +2 -2
  35. data/lib/morpheus/cli/commands/cat_command.rb +1 -1
  36. data/lib/morpheus/cli/commands/catalog_item_types_command.rb +12 -12
  37. data/lib/morpheus/cli/commands/clouds.rb +3 -3
  38. data/lib/morpheus/cli/commands/clusters.rb +154 -3
  39. data/lib/morpheus/cli/commands/containers_command.rb +398 -253
  40. data/lib/morpheus/cli/commands/deployments.rb +1 -1
  41. data/lib/morpheus/cli/commands/deploys.rb +9 -9
  42. data/lib/morpheus/cli/commands/doc.rb +15 -16
  43. data/lib/morpheus/cli/commands/execution_request_command.rb +2 -2
  44. data/lib/morpheus/cli/commands/file_copy_request_command.rb +5 -5
  45. data/lib/morpheus/cli/commands/groups.rb +2 -2
  46. data/lib/morpheus/cli/commands/health_command.rb +4 -4
  47. data/lib/morpheus/cli/commands/hosts.rb +43 -5
  48. data/lib/morpheus/cli/commands/image_builder_command.rb +1 -1
  49. data/lib/morpheus/cli/commands/instances.rb +419 -148
  50. data/lib/morpheus/cli/commands/integrations_command.rb +22 -20
  51. data/lib/morpheus/cli/commands/key_pairs.rb +2 -2
  52. data/lib/morpheus/cli/commands/library_container_scripts_command.rb +2 -2
  53. data/lib/morpheus/cli/commands/library_container_templates_command.rb +2 -2
  54. data/lib/morpheus/cli/commands/library_instance_types_command.rb +3 -3
  55. data/lib/morpheus/cli/commands/library_spec_templates_command.rb +2 -2
  56. data/lib/morpheus/cli/commands/login.rb +1 -1
  57. data/lib/morpheus/cli/commands/man_command.rb +32 -18
  58. data/lib/morpheus/cli/commands/packages_command.rb +11 -11
  59. data/lib/morpheus/cli/commands/plugins.rb +1 -1
  60. data/lib/morpheus/cli/commands/policies_command.rb +4 -4
  61. data/lib/morpheus/cli/commands/preseed_scripts_command.rb +2 -2
  62. data/lib/morpheus/cli/commands/remote.rb +1 -1
  63. data/lib/morpheus/cli/commands/reports_command.rb +3 -3
  64. data/lib/morpheus/cli/commands/roles.rb +6 -3
  65. data/lib/morpheus/cli/commands/security_groups.rb +1 -1
  66. data/lib/morpheus/cli/commands/shell.rb +40 -62
  67. data/lib/morpheus/cli/commands/snapshots.rb +3 -5
  68. data/lib/morpheus/cli/commands/source_command.rb +8 -16
  69. data/lib/morpheus/cli/commands/storage_providers_command.rb +7 -7
  70. data/lib/morpheus/cli/commands/tasks.rb +2 -2
  71. data/lib/morpheus/cli/commands/vdi_pools_command.rb +6 -6
  72. data/lib/morpheus/cli/commands/view.rb +5 -1
  73. data/lib/morpheus/cli/commands/whitelabel_settings_command.rb +4 -4
  74. data/lib/morpheus/cli/commands/whoami.rb +2 -2
  75. data/lib/morpheus/cli/credentials.rb +30 -8
  76. data/lib/morpheus/cli/dot_file.rb +8 -15
  77. data/lib/morpheus/cli/error_handler.rb +16 -0
  78. data/lib/morpheus/cli/errors.rb +8 -1
  79. data/lib/morpheus/cli/mixins/print_helper.rb +17 -13
  80. data/lib/morpheus/cli/mixins/rest_command.rb +18 -18
  81. data/lib/morpheus/cli/mixins/secondary_rest_command.rb +12 -12
  82. data/lib/morpheus/cli/option_parser.rb +5 -1
  83. data/lib/morpheus/cli/option_types.rb +59 -12
  84. data/lib/morpheus/cli/version.rb +1 -1
  85. data/lib/morpheus/cli.rb +26 -16
  86. data/lib/morpheus/ext/rest_client.rb +3 -2
  87. data/lib/morpheus/formatters.rb +1 -1
  88. data/lib/morpheus/logging.rb +4 -4
  89. data/lib/morpheus/morpkg.rb +4 -4
  90. data/lib/morpheus/rest_client.rb +2 -2
  91. data/lib/morpheus/routes.rb +2 -2
  92. data/lib/morpheus/terminal.rb +65 -16
  93. data/lib/morpheus.rb +1 -1
  94. data/morpheus-cli.gemspec +1 -0
  95. data/test/api/containers_interface_test.rb +68 -0
  96. data/test/api/doc_interface_test.rb +35 -0
  97. data/test/api/instances_interface_test.rb +22 -0
  98. data/test/api/whoami_interface_test.rb +14 -0
  99. data/test/cli/access_token_test.rb +36 -0
  100. data/test/cli/auth_test.rb +82 -0
  101. data/test/cli/cli_test.rb +48 -0
  102. data/test/cli/containers_test.rb +92 -0
  103. data/test/cli/doc_test.rb +35 -0
  104. data/test/cli/help_test.rb +25 -0
  105. data/test/cli/instances_test.rb +36 -0
  106. data/test/cli/man_test.rb +14 -0
  107. data/test/cli/remote_test.rb +89 -0
  108. data/test/cli/roles_test.rb +34 -0
  109. data/test/cli/shell_test.rb +81 -0
  110. data/test/cli/version_test.rb +23 -0
  111. data/test/cli/view_test.rb +55 -0
  112. data/test/cli/whoami_test.rb +17 -0
  113. data/test/morpheus_test.rb +16 -0
  114. data/test/test_case.rb +338 -0
  115. data/test/test_config.rb +137 -0
  116. data/test/test_data_helper.rb +97 -0
  117. metadata +61 -3
@@ -9,7 +9,7 @@ module Morpheus
9
9
  def self.parse_package_manifest(source_directory)
10
10
  source_directory = File.expand_path(source_directory)
11
11
  manifest_filename = File.join(source_directory, "package-manifest.json")
12
- if !File.exists?(manifest_filename)
12
+ if !File.exist?(manifest_filename)
13
13
  raise "Package manifest file not found: #{manifest_filename}"
14
14
  end
15
15
  manifest = JSON.parse(File.read(manifest_filename))
@@ -46,10 +46,10 @@ module Morpheus
46
46
  elsif File.directory?(outfile)
47
47
  outfile = File.join(outfile, "#{code}-#{version}.morpkg")
48
48
  end
49
- if Dir.exists?(outfile)
49
+ if Dir.exist?(outfile)
50
50
  raise "Invalid package target. #{outfile} is the name of an existing directory."
51
51
  end
52
- if File.exists?(outfile)
52
+ if File.exist?(outfile)
53
53
  if do_overwrite
54
54
  # don't delete, just overwrite.
55
55
  # File.delete(outfile)
@@ -58,7 +58,7 @@ module Morpheus
58
58
  end
59
59
  end
60
60
  # build directories if needed
61
- if !Dir.exists?(File.dirname(outfile))
61
+ if !Dir.exist?(File.dirname(outfile))
62
62
  Dir.mkdir(File.dirname(outfile))
63
63
  end
64
64
 
@@ -8,11 +8,11 @@ module Morpheus
8
8
  class << self
9
9
 
10
10
  def user_agent
11
- if !@user_agent
11
+ if !defined?(@user_agent) || @user_agent.nil?
12
12
  begin
13
13
  @user_agent = "morpheus-cli #{Morpheus::Cli::VERSION}"
14
14
  @user_agent = "#{@user_agent} (#{::RestClient::Platform.architecture}) #{::RestClient::Platform.ruby_agent_version}"
15
- rescue => e
15
+ rescue
16
16
  end
17
17
  end
18
18
  return @user_agent
@@ -178,7 +178,7 @@ module Morpheus::Routes
178
178
  end
179
179
 
180
180
  best_route = nil
181
- best_index = nil
181
+ #best_index = nil
182
182
  best_prefix_words = nil
183
183
  paths.each do |p|
184
184
  if best_route.nil?
@@ -190,7 +190,7 @@ module Morpheus::Routes
190
190
  #if best_index.nil? || match_index < best_index
191
191
  if best_prefix_words.nil? || prefix_words.size < best_prefix_words.size
192
192
  best_route = it
193
- best_index = match_index
193
+ #best_index = match_index
194
194
  best_prefix_words = prefix_words
195
195
  end
196
196
  end
@@ -1,4 +1,4 @@
1
- require 'morpheus/cli'
1
+ #require 'morpheus/cli' #todo: remove circular require...
2
2
  require 'morpheus/benchmarking'
3
3
  require 'morpheus/logging'
4
4
  require 'morpheus/rest_client'
@@ -7,6 +7,7 @@ require 'morpheus/cli/dot_file'
7
7
  require 'morpheus/cli/error_handler'
8
8
  require 'morpheus/cli/expression_parser'
9
9
  require 'morpheus/cli/option_parser'
10
+ require 'morpheus/cli/version'
10
11
  require 'term/ansicolor'
11
12
 
12
13
  module Morpheus
@@ -41,7 +42,13 @@ module Morpheus
41
42
  include Morpheus::Benchmarking::HasBenchmarking
42
43
  # todo: this can be combined with Cli::Shell
43
44
 
44
- class Blackhole # < IO
45
+ class Blackhole # < File
46
+
47
+ def initialize(*args)
48
+ # we shouldn't actually need a File tho.. but Readline wants one
49
+ # File.open(Morpheus::Cli.windows? ? 'NUL:' : '/dev/null', 'w')
50
+ end
51
+
45
52
  def accrete_data(*mgs)
46
53
  # Singularity.push(*msgs)
47
54
  return nil
@@ -61,7 +68,7 @@ module Morpheus
61
68
  end
62
69
 
63
70
  def self.prompt
64
- if @prompt.nil?
71
+ if !defined?(@prompt) || @prompt.nil?
65
72
  if ENV['MORPHEUS_PS1']
66
73
  @prompt = ENV['MORPHEUS_PS1'].dup
67
74
  else
@@ -91,7 +98,7 @@ module Morpheus
91
98
  # the global Morpheus::Terminal instance
92
99
  # This should go away, but it needed for now...
93
100
  def self.instance
94
- @morphterm # ||= self.new({})
101
+ @morphterm ||= self.new({})
95
102
  end
96
103
 
97
104
  # hack alert! This should go away, but is needed for now...
@@ -112,13 +119,13 @@ module Morpheus
112
119
  # @param stderr [IO] Default is STDERR
113
120
  # @param [IO] stderr
114
121
  # @stderr = stderr
115
- def initialize(stdin=STDIN,stdout=STDOUT, stderr=STDERR, homedir=nil)
122
+ def initialize(stdin=$stdin,stdout=$stdout, stderr=$stderr, homedir=nil)
116
123
  attrs = {}
117
124
  if stdin.is_a?(Hash)
118
125
  attrs = stdin.clone()
119
- stdin = attrs[:stdin] || STDIN
120
- stdout = attrs[:stdout] || STDOUT
121
- stderr = attrs[:stderr] || STDERR
126
+ stdin = attrs[:stdin] || $stdin
127
+ stdout = attrs[:stdout] || $stdout
128
+ stderr = attrs[:stderr] || $stderr
122
129
  homedir = attrs[:homedir] || attrs[:home] || attrs[:home_directory]
123
130
  end
124
131
  # establish IO
@@ -132,12 +139,12 @@ module Morpheus
132
139
  set_home_directory(use_homedir)
133
140
 
134
141
  # use colors by default
135
- set_coloring(STDOUT.isatty)
142
+ set_coloring($stdout.isatty) #rescue nil
136
143
  # Term::ANSIColor::coloring = STDOUT.isatty
137
144
  # @coloring = Term::ANSIColor::coloring?
138
145
 
139
146
  # startup script
140
- if File.exists? Morpheus::Cli::DotFile.morpheus_profile_filename
147
+ if File.exist? Morpheus::Cli::DotFile.morpheus_profile_filename
141
148
  @profile_dot_file = Morpheus::Cli::DotFile.new(Morpheus::Cli::DotFile.morpheus_profile_filename)
142
149
  else
143
150
  @profile_dot_file = nil
@@ -197,13 +204,52 @@ module Morpheus
197
204
  @stderr
198
205
  end
199
206
 
207
+ def with_pipes(opts, &block)
208
+ originals = {} #{stdout: stdout, stderr: stderr, stdin: stdin}
209
+ if opts[:stdout]
210
+ originals[:stdout] = stdout
211
+ set_stdout(opts[:stdout])
212
+ end
213
+ if opts[:stderr]
214
+ originals[:stderr] = stderr
215
+ set_stderr(opts[:stderr])
216
+ end
217
+ if opts[:stdin]
218
+ originals[:stdin] = stdin
219
+ set_stdin(opts[:stdin])
220
+ end
221
+ begin
222
+ yield
223
+ ensure
224
+ set_stdout(originals[:stdout]) if originals[:stdout]
225
+ set_stderr(originals[:stderr]) if originals[:stderr]
226
+ set_stdin(originals[:stdin]) if originals[:stdin]
227
+ end
228
+ end
229
+
230
+ def with_stdout(io, &block)
231
+ with_pipes(stdout:io, &block)
232
+ end
233
+
234
+ def with_stderr(io, &block)
235
+ with_pipes(stderr:io, &block)
236
+ end
237
+
238
+ def with_stdout_and_stderr(io, &block)
239
+ with_pipes(stdout:io, stderr:io, &block)
240
+ end
241
+
242
+ def with_stdin(io, &block)
243
+ with_pipes(stdin:io, &block)
244
+ end
245
+
200
246
  def home_directory=(homedir)
201
247
  set_home_directory(homedir)
202
248
  end
203
249
 
204
250
  def set_home_directory(homedir)
205
251
  full_homedir = File.expand_path(homedir)
206
- # if !Dir.exists?(full_homedir)
252
+ # if !Dir.exist?(full_homedir)
207
253
  # print_red_alert "Directory not found: #{full_homedir}"
208
254
  # exit 1
209
255
  # end
@@ -293,7 +339,7 @@ module Morpheus
293
339
  # out << "Options:\n"
294
340
  out << optparse.to_s
295
341
  out << "\n"
296
- out << "For more information, see https://github.com/gomorpheus/morpheus-cli/wiki"
342
+ out << "For more information, see https://clidocs.morpheusdata.com"
297
343
  out << "\n"
298
344
  out
299
345
  end
@@ -330,6 +376,10 @@ module Morpheus
330
376
  # $stdin.gets(*args)
331
377
  # end
332
378
 
379
+ def readline(*args)
380
+ # todo: one prompt to rule them all
381
+ end
382
+
333
383
  # protected
334
384
 
335
385
  def execute(input)
@@ -397,7 +447,7 @@ module Morpheus
397
447
  set_home_directory(@use_home_directory)
398
448
  # re-initialize some variables
399
449
  # startup script
400
- if File.exists? Morpheus::Cli::DotFile.morpheus_profile_filename
450
+ if File.exist? Morpheus::Cli::DotFile.morpheus_profile_filename
401
451
  @profile_dot_file = Morpheus::Cli::DotFile.new(Morpheus::Cli::DotFile.morpheus_profile_filename)
402
452
  else
403
453
  @profile_dot_file = nil
@@ -414,7 +464,7 @@ module Morpheus
414
464
 
415
465
 
416
466
  if @profile_dot_file && !@profile_dot_file_has_run
417
- if !noprofile && File.exists?(@profile_dot_file.filename)
467
+ if !noprofile && File.exist?(@profile_dot_file.filename)
418
468
  execute_profile_script()
419
469
  end
420
470
  end
@@ -466,14 +516,13 @@ module Morpheus
466
516
  # return 127, nil
467
517
  # end
468
518
 
469
- if @benchmarking || args.include?('-B') || args.include?('--benchmark')
519
+ if (defined?(@benchmarking) && @benchmarking) || args.include?('-B') || args.include?('--benchmark')
470
520
  benchmark_name = "morpheus #{formatted_cmd}"
471
521
  benchmark_name.sub!(' -B', '')
472
522
  benchmark_name.sub!(' --benchmark', '')
473
523
  #benchmark_name << " -B"
474
524
  start_benchmark(benchmark_name)
475
525
  end
476
-
477
526
  # shell is a Singleton command class
478
527
  if args[0] == "shell"
479
528
  require 'morpheus/cli/commands/shell'
data/lib/morpheus.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # This provides the command: require 'morpheus'
2
- # This is really the same as just morpheus/api right now.
2
+ # This is really the same as just morpheus/cli right now.
3
3
  # require 'morpheus/api'
4
4
 
5
5
  require 'morpheus/cli'
data/morpheus-cli.gemspec CHANGED
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "http"
30
30
  spec.add_dependency "rubyzip"
31
31
  spec.add_dependency "money"
32
+ spec.add_dependency "test-unit"
32
33
  end
@@ -0,0 +1,68 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::ContainersInterface
4
+ class MorpheusTest::ContainersInterfaceTest < MorpheusTest::TestCase
5
+
6
+ include MorpheusTest::TestDataHelper
7
+
8
+ def setup()
9
+ super
10
+ #load_container_test_data()
11
+ end
12
+
13
+ def test_get
14
+ container_id = find_first_container_id()
15
+ response = client.containers.get(container_id)
16
+ assert response['container'].is_a?(Hash)
17
+ assert_equal response['container']['id'], container_id
18
+ end
19
+
20
+ # todo: need to wait and refresh status for this to work well
21
+
22
+ =begin
23
+ def test_stop
24
+ response = client.containers.stop(@id, {})
25
+ assert_equal response['success'], true
26
+ end
27
+
28
+ def test_start
29
+ response = client.containers.start(@id, {})
30
+ assert_equal response['success'], true
31
+ end
32
+
33
+ def test_restart
34
+ response = client.containers.restart(@id, {})
35
+ assert_equal response['success'], true
36
+ end
37
+
38
+ def test_suspend
39
+ response = client.containers.suspend(@id, {})
40
+ assert_equal response['success'], true
41
+ end
42
+
43
+ def test_eject
44
+ response = client.containers.eject(@id, {})
45
+ assert_equal response['success'], true
46
+ end
47
+
48
+ def test_available_actions
49
+ response = client.containers.available_actions(@id)
50
+ assert response['actions'].is_a?(Array)
51
+ end
52
+
53
+ def test_action
54
+ response = client.containers.action(@id, {})
55
+ assert_equal response['success'], true
56
+ end
57
+
58
+ def test_import
59
+ response = client.containers.import(@id, {})
60
+ assert_equal response['success'], true
61
+ end
62
+
63
+ def test_clone_image
64
+ response = client.containers.clone_image(@id, {})
65
+ assert_equal response['success'], true
66
+ end
67
+ =end
68
+ end
@@ -0,0 +1,35 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::DocInterface
4
+ class MorpheusTest::DocInterfaceTest < MorpheusTest::TestCase
5
+
6
+ def test_doc_list
7
+ @doc_interface = client.doc
8
+ response = @doc_interface.list()
9
+ assert_equal response['links'].class, Array
10
+ end
11
+
12
+ def test_doc_get
13
+ @doc_interface = client.doc
14
+ response = @doc_interface.openapi()
15
+ assert_equal response['openapi'], '3.0.3'
16
+ # todo: fix this, can be cached and fail
17
+ #assert_equal response['version'], Morpheus::Cli::Remote.load_remote(@config.remote_name)[:build_version]
18
+ end
19
+
20
+ def test_doc_get_yaml
21
+ @doc_interface = client.doc
22
+ response = @doc_interface.openapi({'format' => "yaml"})
23
+ assert response.body
24
+ assert YAML.load(response.body)
25
+ end
26
+
27
+ # def test_doc_download
28
+ # @doc_interface = client.doc
29
+ # response = @doc_interface.download_openapi('/path/to/openapi.json')
30
+ # yaml_content = response.body
31
+ # yaml_data = YAML.load(yaml_content)
32
+ # assert_not_nil yaml_data
33
+ # end
34
+
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::InstancesInterface
4
+ class MorpheusTest::InstancesInterfaceTest < MorpheusTest::TestCase
5
+
6
+ def test_instances_interface
7
+ @instances_interface = client.instances
8
+ response = @instances_interface.list()
9
+ instances = response['instances']
10
+ assert instances.is_a?(Array)
11
+ if !instances.empty?
12
+ response = @instances_interface.get(instances[0]['id'])
13
+ instance = response['instance']
14
+ assert instance.is_a?(Hash)
15
+ assert_equal instance['id'], instances[0]['id']
16
+ else
17
+ #puts "No instances found in this environment"
18
+ end
19
+ #todo: create and delete
20
+ end
21
+
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::WhoamiInterface
4
+ class MorpheusTest::WhoamiInterfaceTest < MorpheusTest::TestCase
5
+
6
+ def test_whoami_interface
7
+ @whoami_interface = client.whoami
8
+ response = @whoami_interface.get()
9
+ assert_equal response['user']['username'], @config.username
10
+ # todo: fix this, can be cached and fail
11
+ #assert_equal response['appliance']['buildVersion'], Morpheus::Cli::Remote.load_remote(@config.remote_name)[:build_version]
12
+ end
13
+
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for Morpheus::Cli::AccessTokenCommand
4
+ class MorpheusTest::AccessTokenTest < MorpheusTest::TestCase
5
+
6
+ def test_access_token
7
+ assert_execute("access-token")
8
+ assert_execute("access-token get")
9
+ assert_equal(is_logged_in(), true, "is_logged_in() should be true after access-token refresh")
10
+ end
11
+
12
+ def test_access_token_details
13
+ assert_execute("access-token details")
14
+ end
15
+
16
+ def test_access_token_refresh
17
+ previous_token = get_access_token()
18
+ without_authentication do
19
+ login()
20
+ assert_execute("access-token refresh -y")
21
+ assert_equal(is_logged_in(), true, "is_logged_in() should be true after access-token refresh")
22
+ new_token = get_access_token()
23
+ assert_not_equal(previous_token, new_token, "Access token should have changed")
24
+ assert_error("login --test --token #{previous_token} ", "Old token should no longer be valid after refresh")
25
+ assert_execute("login --token #{new_token} ", "New token should be valid after refresh")
26
+ end
27
+ end
28
+
29
+ def test_access_token_unauthenticated
30
+ without_authentication do
31
+ assert_error("access-token")
32
+ assert_error("access-token get")
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,82 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for login and logout
4
+ class MorpheusTest::AuthTest < MorpheusTest::TestCase
5
+
6
+ def requires_authentication
7
+ false
8
+ end
9
+
10
+ def test_login
11
+ assert_execute %(login "#{escape_arg @config.username}" "#{escape_arg @config.password_decrypted}")
12
+ assert is_logged_in()
13
+ end
14
+
15
+ def test_login_bad_credentials
16
+ assert_error %(login "#{escape_arg @config.username}" "invalid_password")
17
+ assert !is_logged_in()
18
+ end
19
+
20
+ def test_login_test_option
21
+ without_authentication do
22
+ assert_equal(is_logged_in(), false, "begin as logged out")
23
+ assert_execute(%(login --test "#{escape_arg @config.username}" "#{escape_arg @config.password_decrypted}"))
24
+ assert_equal(is_logged_in(), false, "should still be logged out")
25
+ end
26
+
27
+ with_authentication do
28
+ assert is_logged_in()
29
+ assert_error %(login --test "#{escape_arg @config.username}" "invalid_password")
30
+ assert is_logged_in(), "should still be logged in"
31
+ end
32
+ end
33
+
34
+ def test_logout
35
+ with_authentication do
36
+ assert_execute %(logout)
37
+ assert !is_logged_in()
38
+ end
39
+ without_authentication do
40
+ assert_execute %(logout)
41
+ assert !is_logged_in()
42
+ end
43
+ end
44
+
45
+ def test_login_prompt
46
+ with_input @config.username.to_s, @config.password_decrypted do
47
+ assert_execute %(login)
48
+ end
49
+ with_input @config.username.to_s, "invalid_password" do
50
+ assert_error %(login --test)
51
+ end
52
+ without_authentication do
53
+ with_input @config.username, @config.password_decrypted do
54
+ assert_execute %(instances list)
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_login_adhoc
60
+ assert_execute %(login "#{escape_arg @config.username}" "#{escape_arg @config.password_decrypted}")
61
+ assert is_logged_in()
62
+ assert_execute %(login "#{escape_arg @config.username}" "#{escape_arg @config.password_decrypted}")
63
+ assert is_logged_in()
64
+ assert_execute("logout")
65
+ assert !is_logged_in()
66
+
67
+ # a bit meta, but let's test our helper methods here..
68
+ # login()
69
+ # assert_equal(is_logged_in(), true, "should be logged in")
70
+ # logout()
71
+ # assert_equal(is_logged_in(), false, "should be logged out")
72
+ # login_if_needed()
73
+ # assert_equal(is_logged_in(), true, "should be logged in")
74
+ # logout_if_needed()
75
+ # assert_equal(is_logged_in(), false, "should be logged out")
76
+ # logout()
77
+ # assert_equal(is_logged_in(), false, "should be logged out")
78
+ # login_if_needed()
79
+ # assert_equal(is_logged_in(), true, "should be logged in")
80
+ end
81
+
82
+ end
@@ -0,0 +1,48 @@
1
+ require 'morpheus_test'
2
+
3
+ # Tests for top level CLI functionality
4
+ class MorpheusTest::CliTest < MorpheusTest::TestCase
5
+
6
+ def requires_remote
7
+ false
8
+ end
9
+
10
+ def requires_authentication
11
+ false
12
+ end
13
+
14
+ def test_cli_no_arguments
15
+ assert_error("")
16
+ end
17
+
18
+ def test_cli_unknown_command
19
+ assert_error("unknown_command")
20
+ end
21
+
22
+ def test_cli_unknown_subcommand
23
+ assert_error("instances unknown_subcommand")
24
+ end
25
+
26
+ def test_cli_version_option
27
+ assert_execute("-v")
28
+ assert_execute("--version")
29
+ end
30
+
31
+ def test_cli_nocolor
32
+ assert_execute("version -C")
33
+ assert_execute("echo -C \"disable coloring with the -C option\"")
34
+ # todo: fix bug here that makes this persist for all subsequent terminal commands
35
+ # this re-enavbles it for remainder of tests
36
+ # assert_execute("coloring on?")
37
+ assert_execute("coloring off?")
38
+ assert_execute("coloring")
39
+ end
40
+
41
+ # HelpTest handles this now..
42
+ # def test_help
43
+ # assert_execute("help")
44
+ # assert_execute("-h")
45
+ # assert_execute("--help")
46
+ # end
47
+
48
+ end
@@ -0,0 +1,92 @@
1
+ require 'morpheus_test'
2
+ require 'test_data_helper'
3
+
4
+ # Tests for Morpheus::Cli::Containers
5
+ class MorpheusTest::ContainersTest < MorpheusTest::TestCase
6
+
7
+ include MorpheusTest::TestDataHelper
8
+
9
+ def setup()
10
+ super
11
+ #load_container_test_data()
12
+ end
13
+
14
+ def test_containers_get
15
+ id = find_first_container_id()
16
+ assert_execute %(containers get #{id})
17
+ end
18
+
19
+ # todo: need to wait and refresh status for this to work well
20
+
21
+ =begin
22
+ def test_containers_get_many
23
+ ids = find_many_container_ids().take(5)
24
+ assert_execute %(containers get #{ids.join(' ')})
25
+ end
26
+
27
+ def test_containers_stop
28
+ with_input ["n", "y"] do
29
+ assert_execute %(containers stop #{@id}), exit_code: 9
30
+ assert_execute %(containers stop #{@id})
31
+ end
32
+ end
33
+
34
+ def test_containers_start
35
+ with_input ["n", "y"] do
36
+ assert_execute %(containers start #{@id}), exit_code: 9
37
+ assert_execute %(containers start #{@id})
38
+ end
39
+ end
40
+
41
+ def test_containers_restart
42
+ with_input ["n", "y"] do
43
+ assert_execute %(containers restart #{@id}), exit_code: 9
44
+ assert_execute %(containers restart #{@id})
45
+ end
46
+ end
47
+
48
+ def test_containers_suspend
49
+ with_input ["n", "y"] do
50
+ assert_execute %(containers suspend #{@id}), exit_code: 9
51
+ assert_execute %(containers suspend #{@id})
52
+ end
53
+ end
54
+
55
+ def test_containers_eject
56
+ with_input ["n", "y"] do
57
+ assert_execute %(containers eject #{@id}), exit_code: 9
58
+ assert_execute %(containers eject #{@id})
59
+ end
60
+ end
61
+ =end
62
+
63
+ def test_containers_actions
64
+ @id = find_first_container_id()
65
+ assert_execute %(containers actions #{@id})
66
+ end
67
+
68
+ =begin
69
+ # do not run random actions for now
70
+ # def test_containers_action
71
+ # #action_code = "docker-remove-node"
72
+ # action = client.containers.available_actions(@id)['actions'].first
73
+ # assert action.is_a?(Hash), "Expected to find an action to run"
74
+ # action_code = action['code']
75
+ # assert_execute %(containers action #{@id} -a #{action_code} -y)
76
+ # end
77
+
78
+ def test_containers_import
79
+ with_input ["n", "y"] do
80
+ assert_execute %(containers import #{@id} -N), exit_code: 9
81
+ assert_execute %(containers import #{@id} -N)
82
+ end
83
+ end
84
+
85
+ def test_containers_clone_image
86
+ with_input ["n", "y"] do
87
+ assert_execute %(containers clone-image #{@id} -N), exit_code: 9
88
+ assert_execute %(containers clone-image #{@id} -N)
89
+ end
90
+ end
91
+ =end
92
+ end