View | Details | Raw Unified | Return to bug 41682
Collapse All | Expand All

(-)a/t/db_dependent/check_sysprefs.t (-10 / +14 lines)
Lines 32-43 my $root_dir = $intranetdir . '/installer/data/mysql/mandatory'; Link Here
32
my $syspref_filepath = "$root_dir/sysprefs.sql";
32
my $syspref_filepath = "$root_dir/sysprefs.sql";
33
33
34
my @lines            = read_file($syspref_filepath) or die "Can't open $syspref_filepath: $!";
34
my @lines            = read_file($syspref_filepath) or die "Can't open $syspref_filepath: $!";
35
my $sysprefs_in_file = get_sysprefs_from_file(@lines);
35
my @sysprefs_in_file = get_sysprefs_from_file(@lines);
36
36
37
subtest 'Compare database with sysprefs.sql file' => sub {
37
subtest 'Compare database with sysprefs.sql file' => sub {
38
    ok( scalar( keys %$sysprefs_in_file ), "Found sysprefs" );
38
    ok( scalar(@sysprefs_in_file), "Found sysprefs" );
39
39
40
    check_db($sysprefs_in_file);
40
    check_db(@sysprefs_in_file);
41
};
41
};
42
42
43
subtest 'Compare sysprefs.sql with YAML files' => sub {
43
subtest 'Compare sysprefs.sql with YAML files' => sub {
Lines 47-53 subtest 'Compare sysprefs.sql with YAML files' => sub { Link Here
47
    my @yaml_mod   = @$yaml_prefs;
47
    my @yaml_mod   = @$yaml_prefs;
48
    @yaml_mod = grep !/marcflavour/, @yaml_mod;    # Added by web installer
48
    @yaml_mod = grep !/marcflavour/, @yaml_mod;    # Added by web installer
49
49
50
    my @syspref_names_in_file = keys %$sysprefs_in_file;
50
    my @syspref_names_in_file = map { $_->{variable} } @sysprefs_in_file;
51
    @syspref_names_in_file = grep !/ElasticsearchIndexStatus_authorities/,
51
    @syspref_names_in_file = grep !/ElasticsearchIndexStatus_authorities/,
52
        @syspref_names_in_file;                    # Not to be changed manually
52
        @syspref_names_in_file;                    # Not to be changed manually
53
    @syspref_names_in_file = grep !/ElasticsearchIndexStatus_biblios/,
53
    @syspref_names_in_file = grep !/ElasticsearchIndexStatus_biblios/,
Lines 79-85 subtest 'Compare sysprefs.sql with YAML files' => sub { Link Here
79
#
79
#
80
sub get_sysprefs_from_file {
80
sub get_sysprefs_from_file {
81
    my @lines = @_;
81
    my @lines = @_;
82
    my $sysprefs;
82
    my @sysprefs;
83
    for my $line (@lines) {
83
    for my $line (@lines) {
84
        chomp $line;
84
        chomp $line;
85
        next if $line =~ /^INSERT INTO /;    # first line
85
        next if $line =~ /^INSERT INTO /;    # first line
Lines 111-117 sub get_sysprefs_from_file { Link Here
111
            }
111
            }
112
112
113
            # FIXME Explode if already exists?
113
            # FIXME Explode if already exists?
114
            $sysprefs->{$variable} = {
114
            push @sysprefs, {
115
                variable    => $variable,
115
                variable    => $variable,
116
                value       => $value,
116
                value       => $value,
117
                options     => $options,
117
                options     => $options,
Lines 122-128 sub get_sysprefs_from_file { Link Here
122
            die "$line does not match";
122
            die "$line does not match";
123
        }
123
        }
124
    }
124
    }
125
    return $sysprefs;
125
    return @sysprefs;
126
}
126
}
127
127
128
#  Get system preferences from YAML files
128
#  Get system preferences from YAML files
Lines 157-168 sub check_db { Link Here
157
157
158
    # Checking the number of sysprefs in the database
158
    # Checking the number of sysprefs in the database
159
    my @syspref_names_in_db   = keys %$sysprefs_in_db;
159
    my @syspref_names_in_db   = keys %$sysprefs_in_db;
160
    my @syspref_names_in_file = keys %$sysprefs_in_file;
160
    my @syspref_names_in_file = map { $_->{variable} } @sysprefs_in_file;
161
    my @diff                  = array_minus @syspref_names_in_db, @syspref_names_in_file;
161
    my @diff                  = array_minus @syspref_names_in_db, @syspref_names_in_file;
162
    is_deeply( [ sort @diff ], [ 'Version', 'marcflavour' ] )
162
    is_deeply( [ sort @diff ], [ 'Version', 'marcflavour' ] )
163
        or diag sprintf( "Too many sysprefs in DB: %s", join ", ", @diff );
163
        or diag sprintf( "Too many sysprefs in DB: %s", join ", ", @diff );
164
164
165
    for my $pref ( sort values %$sysprefs_in_file ) {
165
    my @sorted_names_in_file = sort {
166
        $b =~ s/_/ZZZ/g;    # mysql sorts underscore last, if you modify this qa-test-tools will need adjustements
167
        lc($a) cmp lc($b)
168
    } @syspref_names_in_file;
169
    is_deeply( \@syspref_names_in_file, \@sorted_names_in_file, 'Syspref in sysprefs.sql must be sorted by name' );
170
    for my $pref (@sysprefs_in_file) {
166
        my $in_db     = $sysprefs_in_db->{ $pref->{variable} };
171
        my $in_db     = $sysprefs_in_db->{ $pref->{variable} };
167
        my %db_copy   = %$in_db;
172
        my %db_copy   = %$in_db;
168
        my %file_copy = %$pref;
173
        my %file_copy = %$pref;
169
- 

Return to bug 41682