From 78e8b99c863d3ac704cc067206ccceb8d3982cb7 Mon Sep 17 00:00:00 2001 From: "robert.richardson" Date: Thu, 17 Oct 2024 21:44:02 +0200 Subject: [PATCH 1/2] Remove unused import in t/10-jobs.t --- t/10-jobs.t | 1 - 1 file changed, 1 deletion(-) diff --git a/t/10-jobs.t b/t/10-jobs.t index 266a235a43c..40a3b2fc0de 100644 --- a/t/10-jobs.t +++ b/t/10-jobs.t @@ -14,7 +14,6 @@ use FindBin; use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib"; use Mojo::Base -signatures; use autodie ':all'; -use Encode; use File::Copy; use OpenQA::Jobs::Constants; use OpenQA::Test::Case; From b7ab64d68258f3ca1578ad06226ae12e216351b7 Mon Sep 17 00:00:00 2001 From: "robert.richardson" Date: Wed, 16 Oct 2024 10:43:39 +0200 Subject: [PATCH 2/2] Consistently handle settings with multiple values Using JSON syntax to consistently store array values. Related ticket: https://progress.opensuse.org/issues/166154 --- lib/OpenQA/Schema/ResultSet/Jobs.pm | 9 ++++++++- t/10-jobs.t | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/OpenQA/Schema/ResultSet/Jobs.pm b/lib/OpenQA/Schema/ResultSet/Jobs.pm index 494ddb1f98d..bc2b3a201b1 100644 --- a/lib/OpenQA/Schema/ResultSet/Jobs.pm +++ b/lib/OpenQA/Schema/ResultSet/Jobs.pm @@ -6,6 +6,7 @@ package OpenQA::Schema::ResultSet::Jobs; use Mojo::Base 'DBIx::Class::ResultSet', -signatures; use DBIx::Class::Timestamps 'now'; use Date::Format 'time2str'; +use Encode qw(decode_utf8); use File::Basename 'basename'; use IPC::Run; use OpenQA::App; @@ -112,7 +113,7 @@ sub create_from_settings { my ($self, $settings, $scheduled_product_id) = @_; my %settings = %$settings; - my %new_job_args = (TEST => $settings{TEST}); + my %new_job_args; my $result_source = $self->result_source; my $schema = $result_source->schema; @@ -171,6 +172,12 @@ sub create_from_settings { } } + for my $key (keys %settings) { + my $value = $settings{$key}; + $settings{$key} = decode_utf8 encode_json $value if (ref $value eq 'ARRAY' || ref $value eq 'HASH'); + } + $new_job_args{TEST} = $settings{TEST}; + # move important keys from the settings directly to the job for my $key (OpenQA::Schema::Result::Jobs::MAIN_SETTINGS) { if (my $value = delete $settings{$key}) { $new_job_args{$key} = $value } diff --git a/t/10-jobs.t b/t/10-jobs.t index 40a3b2fc0de..b6e0079744e 100644 --- a/t/10-jobs.t +++ b/t/10-jobs.t @@ -25,6 +25,8 @@ use Mojo::JSON qw(decode_json encode_json); use OpenQA::Test::Utils qw(perform_minion_jobs); use OpenQA::Test::TimeLimit '30'; +binmode(STDOUT, ":encoding(UTF-8)"); + my $schema_name = OpenQA::Test::Database::generate_schema_name; my $schema = OpenQA::Test::Case->new->init_data( fixtures_glob => '01-jobs.pl 05-job_modules.pl 06-job_dependencies.pl', @@ -1005,4 +1007,16 @@ subtest 'get all setting values for a job/key in a sorted array' => sub { is_deeply $job_settings->all_values_sorted(99926, 'WORKER_CLASS'), [qw(bar baz foo)], 'all values returned'; }; +subtest 'handling of array and unicode settings' => sub { + my %s = %settings; + $s{TEST} = 'array_setting_test'; + $s{ARRAY_SETTING} = ['value1', 'ä', '…']; + my $job = _job_create(\%s); + my $entry = $job->settings->find({key => 'ARRAY_SETTING'}); + ok $entry, 'ARRAY_SETTING exists in job settings'; + my $v = $entry->value; + is ref($v), '', 'ARRAY_SETTING value is stored as a string'; + is $v, '["value1","ä","…"]', 'retrieved correctly encoded JSON array as string'; +}; + done_testing();