Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Highline 2.1.0 #201

Merged
merged 7 commits into from
Mar 21, 2023
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
12 changes: 6 additions & 6 deletions bin/appliance_console
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ 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}:"
Expand Down Expand Up @@ -141,7 +141,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
Expand Down
1 change: 1 addition & 0 deletions lib/manageiq-appliance_console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion lib/manageiq/appliance_console/prompts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manageiq-appliance_console.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 4 additions & 9 deletions spec/database_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -555,22 +555,17 @@ 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

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
Expand Down
11 changes: 6 additions & 5 deletions spec/prompts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 0 additions & 12 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
10 changes: 1 addition & 9 deletions spec/support/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+')
Expand Down Expand Up @@ -56,22 +57,13 @@ 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)
end

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
Expand Down