aboutsummaryrefslogtreecommitdiff
path: root/tests/submit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/submit')
-rw-r--r--tests/submit/buildfile10
-rw-r--r--tests/submit/data.testscript22
-rw-r--r--tests/submit/submit-dir.testscript12
-rw-r--r--tests/submit/submit-git.testscript133
-rw-r--r--tests/submit/submit-pub.testscript213
5 files changed, 363 insertions, 27 deletions
diff --git a/tests/submit/buildfile b/tests/submit/buildfile
index aaffede..a90115a 100644
--- a/tests/submit/buildfile
+++ b/tests/submit/buildfile
@@ -1,5 +1,4 @@
# file : tests/submit/buildfile
-# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
dir = ../../brep/handler/submit/
@@ -8,9 +7,12 @@ include $dir
commons = data
-./: testscript{* -{$commons}} common_testscript{$commons} {*/ -test/}{**} \
- $dir/exe{brep-submit-dir} $dir/exe{brep-submit-git} file{hello.tar.gz} \
- doc{README}
+./: testscript{* -{$commons}} common_testscript{$commons} {*/ -test/}{**} \
+ $dir/exe{brep-submit-dir} \
+ $dir/exe{brep-submit-git} \
+ $dir/exe{brep-submit-pub} \
+ file{hello.tar.gz} doc{README}
testscript{submit-dir}@./: test = $out_base/$dir/brep-submit-dir
testscript{submit-git}@./: test = $out_base/$dir/brep-submit-git
+testscript{submit-pub}@./: test = $out_base/$dir/brep-submit-pub
diff --git a/tests/submit/data.testscript b/tests/submit/data.testscript
index 70507d5..b0fe8f0 100644
--- a/tests/submit/data.testscript
+++ b/tests/submit/data.testscript
@@ -1,15 +1,15 @@
# file : tests/submit/data.testscript
-# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
# Pre-created submission data directory that will be copied by subsequent
# tests and scope setup commands. The common approach will be that group
-# scopes copy and modify the parent scope submission directory as required by
-# the nested tests and scopes. Tests will also clone the parent scope
-# submission data directory to optionally modify it, use and cleanup at the
-# end. Note that configuration can not be shared between multiple submission
-# handler processes. Also we need to make sure that submission data
-# directories are not cloned while being used by submission handler scripts.
+# scopes copy and modify the parent scope submission data directory as
+# required by the nested tests and scopes. Tests will also clone the parent
+# scope submission data directory to optionally modify it, use and cleanup at
+# the end. Note that submission data directory can not be shared between
+# multiple submission handler processes. Also we need to make sure that
+# submission data directories are not cloned while being used by submission
+# handler scripts.
#
data_dir = $regex.replace($path_search('*/request.manifest', $src_base), \
'(.*)/.*', \
@@ -26,10 +26,10 @@ root_data_dir = $~/$data_dir
# The most commonly used submission data directory cloning command that copies
# it from the parent scope working directory.
#
-clone_data = cp --no-cleanup -r ../$data_dir ./
-clone_data_clean = cp --no-cleanup -r ../$data_dir ./ &$data_dir/***
+clone_data = [cmdline] cp --no-cleanup -r ../$data_dir ./
+clone_data_clean = [cmdline] cp --no-cleanup -r ../$data_dir ./ &$data_dir/***
# Clones the original submission data directory.
#
-clone_root_data = cp --no-cleanup -r $root_data_dir ./
-clone_root_data_clean = cp --no-cleanup -r $root_data_dir ./ &$data_dir/***
+clone_root_data = [cmdline] cp --no-cleanup -r $root_data_dir ./
+clone_root_data_clean = [cmdline] cp --no-cleanup -r $root_data_dir ./ &$data_dir/***
diff --git a/tests/submit/submit-dir.testscript b/tests/submit/submit-dir.testscript
index 4a0c619..285710f 100644
--- a/tests/submit/submit-dir.testscript
+++ b/tests/submit/submit-dir.testscript
@@ -1,5 +1,4 @@
# file : tests/submit/submit-dir.testscript
-# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
.include data.testscript
@@ -78,7 +77,16 @@
$* >>"EOO"
: 1
status: 400
- message: archive is not a valid package \(run bpkg pkg-verify for details\)
+ message:\\
+ package archive is not valid
+
+ gzip: libhello-0.1.0.tar.gz: not in gzip format
+ tar: This does not look like a tar archive
+ tar: libhello-0.1.0/manifest: Not found in archive
+ tar: Exiting with failure status due to previous errors
+ info: libhello-0.1.0.tar.gz does not appear to be a bpkg package
+ info: run bpkg pkg-verify for details
+ \\
reference: $checksum
EOO
}
diff --git a/tests/submit/submit-git.testscript b/tests/submit/submit-git.testscript
index 122c9ae..5197afc 100644
--- a/tests/submit/submit-git.testscript
+++ b/tests/submit/submit-git.testscript
@@ -1,5 +1,4 @@
# file : tests/submit/submit-git.testscript
-# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
.include data.testscript
@@ -10,19 +9,23 @@
#
# test.redirects += 2>!
-g = git 2>! >&2
+g = [cmdline] git 2>! >&2
# Create and clone the reference repository.
#
root_ref = $~/ref.git
root_ref_dir = $~/ref
-clone_root_ref = cp --no-cleanup -r $root_ref ./ &ref.git/***
+clone_root_ref = [cmdline] cp --no-cleanup -r $root_ref ./ &ref.git/***
+mkdir --no-cleanup $root_ref
+$g -C $root_ref init --bare &ref.git/***
-+$g clone $root_ref $root_ref_dir &ref/***
+# Convert specific warnings to infos as we expect them to appear. This, in
+# particular, prevents bbot workers to set task result status to warning.
+#
++git clone $root_ref $root_ref_dir &ref/*** 2>&1 | \
+ sed -e 's/warning: (.*cloned an empty repository.*)/info: \1/' >&2 2>!
+cat <<EOI >=$root_ref_dir/submit.config.bash
sections[alpha]=1/alpha
@@ -32,6 +35,8 @@ clone_root_ref = cp --no-cleanup -r $root_ref ./ &ref.git/***
owners=owners
EOI
++$g -C $root_ref_dir config user.name 'Test Script'
++$g -C $root_ref_dir config user.email 'testscript@example.com'
+$g -C $root_ref_dir add '*'
+$g -C $root_ref_dir commit -m 'Add submit.config.bash'
+$g -C $root_ref_dir push
@@ -43,7 +48,7 @@ root_tgt_url = "file:///$~/tgt.git"
+cp -r $root_ref $root_tgt
-clone_root_tgt = cp --no-cleanup -r $root_tgt ./ &tgt.git/***
+clone_root_tgt = [cmdline] cp --no-cleanup -r $root_tgt ./ &tgt.git/***
# Extract the package repository.
#
@@ -95,10 +100,10 @@ pkg_ctl="$prj_ctl/hello.git"
: success
:
{
- : ref-unknown-tgt-aquire-prj-pkg
+ : ref-unknown-tgt-acquire-prj-pkg
:
: Test that on the first package submission the project and package names
- : ownership is successfully aquired. Authentication is enabled on both the
+ : ownership is successfully acquired. Authentication is enabled on both the
: reference and target repos.
:
: Note that here we also test that --commiter-* options are picked up
@@ -174,7 +179,7 @@ pkg_ctl="$prj_ctl/hello.git"
: ref-disabled-tgt-aquire-prj-pkg
:
: Test that on the first package submit the project and package names
- : ownership is successfully aquired. Authentication is disabled for the
+ : ownership is successfully acquired. Authentication is disabled for the
: reference repo.
:
{
@@ -191,6 +196,8 @@ pkg_ctl="$prj_ctl/hello.git"
# owners=owners
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref commit -am 'Disable ownership';
$g -C ref push;
@@ -204,10 +211,10 @@ pkg_ctl="$prj_ctl/hello.git"
EOO
}
- : ref-absent-tgt-aquire-prj-pkg
+ : ref-absent-tgt-acquire-prj-pkg
:
: Test that on the first package submit the project and package names
- : ownership is successfully aquired. Reference repo is absent.
+ : ownership is successfully acquired. Reference repo is absent.
:
: Note that here we also pass the --result-url option.
:
@@ -252,6 +259,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $pkg_ctl
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt add owners;
$g -C tgt commit -m 'Add ownership info';
$g -C tgt push;
@@ -289,6 +298,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add ownership info';
$g -C ref push;
@@ -306,6 +317,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $pkg_ctl
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt add owners;
$g -C tgt commit -m 'Add ownership info';
$g -C tgt push;
@@ -358,6 +371,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $pkg_ctl
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add ownership info';
$g -C ref push;
@@ -393,6 +408,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add ownership info';
$g -C ref push;
@@ -426,6 +443,8 @@ pkg_ctl="$prj_ctl/hello.git"
# owners=owners
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt commit -am 'Disable ownership';
$g -C tgt push;
@@ -437,6 +456,78 @@ pkg_ctl="$prj_ctl/hello.git"
EOO
}
+ : ref-absent-tgt-pkg-rev
+ :
+ : Test that the package revision is removed.
+ :
+ {
+ $clone_root_data;
+
+ $clone_root_tgt;
+ $g clone tgt.git &tgt/***;
+
+ cat <<EOI >=tgt/submit.config.bash;
+ sections['*']=1/alpha
+ EOI
+
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
+ $g -C tgt commit -am 'Add config and archive';
+ $g -C tgt push;
+
+ # Initial submission.
+ #
+ $* "file:///$~/tgt.git" $data_dir >>"EOO";
+ : 1
+ status: 200
+ message: package submission is queued: libhello/0.1.0
+ reference: $checksum
+ EOO
+
+ $g -C tgt pull;
+
+ test -f tgt/1/alpha/hello/libhello-0.1.0.tar.gz;
+
+ # Revision submission.
+ #
+ # Here we test that the handler removes the previous revision.
+ #
+ $clone_root_data_clean;
+
+ tar -xf $~/$data_dir/libhello-0.1.0.tar.gz;
+ sed -i -e 's/(version: 0.1.0)/\1+1/' libhello-0.1.0/manifest;
+ mv libhello-0.1.0 libhello-0.1.0+1;
+ tar cfz $~/$data_dir/libhello-0.1.0+1.tar.gz libhello-0.1.0+1;
+ rm -r libhello-0.1.0+1;
+ rm $~/$data_dir/libhello-0.1.0.tar.gz;
+ sed -i -e 's/(archive: libhello-0.1.0)(.tar.gz)/\1+1\2/' $data_dir/request.manifest;
+
+ $* "file:///$~/tgt.git" $data_dir >>"EOO" &tgt/1/alpha/hello/libhello-0.1.0+1.tar.gz;
+ : 1
+ status: 200
+ message: package submission is queued: libhello/0.1.0+1
+ reference: $checksum
+ EOO
+
+ $g -C tgt pull;
+
+ test -f tgt/1/alpha/hello/libhello-0.1.0.tar.gz == 1;
+ test -f tgt/1/alpha/hello/libhello-0.1.0+1.tar.gz;
+
+ # While at it, test the older revision submission.
+ #
+ $clone_root_data_clean;
+
+ $* "file:///$~/tgt.git" $data_dir >>"EOO";
+ : 1
+ status: 422
+ message: newer revision libhello/0.1.0+1 is present
+ reference: $checksum
+ EOO
+
+ test -f tgt/1/alpha/hello/libhello-0.1.0+1.tar.gz
+ }
+
: section-fallback
:
{
@@ -455,6 +546,8 @@ pkg_ctl="$prj_ctl/hello.git"
owners=owners
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt commit -am 'Add section name fallback';
$g -C tgt push;
@@ -572,6 +665,8 @@ pkg_ctl="$prj_ctl/hello.git"
mkdir -p ref/1/alpha/hello;
cp $data_dir/libhello-0.1.0.tar.gz ref/1/alpha/hello/;
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add 1/;
$g -C ref commit -m 'Add libhello-0.1.0.tar.gz';
$g -C ref push;
@@ -613,6 +708,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/foo
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add ownership info';
$g -C ref push;
@@ -645,6 +742,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: https://example.com/foo
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners/hello/project-owner.manifest;
$g -C ref commit -m 'Add project ownership info';
$g -C ref push;
@@ -686,6 +785,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/foo
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add ownership info';
$g -C ref push;
@@ -712,6 +813,8 @@ pkg_ctl="$prj_ctl/hello.git"
mkdir -p tgt/1/alpha/hello;
cp $data_dir/libhello-0.1.0.tar.gz tgt/1/alpha/hello/;
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt add 1/;
$g -C tgt commit -m 'Add libhello-0.1.0.tar.gz';
$g -C tgt push;
@@ -752,6 +855,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/foo
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt add owners;
$g -C tgt commit -m 'Add ownership info';
$g -C tgt push;
@@ -784,6 +889,8 @@ pkg_ctl="$prj_ctl/hello.git"
# owners=owners
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt commit -am 'Disable ownership';
$g -C tgt push;
@@ -817,6 +924,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/
EOI
+ $g -C ref config user.name 'Test Script';
+ $g -C ref config user.email 'testscript@example.com';
$g -C ref add owners;
$g -C ref commit -m 'Add project ownership info';
$g -C ref push;
@@ -832,6 +941,8 @@ pkg_ctl="$prj_ctl/hello.git"
# owners=owners
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt commit -am 'Disable ownership';
$g -C tgt push;
@@ -872,6 +983,8 @@ pkg_ctl="$prj_ctl/hello.git"
control: $prj_ctl/foo
EOI
+ $g -C tgt config user.name 'Test Script';
+ $g -C tgt config user.email 'testscript@example.com';
$g -C tgt add owners;
$g -C tgt commit -m 'Add ownership info';
$g -C tgt push;
diff --git a/tests/submit/submit-pub.testscript b/tests/submit/submit-pub.testscript
new file mode 100644
index 0000000..8c042a7
--- /dev/null
+++ b/tests/submit/submit-pub.testscript
@@ -0,0 +1,213 @@
+# file : tests/submit/submit-pub.testscript
+# license : MIT; see accompanying LICENSE file
+
+.include data.testscript
+
+user=$getenv("USER")
+
+# Disable tests if the password-less sudo is not enabled for the user.
+#
++if! sudo -u "$user" --non-interactive echo 'test' >'test'
+ exit
+end
+
+root_rep=$~/pkg-1
+
++mkdir -p $root_rep/1
++echo ": 1" >=$root_rep/1/repositories.manifest
++bpkg rep-create $root_rep/1 2>! &$root_rep/1/packages.manifest
+
+clone_root_rep = [cmdline] cp --no-cleanup -r $root_rep ./ &pkg-1/*** &?pkg.lock
+
+: args
+{
+ : none
+ :
+ $* 2>>~%EOE% != 0
+ %\[.+\] \[brep:error\] \[ref \] \[brep-submit-pub\]: usage: .+brep-submit-pub \[<options>\] \[<loader-path> <loader-options>\] <repo> <dir>%
+ EOE
+
+ : few
+ :
+ $* 2>>~%EOE% != 0
+ %\[.+\] \[brep:error\] \[ref \] \[brep-submit-pub\]: usage: .+brep-submit-pub \[<options>\] \[<loader-path> <loader-options>\] <repo> <dir>%
+ EOE
+
+ : repo-not-exist
+ :
+ $* $~/repo $~/dir 2>>~%EOE% != 0
+ %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-pub\]: '.+repo' does not exist or is not a symlink%
+ EOE
+
+ : dir-not-exist
+ :
+ {
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+ $* $~/pkg $~/dir 2>>~%EOE% != 0
+ %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-pub\]: '.+dir' does not exist or is not a directory%
+ EOE
+ }
+}
+
+: success
+:
+{
+ test.options += --user "$user"
+
+ : simulate
+ :
+ {
+ $clone_root_data;
+ echo 'simulate: success' >+$data_dir/request.manifest;
+
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+
+ $* $~/pkg $~/$data_dir >>"EOO";
+ : 1
+ status: 200
+ message: package is published: libhello/0.1.0
+ reference: $checksum
+ EOO
+
+ test -d $data_dir != 0
+ }
+
+ : for-real
+ :
+ : Here we also create the package revision which is expected to be removed
+ : by the handler.
+ :
+ {
+ $clone_root_data;
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+
+ # Initial submission.
+ #
+ $* $~/pkg $~/$data_dir &!pkg-1/*** &pkg-*/*** >>"EOO";
+ : 1
+ status: 200
+ message: package is published: libhello/0.1.0
+ reference: $checksum
+ EOO
+
+ test -f pkg/1/hello/libhello-0.1.0.tar.gz;
+
+ # While at it, test the duplicate submission.
+ #
+ $clone_root_data_clean;
+
+ $* $~/pkg $~/$data_dir >>"EOO";
+ : 1
+ status: 422
+ message: duplicate submission
+ reference: $checksum
+ EOO
+
+ test -f pkg/1/hello/libhello-0.1.0.tar.gz;
+
+ # Revision submission.
+ #
+ # Here we test that the handler removes the previous revision.
+ #
+ tar -xf $~/$data_dir/libhello-0.1.0.tar.gz;
+ sed -i -e 's/(version: 0.1.0)/\1+1/' libhello-0.1.0/manifest;
+ mv libhello-0.1.0 libhello-0.1.0+1;
+ tar cfz $~/$data_dir/libhello-0.1.0+1.tar.gz libhello-0.1.0+1;
+ rm -r libhello-0.1.0+1;
+ rm $~/$data_dir/libhello-0.1.0.tar.gz;
+ sed -i -e 's/(archive: libhello-0.1.0)(.tar.gz)/\1+1\2/' $data_dir/request.manifest;
+
+ $* $~/pkg $~/$data_dir >>"EOO";
+ : 1
+ status: 200
+ message: package is published: libhello/0.1.0+1
+ reference: $checksum
+ EOO
+
+ test -f pkg/1/hello/libhello-0.1.0.tar.gz == 1;
+ test -f pkg/1/hello/libhello-0.1.0+1.tar.gz;
+
+ # While at it, test the older revision submission.
+ #
+ $clone_root_data_clean;
+
+ $* $~/pkg $~/$data_dir >>"EOO";
+ : 1
+ status: 422
+ message: newer revision libhello/0.1.0+1 is present
+ reference: $checksum
+ EOO
+
+ test -f pkg/1/hello/libhello-0.1.0+1.tar.gz
+ }
+
+ : result-url
+ :
+ {
+ $clone_root_data;
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+
+ test.options += --result-url 'https://example.com/';
+
+ $* $~/pkg $~/$data_dir &!pkg-1/*** &pkg-*/*** >>"EOO"
+ : 1
+ status: 200
+ message: package is published: https://example.com/libhello/0.1.0
+ reference: $checksum
+ EOO
+ }
+}
+
+: failure
+:
+{
+ test.options += --user "$user"
+
+ : invalid-package
+ :
+ : Here we remove repositories.manifest to make sure that the bpkg-rep-create
+ : failure ends up with a proper response.
+ :
+ {
+ $clone_root_data_clean;
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+
+ rm pkg/1/repositories.manifest;
+
+ $* $~/brep-loader $~/pkg $~/$data_dir >>~"%EOO%"
+ : 1
+ status: 400
+ message:\\
+ submitted archive is not a valid package
+ %.+
+ \\
+ reference: $checksum
+ EOO
+ }
+
+ : not-loadable
+ :
+ : Here we specify a non-existing brep loader program to make sure that the
+ : brep database load failure ends up with a proper response.
+ :
+ {
+ $clone_root_data_clean;
+ $clone_root_rep;
+ ln -s pkg-1 pkg;
+
+ $* $~/brep-loader $~/pkg $~/$data_dir >>~"%EOO%"
+ : 1
+ status: 400
+ message:\\
+ unable to add package to repository
+ %.+
+ \\
+ reference: $checksum
+ EOO
+ }
+}