From 5db7c890e0cd43c3054ba5b3957c3822bf023ad3 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 9 Jan 2023 21:00:11 -0500 Subject: [PATCH 1/7] highline dependency change --- manageiq-appliance_console.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manageiq-appliance_console.gemspec b/manageiq-appliance_console.gemspec index d41f811e..9515509a 100644 --- a/manageiq-appliance_console.gemspec +++ b/manageiq-appliance_console.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "awesome_spawn", "~> 1.4" spec.add_runtime_dependency "bcrypt", "~> 3.1.10" spec.add_runtime_dependency "bcrypt_pbkdf", ">= 1.0", "< 2.0" - spec.add_runtime_dependency "highline", "~> 1.6.21" + spec.add_runtime_dependency "highline", "~> 2.1" spec.add_runtime_dependency "i18n", ">= 0.8" spec.add_runtime_dependency "linux_admin", "~> 2.0" spec.add_runtime_dependency "manageiq-password", "< 2" From e485fb29217bb4bba9dbab5c49c14affd3224561 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 22 Aug 2022 11:47:12 -0400 Subject: [PATCH 2/7] drop expect_readline_question_asked The questions asked and the output are merged together. This method was only used in one spot so not much lost. --- spec/database_admin_spec.rb | 9 +++------ spec/support/ui.rb | 10 +--------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index 8e2f5f53..f1537fca 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -559,18 +559,15 @@ def confirm_and_execute say ["y", "metrics_*"] expect(subject.ask_for_tables_to_exclude_in_dump).to be_truthy - expect_output <<-EXAMPLE.strip_heredoc - + expect_output <<-EXAMPLE.strip_heredoc.chomp + Would you like to exclude tables in the dump? (Y/N): To exclude tables from the dump, enter them in a space separated list. For example: > metrics_* vim_performance_states event_streams + Enter the tables to exclude: |metrics_* vim_performance_states event_streams| EXAMPLE - expect_readline_question_asked <<-PROMPT.strip_heredoc.chomp - Would you like to exclude tables in the dump? (Y/N): y - Enter the tables to exclude: |metrics_* vim_performance_states event_streams| - PROMPT end it "adds `:exclude_table_data => ['metrics_*', 'vms']` to @database_opts" do diff --git a/spec/support/ui.rb b/spec/support/ui.rb index 3b4e105b..cf99908a 100644 --- a/spec/support/ui.rb +++ b/spec/support/ui.rb @@ -11,6 +11,7 @@ File.open(@temp_stdin.path, 'w+') end + # this is now data typed in our tests by us via 'say' let(:readline_output) do @temp_stdout = Tempfile.new("temp_stdout") File.open(@temp_stdout.path, 'w+') @@ -56,14 +57,6 @@ def expect_cls expect(subject).to receive(:print) end - def expect_readline_question_asked(question) - readline_output.rewind - readline_output_content = readline_output.read - unless readline_output_content.empty? - expect(readline_output_content).to include(question) - end - end - def expect_output(strs) strs = strs.collect { |s| s == "" ? "\n" : s }.join if strs.kind_of?(Array) expect(output.string).to eq(strs) @@ -71,7 +64,6 @@ def expect_output(strs) def expect_heard(strs, check_eof = true) strs = Array(strs) - expect_readline_question_asked(strs.shift) unless readline_output.tap(&:rewind).read.empty? expect_output(strs) expect { subject.ask("is there more") }.to raise_error(EOFError) if check_eof expect(input).to be_eof From 9afb1afa7911af5d3b9cd4edd72c0984292ac68e Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 9 Jan 2023 21:01:26 -0500 Subject: [PATCH 3/7] Handle default value output in highline If we enter a value that is not a default value, but one is derived, then the actual value entered is output. so if we type in text that infers option 1, then highline now outputs (1) Not exactly sure why there is a change for a default value being presented, I'm guessing the value was not checked by the previous test. So the change in expect_heard shows this at this time --- spec/database_admin_spec.rb | 2 +- spec/prompts_spec.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index f1537fca..de91ed62 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -98,7 +98,7 @@ expect(subject.ask_file_location).to be_truthy error = "Please provide #{errmsg}" - expect_heard ["Enter the #{prmpt}: ", error, prompt] + expect_heard ["Enter the #{prmpt}: |/tmp/evm_db.backup| ", error, prompt] expect(subject.database_opts[:local_file]).to eq(file.path) end diff --git a/spec/prompts_spec.rb b/spec/prompts_spec.rb index 77438726..1e5cb0b4 100644 --- a/spec/prompts_spec.rb +++ b/spec/prompts_spec.rb @@ -277,7 +277,8 @@ expect(subject.ask_for_disk("database disk").path).to eq("/dev/a") expect_heard ["database disk", "", "", "1) /dev/a: 10 MB", "", - "2) Don't partition the disk", "", "", + "2) Don't partition the disk", "", + "(1) ", "", "Choose the database disk: |1| "] end end @@ -328,28 +329,28 @@ say "" expect_cls expect(subject.ask_with_menu("q?", %w(a b), 1)).to eq("a") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the number of a menu option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, 1)).to eq("a1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the index of a menu hash key option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, "a")).to eq("a1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |1| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(1) ", "", "Choose the q?: |1| "] end it "defaults to the index of a menu hash value option" do say "" expect_cls expect(subject.ask_with_menu("q?", {"a" => "a1", "b" => "b1"}, "b1")).to eq("b1") - expect_heard ["q?", "", "", "1) a", "", "2) b", "", "", "Choose the q?: |2| "] + expect_heard ["q?", "", "", "1) a", "", "2) b", "", "(2) ", "", "Choose the q?: |2| "] end end From 033d152d29e9f441e7cc414cd942db1c69a5ab22 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 22 Aug 2022 13:58:10 -0400 Subject: [PATCH 4/7] drop highline $terminal This is replaced by HighLine.default_instance --- bin/appliance_console | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/appliance_console b/bin/appliance_console index d665edab..c6e47c31 100755 --- a/bin/appliance_console +++ b/bin/appliance_console @@ -8,19 +8,20 @@ Bundler.setup require 'manageiq-appliance_console' require 'fileutils' +# defines globally /via kernal: agree(), ask(), choose() and say() require 'highline/import' -require 'highline/system_extensions' require 'rubygems' require 'bcrypt' require 'linux_admin' require 'manageiq/appliance_console/postgres_admin' require 'awesome_spawn' -include HighLine::SystemExtensions require 'manageiq/appliance_console/i18n' -$terminal.wrap_at = 80 -$terminal.page_at = 35 +HighLine.default_instance.tap do |highline| + highline.wrap_at = 80 + highline.page_at = 35 +end def summary_entry(field, value) dfield = "#{field}:" @@ -141,7 +142,7 @@ Welcome to the #{I18n.t("product.name")} Virtual Appliance. To modify the configuration, use a web browser to access the management page. -#{$terminal.list(summary_attributes)} +#{HighLine.default_instance.list(summary_attributes)} EOL press_any_key From 59d85437ac7d11a46d182c349a964e893b6114c5 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Mon, 9 Jan 2023 20:58:34 -0500 Subject: [PATCH 5/7] move postgres dependency to dependencies --- bin/appliance_console | 1 - lib/manageiq-appliance_console.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/appliance_console b/bin/appliance_console index c6e47c31..8e2169df 100755 --- a/bin/appliance_console +++ b/bin/appliance_console @@ -13,7 +13,6 @@ require 'highline/import' require 'rubygems' require 'bcrypt' require 'linux_admin' -require 'manageiq/appliance_console/postgres_admin' require 'awesome_spawn' require 'manageiq/appliance_console/i18n' diff --git a/lib/manageiq-appliance_console.rb b/lib/manageiq-appliance_console.rb index d6b2b085..455e0988 100644 --- a/lib/manageiq-appliance_console.rb +++ b/lib/manageiq-appliance_console.rb @@ -43,6 +43,7 @@ def self.logger require 'manageiq/appliance_console/message_configuration_server' require 'manageiq/appliance_console/oidc_authentication' require 'manageiq/appliance_console/principal' +require 'manageiq/appliance_console/postgres_admin' require 'manageiq/appliance_console/saml_authentication' require 'manageiq/appliance_console/scap' require 'manageiq/appliance_console/temp_storage_configuration' From 40c910fa41f40fe6404a4c7130d75c00c975abbc Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 21 Mar 2023 13:02:25 -0400 Subject: [PATCH 6/7] enable (remove pending) for database admin spec --- spec/database_admin_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/database_admin_spec.rb b/spec/database_admin_spec.rb index de91ed62..3f2a03ac 100644 --- a/spec/database_admin_spec.rb +++ b/spec/database_admin_spec.rb @@ -555,8 +555,6 @@ def confirm_and_execute context "when excluding tables" do it "asks to input tables, providing an example and sensible defaults" do - pending "something is wrong with this test and the readline mocking on CI" if ENV["CI"] - say ["y", "metrics_*"] expect(subject.ask_for_tables_to_exclude_in_dump).to be_truthy expect_output <<-EXAMPLE.strip_heredoc.chomp From ff01d191f8fdfd702526b5e8d6cdb8732b0e99b8 Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 21 Mar 2023 13:21:31 -0400 Subject: [PATCH 7/7] drop STDIN.tty? hack this was necessary to get older version of highline up and running in rails see #178 df5cffb3579 --- lib/manageiq/appliance_console/prompts.rb | 6 +++++- spec/spec_helper.rb | 12 ------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/manageiq/appliance_console/prompts.rb b/lib/manageiq/appliance_console/prompts.rb index 6da629cc..f9363195 100644 --- a/lib/manageiq/appliance_console/prompts.rb +++ b/lib/manageiq/appliance_console/prompts.rb @@ -34,7 +34,11 @@ def ask_for_uri(prompt, expected_scheme, opts = {}) def press_any_key say("\nPress any key to continue.") - STDIN.noecho(&:getch) + HighLine.default_instance.tap do |highline| + highline.terminal.raw_no_echo_mode_exec do + highline.terminal.get_character + end + end end def clear_screen diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f87f0859..5097bdce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,18 +3,6 @@ SimpleCov.start end -# In GitHub Actions (CI), we do not have a tty, so the various tests that use -# STDIN in order to test interactivity will fail. This code creates a psuedo-tty -# in that environment. If you want to test locally in a "non-tty" way, you can -# run the tests as follows: `true | bundle exec rake 2>&1 | cat` -unless STDIN.tty? - require "pty" - require "io/console" - _master_io, slave_file = PTY.open - slave_file.raw! - STDIN.reopen(slave_file) -end - require "manageiq-appliance_console" ManageIQ::ApplianceConsole.logger = Logger.new("/dev/null")