diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-08-31 21:41:53 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-09-01 18:36:07 +0300 |
commit | b1888e516c9c9d750726318227bf69856ec91b8b (patch) | |
tree | 446fa1cdd1a9a9bf1827eba2a4f5bac7876f65ad /tests | |
parent | d22f466823192963c22eb8f51ae930cb5af8fa9a (diff) |
Add ci-load
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ci/8716f424-fd94-4def-9e2e-687203bbf4ad/request.manifest | 7 | ||||
-rw-r--r-- | tests/ci/README | 11 | ||||
-rw-r--r-- | tests/ci/buildfile | 6 | ||||
-rw-r--r-- | tests/ci/ci-dir.test | 19 | ||||
-rw-r--r-- | tests/ci/ci-load.test | 141 | ||||
-rw-r--r-- | tests/ci/data.test | 32 | ||||
-rw-r--r-- | tests/submit/0f6b1460b3ec/package.manifest | 10 | ||||
-rw-r--r-- | tests/submit/0f6b1460b3ec/result.manifest | 4 | ||||
-rw-r--r-- | tests/submit/README | 12 | ||||
-rw-r--r-- | tests/submit/submit-dir.test | 2 | ||||
-rw-r--r-- | tests/submit/submit-git.test | 11 |
11 files changed, 213 insertions, 42 deletions
diff --git a/tests/ci/8716f424-fd94-4def-9e2e-687203bbf4ad/request.manifest b/tests/ci/8716f424-fd94-4def-9e2e-687203bbf4ad/request.manifest new file mode 100644 index 0000000..3ef553a --- /dev/null +++ b/tests/ci/8716f424-fd94-4def-9e2e-687203bbf4ad/request.manifest @@ -0,0 +1,7 @@ +: 1 +id: 8716f424-fd94-4def-9e2e-687203bbf4ad +repository: https://git.build2.org/hello/hello.git#master +package: hello +timestamp: 2018-09-01T08:38:55Z +client-ip: fe80::56e1:adff:fe83:82f5 +user-agent: curl/7.59.0 diff --git a/tests/ci/README b/tests/ci/README new file mode 100644 index 0000000..14defe5 --- /dev/null +++ b/tests/ci/README @@ -0,0 +1,11 @@ +Prepare the test data with the following instructions. + +Locally run brep server configured to use ci-dir handler. + +$ curl \ +--form-string repository=https://git.build2.org/hello/hello.git#master \ +--form-string package=hello \ +http://localhost/pkg?ci + +Replace the submission data directory in brep/tests/ci/ with the one produced +with the above command, removing all files it contains except request.manifest. diff --git a/tests/ci/buildfile b/tests/ci/buildfile index b1c3146..1e085e0 100644 --- a/tests/ci/buildfile +++ b/tests/ci/buildfile @@ -11,6 +11,8 @@ include $dir commons = data -./: test{* -{$commons}} common{$commons} $dir/exe{brep-ci-dir} +./: test{* -{$commons}} common{$commons} \ + $dir/exe{brep-ci-dir} $dir/exe{brep-ci-load} -test{ci-dir}@./: test = $out_base/$dir/brep-ci-dir +test{ci-dir}@./: test = $out_base/$dir/brep-ci-dir +test{ci-load}@./: test = $out_base/$dir/brep-ci-load diff --git a/tests/ci/ci-dir.test b/tests/ci/ci-dir.test index 0e98f3a..11de2f0 100644 --- a/tests/ci/ci-dir.test +++ b/tests/ci/ci-dir.test @@ -12,7 +12,7 @@ %\[.+\] \[brep:error\] \[ref \] \[brep-ci-dir\]: usage: .+brep-ci-dir <dir>% EOE - : not-exist + : dir-not-exist : $* $~/dir 2>>~%EOE% != 0 %\[.+\] \[brep:error\] \[ref dir\] \[brep-ci-dir\]: '.+dir' does not exist or is not a directory% @@ -74,4 +74,21 @@ reference: $request_id EOO } + + : unable-fetch-repo + : + { + $clone_root_data_clean; + + sed -i -e "s%^\(repository:\) .+\$%\\1 http://example.com/repo.git%" \ + $data_dir/request.manifest; + + $* >>~"%EOO%" + : 1 + status: 422 + %message: unable to fetch repository information .+% + %.* + reference: $request_id + EOO + } } diff --git a/tests/ci/ci-load.test b/tests/ci/ci-load.test new file mode 100644 index 0000000..c4a4c62 --- /dev/null +++ b/tests/ci/ci-load.test @@ -0,0 +1,141 @@ +# file : tests/ci/ci-load.test +# copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include data.test + +: args +{ + : none + : + $* 2>>~%EOE% != 0 + %\[.+\] \[brep:error\] \[ref \] \[brep-ci-load\]: usage: .+brep-ci-load \[--result-url <url>\] <loader-path> \[<loader-options>\] <dir>% + EOE + + : no-dir + : + $* brep-load 2>>~%EOE% != 0 + %\[.+\] \[brep:error\] \[ref brep-load\] \[brep-ci-load\]: usage: .+brep-ci-load \[--result-url <url>\] <loader-path> \[<loader-options>\] <dir>% + EOE + + : dir-not-exist + : + $* brep-load $~/dir 2>>~%EOE% != 0 + %\[.+\] \[brep:error\] \[ref dir\] \[brep-ci-load\]: '.+dir' does not exist or is not a directory% + EOE +} + +: success +: +{ + : simulate + : + { + $clone_root_data; + + echo 'simulate: success' >+$data_dir/request.manifest; + + $* ./brep-load $data_dir >>"EOO"; + : 1 + status: 200 + message: CI request is queued + reference: $request_id + EOO + + test -d $data_dir != 0 + } + + : for-real + : + { + # Create the loader script that validates the arguments passed and the + # files produced by the handler. + # + loader=$~/brep-load + + cat <<"EOI" >=$loader; + #!/usr/bin/env bash + if [ "\$#" != 5 -o \ + "\$1" != "--db-host=localhost" -o \ + "\$2" != "--db-port=8432" -o \ + "\$3" != "--force" -o \ + "\$4" != "--shallow" -o \ + "\$5" != "$data_dir/loadtab" -o \ + ! -f "$data_dir/cache/repositories.manifest" -o \ + ! -f "$data_dir/cache/packages.manifest" ]; then + exit 1 + fi + if ! diff "$data_dir/loadtab" - <<<"https://git.build2.org/hello/hello.git#master hello cache:cache"; then + exit 1 + fi + EOI + + chmod 755 $loader; + + $clone_root_data; + + $* $loader --db-host=localhost --db-port=8432 $data_dir >>"EOO" + : 1 + status: 200 + message: CI request is queued + reference: $request_id + EOO + + $clone_root_data; + + $* --result-url "http://example.com/" \ + $loader --db-host=localhost --db-port=8432 \ + $data_dir >>"EOO" + : 1 + status: 200 + message: CI request is queued: http://example.com + reference: $request_id + EOO + } +} + +: failure +: +{ + test.arguments += ./brep-load $data_dir + + : bad-simulate + : + { + $clone_root_data_clean; + + echo 'simulate: fly' >+$data_dir/request.manifest; + + $* >>"EOO" + : 1 + status: 400 + message: unrecognized simulation outcome 'fly' + reference: $request_id + EOO + } + + : unable-fetch-repo + : + { + $clone_root_data_clean; + + sed -i -e "s%^\(repository:\) .+\$%\\1 http://example.com/repo.git%" \ + $data_dir/request.manifest; + + $* >>~"%EOO%" + : 1 + status: 422 + %message: unable to fetch repository information .+% + %.* + reference: $request_id + EOO + } + + : loader-not-exist + : + { + $clone_root_data_clean; + + $* 2>~'%.*brep-load.*%' != 0 + } +} diff --git a/tests/ci/data.test b/tests/ci/data.test index c30a691..19383b1 100644 --- a/tests/ci/data.test +++ b/tests/ci/data.test @@ -2,28 +2,24 @@ # copyright : Copyright (c) 2014-2018 Code Synthesis Ltd # license : MIT; see accompanying LICENSE file -# Pre-created CI request 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 +# Pre-created CI request 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. # -request_id = 4cfa00ec-8459-4f4f-9ef0-8883ddcc4f5b -data_dir = $request_id/ +data_dir = $regex.replace($path_search('*/request.manifest', $src_base), \ + '(.*)/.*', \ + '\1') -+mkdir $data_dir +request_id = "$data_dir" -+cat <<"EOI" >=$data_dir/request.manifest - : 1 - id: $request_id - repository: https://example.com/hello.git#master - package: foo - package: bar/1.0 - timestamp: 2018-08-24T18:08:01Z - EOI +# Copy the original CI request data directory to the root scope. +# ++cp -r $src_base/$data_dir ./ root_data_dir = $~/$data_dir diff --git a/tests/submit/0f6b1460b3ec/package.manifest b/tests/submit/0f6b1460b3ec/package.manifest deleted file mode 100644 index 6fc36e7..0000000 --- a/tests/submit/0f6b1460b3ec/package.manifest +++ /dev/null @@ -1,10 +0,0 @@ -: 1 -name: libhello -version: 0.1.0 -project: hello -summary: hello library -license: TODO -url: https://example.org/hello -email: user@example.org -depends: * build2 >= 0.8.0- -depends: * bpkg >= 0.8.0- diff --git a/tests/submit/0f6b1460b3ec/result.manifest b/tests/submit/0f6b1460b3ec/result.manifest deleted file mode 100644 index 93a3555..0000000 --- a/tests/submit/0f6b1460b3ec/result.manifest +++ /dev/null @@ -1,4 +0,0 @@ -: 1 -status: 200 -message: libhello/0.1.0 submission is queued -reference: 0f6b1460b3ec diff --git a/tests/submit/README b/tests/submit/README index 7286c83..49ebd1e 100644 --- a/tests/submit/README +++ b/tests/submit/README @@ -22,9 +22,13 @@ Move the archive into brep/tests/submit/ directory. Locally run brep server configured to use submit-dir handler. -$ bdep publish --control http://example.org/hello.git \ - --email user@example.org --repository http://localhost/pkg --yes \ - -d hello +$ bdep publish \ +--control http://example.org/hello.git \ +--email user@example.org \ +--repository http://localhost/pkg \ +--yes \ +-d hello Replace the submission data directory in brep/tests/submit/ with the one -produced with the above command. +produced with the above command, removing package.manifest and result.manifest +files it contains. diff --git a/tests/submit/submit-dir.test b/tests/submit/submit-dir.test index a6a7e3e..821898e 100644 --- a/tests/submit/submit-dir.test +++ b/tests/submit/submit-dir.test @@ -12,7 +12,7 @@ %\[.+\] \[brep:error\] \[ref \] \[brep-submit-dir\]: usage: .+brep-submit-dir <dir>% EOE - : not-exist + : dir-not-exist : $* $~/dir 2>>~%EOE% != 0 %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-dir\]: '.+dir' does not exist or is not a directory% diff --git a/tests/submit/submit-git.test b/tests/submit/submit-git.test index f96f79d..bedfd5f 100644 --- a/tests/submit/submit-git.test +++ b/tests/submit/submit-git.test @@ -66,15 +66,22 @@ pkg_ctl="$prj_ctl/hello.git" : dir-only : - $* $~/dir 2>>~%EOE% != 0 + $* dir 2>>~%EOE% != 0 %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-git\]: usage: .+brep-submit-git \[<options>\] <tgt-repo> \[<ref-repo>\] <dir>% EOE : ref-not-exist : - $* "$root_tgt_url" ref $~/dir 2>>~%EOE% != 0 + $* "$root_tgt_url" ref dir 2>>~%EOE% != 0 %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-git\]: 'ref' does not exist or is not a directory% EOE + + : dir-not-exist + : + mkdir ref; + $* "$root_tgt_url" ref dir 2>>~%EOE% != 0 + %\[.+\] \[brep:error\] \[ref dir\] \[brep-submit-git\]: 'dir' does not exist or is not a directory% + EOE } : success |