Skip to content

Commit

Permalink
Merge branch 'main' into scratch-dev-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaumik-Ashraf authored Nov 21, 2024
2 parents 4d63700 + 88bc16c commit 75eea1b
Show file tree
Hide file tree
Showing 29 changed files with 362 additions and 129 deletions.
58 changes: 29 additions & 29 deletions client/src/components/InputsModal/AuthTypeSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import React, { FC } from 'react';
import { TestInput } from '~/models/testSuiteModels';
import { InputOption, TestInput } from '~/models/testSuiteModels';
import InputCombobox from './InputCombobox';

export interface InputAccessProps {
requirement: TestInput;
input: TestInput;
index: number;
inputsMap: Map<string, unknown>;
setInputsMap: (map: Map<string, unknown>, edited?: boolean) => void;
}

const AuthTypeSelector: FC<InputAccessProps> = ({
requirement,
index,
inputsMap,
setInputsMap,
}) => {
const selectorSettings = requirement.options?.components
? requirement.options?.components[0]
const AuthTypeSelector: FC<InputAccessProps> = ({ input, index, inputsMap, setInputsMap }) => {
const selectorSettings = input.options?.components
? input.options?.components[0]
: // Default auth type settings
{
name: 'auth_type',
default: 'public',
};

const selectorOptions: InputOption[] =
input.options?.components?.find((component) => component.name === 'auth_type')?.options
?.list_options ||
([
{
label: 'Public',
value: 'public',
},
{
label: 'Confidential Symmetric',
value: 'symmetric',
},
{
label: 'Confidential Asymmetric',
value: 'asymmetric',
},
{
label: 'Backend Services',
value: 'backend_services',
},
] as InputOption[]);

const selectorModel: TestInput = {
name: 'auth_type',
type: 'select',
title: 'Auth Type',
description: requirement.description,
description: input.description,
default: selectorSettings.default || 'public',
optional: selectorSettings.optional,
locked: selectorSettings.locked,
options: {
list_options: [
{
label: 'Public',
value: 'public',
},
{
label: 'Confidential Symmetric',
value: 'symmetric',
},
{
label: 'Confidential Asymmetric',
value: 'asymmetric',
},
{
label: 'Backend Services',
value: 'backend_services',
},
],
list_options: selectorOptions,
},
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/InputsModal/InputAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const InputAccess: FC<InputAccessProps> = ({ requirement, index, inputsMap, setI
)}
<List>
<AuthTypeSelector
requirement={requirement}
input={requirement}
index={index}
inputsMap={accessValues}
setInputsMap={updateAuthType}
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/InputsModal/InputAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const InputAuth: FC<InputAuthProps> = ({ requirement, index, inputsMap, setInput
)}
<List>
<AuthTypeSelector
requirement={requirement}
input={requirement}
index={index}
inputsMap={authValues}
setInputsMap={updateAuthType}
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/InputsModal/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export default makeStyles()((theme: Theme) => ({
fontWeight: 600,
color: theme.palette.common.grayDarkest,
},
'& label.Mui-focused': {
'& > label.Mui-focused': {
color: theme.palette.secondary.main,
},
'& label.Mui-disabled': {
'& > label.Mui-disabled': {
color: theme.palette.common.gray,
},
'& label.Mui-error': {
'& > label.Mui-error': {
color: theme.palette.error.main,
},
},
Expand Down
3 changes: 2 additions & 1 deletion inferno_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Gem::Specification.new do |spec|
'lib/inferno/public/assets.json',
'spec/support/factory_bot.rb',
Dir['spec/factories/**/*.rb'],
Dir['spec/fixtures/**/*.rb']
Dir['spec/fixtures/**/*.rb'],
Dir['spec/*.rb']
].flatten

spec.bindir = 'bin'
Expand Down
21 changes: 15 additions & 6 deletions lib/inferno/apps/cli/execute.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
require 'pastel'
require 'active_support'
require_relative '../../utils/verify_runnable'
require_relative '../../utils/persist_inputs'
require_relative 'execute/console_outputter'
require_relative '../../result_summarizer'

Dir[File.join(__dir__, 'execute', '*_outputter.rb')].each { |outputter| require outputter }

module Inferno
module CLI
class Execute
include ::Inferno::Utils::VerifyRunnable
include ::Inferno::Utils::PersistInputs

OUTPUTTERS = {
'console' => Inferno::CLI::Execute::ConsoleOutputter,
'plain' => Inferno::CLI::Execute::PlainOutputter,
'json' => Inferno::CLI::Execute::JSONOutputter,
'quiet' => Inferno::CLI::Execute::QuietOutputter
}.freeze

attr_accessor :options

def self.suppress_output
Expand Down Expand Up @@ -88,8 +94,12 @@ def print_help_and_exit
end

def outputter
# TODO: swap outputter based on options
@outputter ||= Inferno::CLI::Execute::ConsoleOutputter.new
unless OUTPUTTERS.key? options[:outputter]
raise StandardError,
"Unrecognized outputter #{options[:outputter]}"
end

@outputter ||= OUTPUTTERS[options[:outputter]].new
end

def all_selected_groups_and_tests
Expand Down Expand Up @@ -164,7 +174,6 @@ def create_params(test_session, runnable)
end

def dispatch_job(test_run)
# TODO: move suppression to outputter? better suppression?
if options[:verbose]
Jobs.perform(Jobs::ExecuteTestRun, test_run.id, force_synchronous: true)
else
Expand Down
47 changes: 18 additions & 29 deletions lib/inferno/apps/cli/execute/console_outputter.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'pastel'
require_relative '../../web/serializers/test_run'
require_relative '../../web/serializers/result'
require_relative 'serialize'

module Inferno
module CLI
class Execute
# @private
class ConsoleOutputter
COLOR = Pastel.new
CHECKMARK = "\u2713".freeze
BAR = ('=' * 80).freeze

include Serialize

def print_start_message(options)
puts ''
puts BAR
Expand All @@ -23,7 +23,6 @@ def print_start_message(options)

def print_around_run(_options)
puts 'Running tests. This may take a while...'
# TODO: spinner/progress bar
yield
end

Expand All @@ -46,15 +45,18 @@ def print_results(options, results)

def print_end_message(options); end

def print_error(options, exception)
puts COLOR.red "Error: #{exception.full_message}"
verbose_print(options, exception.backtrace&.join('\n'))
def print_error(_options, exception)
puts color.red "Error: #{exception.full_message}"
end

# private

def verbose_print(options, *args)
print(COLOR.dim(*args)) if options[:verbose]
print(color.dim(*args)) if options[:verbose]
end

def color
@color ||= Pastel.new(enabled: $stdout.tty?)
end

def verbose_puts(options, *args)
Expand Down Expand Up @@ -106,21 +108,21 @@ def format_outputs(result)
def format_result(result) # rubocop:disable Metrics/CyclomaticComplexity
case result.result
when 'pass'
COLOR.bold.green(CHECKMARK, ' pass')
color.bold.green(CHECKMARK, ' pass')
when 'fail'
COLOR.bold.red 'X fail'
color.bold.red 'X fail'
when 'skip'
COLOR.yellow '* skip'
color.yellow '* skip'
when 'omit'
COLOR.blue '* omit'
color.blue '* omit'
when 'error'
COLOR.magenta 'X error'
color.magenta 'X error'
when 'wait'
COLOR.bold '. wait'
color.bold '. wait'
when 'cancel'
COLOR.red 'X cancel'
color.red 'X cancel'
when 'running'
COLOR.bold '- running'
color.bold '- running'
else
raise StandardError.new, "Unrecognized result #{result.result}"
end
Expand All @@ -133,19 +135,6 @@ def verbose_print_json_results(options, results)
verbose_puts(options, serialize(results))
verbose_puts(options, BAR)
end

def serialize(entity)
case entity.class.to_s
when 'Array'
JSON.pretty_generate(entity.map { |item| JSON.parse serialize(item) })
when lambda { |x|
defined?(x.constantize) && defined?("Inferno::Web::Serializers::#{x.split('::').last}".constantize)
}
"Inferno::Web::Serializers::#{entity.class.to_s.split('::').last}".constantize.render(entity)
else
raise StandardError, "CLI does not know how to serialize #{entity.class}"
end
end
end
end
end
Expand Down
28 changes: 28 additions & 0 deletions lib/inferno/apps/cli/execute/json_outputter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'serialize'

module Inferno
module CLI
class Execute
# @private
class JSONOutputter
include Serialize

def print_start_message(_options); end

def print_around_run(_options, &)
yield
end

def print_results(_options, results)
puts serialize(results)
end

def print_end_message(_options); end

def print_error(_options, exception)
puts exception.to_json
end
end
end
end
end
18 changes: 18 additions & 0 deletions lib/inferno/apps/cli/execute/plain_outputter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'console_outputter'

module Inferno
module CLI
class Execute
# @private
class PlainOutputter < ConsoleOutputter
def print_error(_options, exception)
puts "Error: #{exception.full_message(highlight: false)}"
end

def color
@color ||= Pastel.new(enabled: false)
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/inferno/apps/cli/execute/quiet_outputter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Inferno
module CLI
class Execute
# @private
class QuietOutputter
def print_start_message(_options); end

def print_around_run(_options, &)
yield
end

def print_results(_options, _results); end

def print_end_message(_options); end

def print_error(options, exception)
puts "Error: #{exception.full_message}" if options[:verbose]
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/inferno/apps/cli/execute/serialize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'active_support'
require_relative '../../web/serializers/test_run'
require_relative '../../web/serializers/result'

module Inferno
module CLI
class Execute
# @private
module Serialize
def serialize(entity)
case entity.class.to_s
when 'Array'
JSON.pretty_generate(entity.map { |item| JSON.parse serialize(item) })
else
Inferno::Web::Serializers.const_get(entity.class.to_s.demodulize).render(entity)
end
end
end
end
end
end
Loading

0 comments on commit 75eea1b

Please sign in to comment.