Skip to content

Commit

Permalink
Merge pull request #1890 from M0ses/test_kiwi_product
Browse files Browse the repository at this point in the history
Test kiwi product and fix disabled test
  • Loading branch information
M0ses committed Jun 21, 2016
2 parents 25935a8 + 33018f7 commit 91b2a5e
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 44 deletions.
102 changes: 96 additions & 6 deletions src/backend/BSHTTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ use Fcntl qw(:DEFAULT);

use strict;

=head1 NAME
BSHTTP
=cut

=head1 SYNOPSIS
TODO
=cut

=head1 DESCRIPTION
This library contains functions to handle http requests in obs
=cut

=head1 FUNCTIONS / METHODS
=cut


sub gethead {
my ($h, $t) = @_;

Expand All @@ -51,12 +74,30 @@ sub unexpected_eof {
die("unexpected EOF\n");
}

#
# read data from socket, do chunk decoding if needed
# req: request data
# maxl = undef: read as much as you can
# exact = 1: read maxl data, maxl==undef -> read to eof;
#

=head2 BSHTTP::read_data
read data from socket, do chunk decoding if needed
my $ret = BSHTTP::read_data(
# request data
{
headers => {
transfer-encoding => 'chunked'
content-length => ...
}, #
__socket => <FILEHANDLE> , # filehandle to socket or opened file
__cl => ... , #
__data
},
$maxl, # if undef read as much as you can
$exact, # Boolean
# if 1 read maxl data
# if maxl == undef -> read to eof
);
=cut

sub read_data {
my ($req, $maxl, $exact) = @_;

Expand Down Expand Up @@ -206,6 +247,55 @@ sub file_receiver {
return $res;
}


=head2 BSHTTP::cpio_receiver
TODO: add meaningful explanation
my $result = BSHTTP::cpio_receiver(
# options given to read_data
{
... # SEE BSHTTP::read_data
},
# all parameters are optional
{
directory => <STRING> , # store files in given directory
# (Otherwise data is stored in $result->[]
withmd5 => <BOOLEAN> , #
acceptsubdirs => <BOOLEAN> , #
createsubdirs => <BOOLEAN> , #
accept => <REGEX|CODEREF> , # Check included files
# by regex or function
map => <REGEX|CODEREF> , # Rename files
# by regex or function
no_unlink => <BOOLEAN> , # Do not remove already existent
# (sub)directories. Only relevant
# if directory is given
#
cpiopostfile => ... , #
}
);
# returns an ArrayRef of HashRefs
# $result = [
# {
# name => <STRING> , # filename
# size => ...
# mtime => ... ,
# mode => ... ,
# md5 => <STRING> , # md5 as hexdigest
# # only if withmd5 was true
# data => <BINARYDATA> , # binary data from file
# # only if no directory was given
# },
# {
# ....
# },
# ....
# ];
=cut

sub cpio_receiver {
my ($req, $param) = @_;
my @res;
Expand Down
6 changes: 5 additions & 1 deletion src/backend/BSRepServer/BuildInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use BSFileDB;
use BSXML;
use Build;
use BSSolv;

# required for orderpackids
use BSSched::ProjPacks;

use BSRepServer;
use BSRepServer::Checker;
use BSRepServer::BuildInfo::Generic;
Expand Down Expand Up @@ -212,7 +216,7 @@ sub getkiwiproductpackages_compat {
my $reporoot = $self->{gctx}->{reporoot};

my $depends = BSUtil::retrieve("$self->{gctx}->{reporoot}/$aprp/$arch/:depends", 1);
next unless $depends && $depends->{'subpacks'};
return unless $depends && $depends->{'subpacks'};
my %apackids = (%{$depends->{'subpacks'} || {}}, %{$depends->{'pkgdeps'}});
for my $apackid (BSSched::ProjPacks::orderpackids({'kind' => $aprojidkind}, keys %apackids)) {
next if $apackid eq '_volatile';
Expand Down
80 changes: 50 additions & 30 deletions src/backend/t/0370-BSRepServer-BuildInfo-KiwiImage.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Test::Mock::BSConfig;
use Test::OBS::Utils;
use Test::Mock::BSRepServer::Checker;

use Test::More tests => 3; # last test to print
use Test::More tests => 5; # last test to print

use BSUtil;
use BSXML;
Expand Down Expand Up @@ -38,56 +38,76 @@ use_ok("BSRepServer::BuildInfo");

my ($got,$expected);


# Test Case 01
{
($got) = BSRepServer::BuildInfo->new(projid=>'home:M0ses:kanku:Images', repoid=>'images', arch=>'x86_64', packid=>'openSUSE-Leap-42.1-JeOS')->getbuildinfo();
local *STDOUT;
my $out;
open(STDOUT,">",\$out);

$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc01", $BSXML::buildinfo);
($got) = BSRepServer::BuildInfo->new(projid=>'home:M0ses:kanku:Images', repoid=>'images', arch=>'x86_64', packid=>'openSUSE-Leap-42.1-JeOS')->getbuildinfo();

$got->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$got->{'bdep'} || []} ];
$expected->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$expected->{'bdep'} || []} ];
$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc01", $BSXML::buildinfo);
}

clean_results($got,$expected);

is_deeply($got, $expected, 'buildinfo for Kiwi Image');


# Test Case 02
{
local *STDOUT;
my $out;
open(STDOUT,">",\$out);

local *STDOUT;
my $out;
open(STDOUT,">",\$out);
($got) = BSRepServer::BuildInfo->new(projid=>'home:Admin:branches:openSUSE.org:home:M0ses:kanku:Images', repoid=>'images', arch=>'x86_64', packid=>'openSUSE-Leap-42.1-JeOS')->getbuildinfo();

($got) = BSRepServer::BuildInfo->new(projid=>'home:Admin:branches:openSUSE.org:home:M0ses:kanku:Images', repoid=>'images', arch=>'x86_64', packid=>'openSUSE-Leap-42.1-JeOS')->getbuildinfo();

#my $data = BSUtil::readstr("$BSConfig::bsdir/result/tc02");
#eval "$data";
$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc02", $BSXML::buildinfo);
}

$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc02", $BSXML::buildinfo);
clean_results($got,$expected);

$got->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$got->{'bdep'} || []} ];
$expected->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$expected->{'bdep'} || []} ];
}
is_deeply($got, $expected, 'buildinfo for Kiwi Image with remotemap');

