summaryrefslogtreecommitdiff
path: root/yarns/400-build.yarn
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-27 17:52:38 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-27 17:52:38 +0300
commit5173ddc34c3d644f1e05482a678eea12042319c4 (patch)
treed2186b9f355c1f05c23d31a7b665d0dbfda30d86 /yarns/400-build.yarn
parent2cf2195240b5befe58bd34fd77141444ec07e3d3 (diff)
downloadick2-5173ddc34c3d644f1e05482a678eea12042319c4.tar.gz
Add: first draft of yarn scenario for building a project
Diffstat (limited to 'yarns/400-build.yarn')
-rw-r--r--yarns/400-build.yarn241
1 files changed, 241 insertions, 0 deletions
diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn
new file mode 100644
index 0000000..0e030fd
--- /dev/null
+++ b/yarns/400-build.yarn
@@ -0,0 +1,241 @@
+<!--
+
+Copyright 2017 Lars Wirzenius
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+-->
+
+# Build a project
+
+This scenario tests the controller API to simulate a build.
+
+ SCENARIO build a project
+
+Set up the controller.
+
+ GIVEN an RSA key pair for token signing
+ AND controller config uses statedir at the state directory
+ AND a running ick controller
+
+Add up a project.
+
+ GIVEN an access token for user with scopes
+ ... uapi_projects_post
+ ... uapi_projects_id_pipeline_id_put
+ ... uapi_projects_id_pipeline_id_get
+ ... uapi_projects_id_builds_get
+ WHEN user makes request POST /projects
+ ... {
+ ... "project": "rome",
+ ... "pipelines": [
+ ... {
+ ... "name": "construct",
+ ... "actions": [
+ ... { "shell": "day 1" },
+ ... { "shell": "day 2" }
+ ... ]
+ ... }
+ ... ]
+ ... }
+ THEN result has status code 201
+
+There are no builds for the project yet, and is idle.
+
+ WHEN user makes request GET /projects/rome/pipelines/construct
+ THEN result has status code 200
+ AND body matches { "status": "idle" }
+
+ WHEN user makes request GET /projects/rome/builds
+ THEN result has status code 200
+ AND body matches { "project": "rome", "builds": []}
+
+Register a worker.
+
+ GIVEN an access token for worker-manager with scopes
+ ... uapi_workers_post
+ WHEN worker-manager makes request POST /workers
+ ... {
+ ... "worker": "obelix",
+ ... }
+ THEN result has status code 201
+
+Trigger build. First with an invalid status, then a real one.
+
+ WHEN user makes request PUT /projects/rome/pipelines/construct
+ ... { "status": "VANDALS!" }
+ THEN result has status code 400
+
+ WHEN user makes request PUT /projects/rome/pipelines/construct
+ ... { "status": "triggered" }
+ THEN result has status code 200
+
+Worker wants work and gets the first step to run. If the worker asks
+again, it gets the same answer. **FIXME: should the name of the worker
+be in the path or can we get it in the access token?**
+
+ WHEN worker-manager makes request GET /work/obelix
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "step": {
+ ... "shell": "day 1"
+ ... }
+ ... }
+
+ WHEN worker-manager makes request GET /work/obelix
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "step": {
+ ... "shell": "day 1"
+ ... }
+ ... }
+
+User can now see pipeline is running and which worker is building it.
+
+ WHEN user makes request GET /projects/rome/pipelines/construct
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "status": "running",
+ ... "worker": "obelix",
+ ... "step_number": 1,
+ ... "step": {
+ ... "shell": "day 1"
+ ... }
+ ... }
+
+Worker reports some build output. Note the null exit code.
+
+ WHEN worker-manager makes request POST /work
+ ... {
+ ... "worker": "obelix",
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "exít_code": null,
+ ... "stdout": "hey ho hey ho",
+ ... "stderr": "",
+ ... "timestamp": "2017-10-27T17:08:49"
+ ... }
+ THEN result has status code 200
+ AND body matches { "result": "waiting for more" }
+
+Still the same job, since the first build step didnt't finish.
+
+ WHEN worker-manager makes request GET /work/obelix
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "step": {
+ ... "shell": "day 1"
+ ... }
+ ... }
+
+Report the step is done, and successfully.
+
+ WHEN worker-manager makes request POST /work
+ ... {
+ ... "worker": "obelix",
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "exít_code": 0,
+ ... "stdout": "hey ho, hey ho\n",
+ ... "stderr": "",
+ ... "timestamp": "2017-10-27T17:08:49"
+ ... }
+ THEN result has status code 200
+ AND body matches { "result": "next step awaits you" }
+
+Now there's another step to do.
+
+ WHEN worker-manager makes request GET /work/obelix
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "step": {
+ ... "shell": "day 2"
+ ... }
+ ... }
+
+User sees changed status.
+
+ WHEN user makes request GET /projects/rome/pipelines/construct
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "status": "running",
+ ... "worker": "obelix",
+ ... "step_number": 2,
+ ... "step": {
+ ... "shell": "day 2"
+ ... }
+ ... }
+
+Report it done.
+
+ WHEN worker-manager makes request POST /work
+ ... {
+ ... "worker": "obelix",
+ ... "project": "rome",
+ ... "pipeline": "construct",
+ ... "exít_code": 0,
+ ... "stdout": "to the gold mine we go!\n",
+ ... "stderr": "",
+ ... "timestamp": "2017-10-27T17:08:49"
+ ... }
+ THEN result has status code 200
+ AND body matches { "result": "no more steps" }
+
+Now there's no more work to do.
+
+ WHEN worker-manager makes request GET /work/obelix
+ THEN result has status code 200
+ AND body matches {}
+
+The pipeline status indicates success.
+
+ WHEN user makes request GET /projects/rome/pipelines/construct
+ THEN result has status code 200
+ AND body matches { "status": "idle" }
+
+Also, there's a build with a log.
+
+ WHEN user makes request GET /projects/rome/builds
+ THEN result has status code 200
+ AND body matches
+ ... {
+ ... "project": "rome",
+ ... "builds": [
+ ... {
+ ... "pipeline": "construct",
+ ... "build_number": 1,
+ ... "status": "success",
+ ... "log": "/projects/rome/logs/1"
+ ... }
+ ... ]
+ ... }
+
+ WHEN user makes request GET /projects/rome/logs/1
+ THEN result has status code 200
+ AND result has header Content-Type: text/plain
+ AND body matches "hey ho, hey ho\nto the gold mine we go!\n"