# Test Case 03 (does *not* test kiwi images, thus currently disabled
# Test Case 03
{
local *STDOUT;
my $out;
open(STDOUT,">",\$out);

($got) = BSRepServer::BuildInfo->new(projid=>'home:Admin:branches:openSUSE.org:OBS:Server:Unstable', repoid=>'openSUSE_Leap_42.1', arch=>'x86_64', packid=>'_product:OBS-Addon-release')->getbuildinfo();

#local *STDOUT;
#my $out;
#open(STDOUT,">",\$out);
# openSUSE.org:OBS:Server:Unstable" repository="openSUSE_42.1" package="_product"
# home:Admin:branches:openSUSE.org:OBS:Server:Unstable/_product:OBS-Addon-release/openSUSE_Leap_42.1/x86_64
($got) = BSRepServer::BuildInfo->new(projid=>'home:Admin:branches:openSUSE.org:OBS:Server:Unstable', repoid=>'openSUSE_Leap_42.1', arch=>'x86_64', packid=>'_product:OBS-Addon-release')->getbuildinfo();
$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc03", $BSXML::buildinfo);
}

#my $data = BSUtil::readstr("$BSConfig::bsdir/result/tc02");
#eval "$data";
clean_results($got,$expected);

$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc03", $BSXML::buildinfo);
is_deeply($got, $expected, 'buildinfo for regular Package with remotemap');

print "$got->{release}\n";
$got->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$got->{'bdep'} || []} ];
$expected->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$expected->{'bdep'} || []} ];
# Test Case 04
{
local *STDOUT;
my $out;
open(STDOUT,">",\$out);

($got) = BSRepServer::BuildInfo->new(projid=>'home:Admin:branches:openSUSE.org:OBS:Server:2.7', repoid=>'images', arch=>'x86_64', packid=>'_product:OBS-Addon-cd-cd-x86_64')->getbuildinfo();

$expected = Test::OBS::Utils::readxmlxz("$BSConfig::bsdir/result/tc04", $BSXML::buildinfo);
}
#is_deeply($got, $expected, 'buildinfo for Kiwi Image with remotemap');

clean_results($got,$expected);

is_deeply($got, $expected, 'buildinfo for Kiwi Product with remotemap');

exit 0;

sub clean_results {
my ($got,$expected) = @_;

$got->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$got->{'bdep'} || []} ];
$expected->{'bdep'} = [ sort {$a->{'name'} cmp $b->{'name'}} @{$expected->{'bdep'} || []} ];
$got->{subpack} = [ sort { $a cmp $b } @{ $got->{subpack} || [] } ];
$expected->{subpack} = [ sort { $a cmp $b } @{ $expected->{subpack} || [] } ];

};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.6.90-1|1|3a468537adffc6af743db618735e5183|1|1466174821|314
Binary file not shown.
Binary file modified src/backend/t/data/0370/result/tc03.xz
Binary file not shown.
Binary file added src/backend/t/data/0370/result/tc04.xz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 32 additions & 7 deletions src/backend/t/lib/Test/Mock/BSRPC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ BEGIN {
$_ = BSRPC::urlencode($_);
s/%3D/=/;
}

my $org_uri = $uri;

$uri = "$uri?" . join('&', @args);
if ($Test::Mock::BSRPC::fixtures_map->{$uri}) {
$uri = $Test::Mock::BSRPC::fixtures_map->{$uri}
Expand All @@ -43,15 +46,37 @@ BEGIN {
}
$uri = "$BSConfig::bsdir/$uri";

my $ret = Test::OBS::Utils::readstrxz($uri);
die("missing fixture: $uri\n") unless defined $ret;
my $receiver = $param->{'receiver'};
if ($receiver) {
$ret = $receiver->(BSHTTP::str2req($ret), $param, $xmlargs || $param->{'receiverarg'}) if $receiver;
} elsif ($xmlargs) {
$ret = BSUtil::fromxml($ret, $xmlargs);
my $ret;
eval {
$ret = Test::OBS::Utils::readstrxz($uri);

die("missing fixture: $uri") unless defined $ret;

my $receiver = $param->{'receiver'};
if ($receiver) {
$ret = $receiver->(BSHTTP::str2req($ret), $param, $xmlargs || $param->{'receiverarg'}) if $receiver;
} elsif ($xmlargs) {
$ret = BSUtil::fromxml($ret, $xmlargs);
}
};

if ( $@ ) {
die ("
$@
Use the following command line to generate them:
curl \"$org_uri\" > \"$uri\"
to compress them use:
xz \"$uri\"
");
}

return $ret;

};
}

Expand Down

0 comments on commit 91b2a5e

Please sign in to comment.