Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
tests: add scenarios to verify new "triggers" functionality
Lars Wirzenius committed 1 year ago
commit aaf687376c0a5a64bf578e866feed0588c6ca532
parent 9af108485d32a05b44dad461c3d4dcd6778c4823
3 files changed +90 -2
modified ci-broker.md
@@ -57,6 +57,43 @@ filters:
  - !Branch "main"
~~~

+
~~~{#broker-with-triggers.yaml .file .yaml}
+
db: ci-broker.db
+
report_dir: reports
+
queue_len_interval: 1min
+
adapters:
+
  mcadapterface:
+
    command: ./adapter.sh
+
    env:
+
      RADICLE_NATIVE_CI: native-ci.yaml
+
    sensitive_env:
+
      API_KEY: xyzzy
+
triggers:
+
  - adapter: mcadapterface
+
    filters:
+
      - !Branch "main"
+
~~~
+

+
~~~{#broker-with-two-triggers.yaml .file .yaml}
+
db: ci-broker.db
+
report_dir: reports
+
queue_len_interval: 1min
+
adapters:
+
  mcadapterface:
+
    command: ./adapter.sh
+
    env:
+
      RADICLE_NATIVE_CI: native-ci.yaml
+
    sensitive_env:
+
      API_KEY: xyzzy
+
triggers:
+
  - adapter: mcadapterface
+
    filters:
+
      - !Branch "main"
+
  - adapter: mcadapterface
+
    filters:
+
      - !Branch "main"
+
~~~
+

~~~{#broker-allow-nothing.yaml .file .yaml}
db: ci-broker.db
report_dir: reports
@@ -293,12 +330,12 @@ nothing else has a hope of working.
_Who:_ `cib-devs`

~~~scenario
-
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
+
given a Radicle node, with CI configured with broker-with-triggers.yaml and adapter dummy.sh
given a Git repository xyzzy in the Radicle node
given the Radicle node emits a refsUpdated event for xyzzy
when I run ./env.sh synthetic-events synt.sock event.json --log log.txt
given a directory reports
-
when I run ./env.sh cib --config broker.yaml process-events
+
when I run ./env.sh cib --config broker-with-triggers.yaml process-events

then stderr contains "CibStart"
then stderr contains "CibConfig"
@@ -315,6 +352,38 @@ then stdout contains ""id": "xyzzy""
~~~


+
## Runs adapters for all matching triggers
+

+
_Want:_ CI broker can run its adapter.
+

+
_Why:_ This is obviously necessary. If this doesn't work,
+
nothing else has a hope of working.
+

+
_Who:_ `cib-devs`
+

+
~~~scenario
+
given a Radicle node, with CI configured with broker-with-two-triggers.yaml and adapter dummy.sh
+
given a Git repository xyzzy in the Radicle node
+
given the Radicle node emits a refsUpdated event for xyzzy
+
when I run ./env.sh synthetic-events synt.sock event.json --log log.txt
+
given a directory reports
+
when I run ./env.sh cib --config broker-with-two-triggers.yaml process-events
+

+
then stderr contains "CibStart"
+
then stderr contains "CibConfig"
+
then stderr contains "CibEndSuccess"
+
then file reports/index.html exists
+
then file reports/status.json exists
+
then file reports/index.rss exists
+

+
when I run cibtool --db ci-broker.db event list
+
then stdout is empty
+

+
when I run cibtool --db ci-broker.db run list
+
then stdout has 2 lines containing "xyzzy"
+
~~~
+

+

## Runs adapter on each type of event

_Want:_ CI broker runs the adapter for each type of CI event.
modified ci-broker.yaml
@@ -25,6 +25,11 @@
    rust:
      function: stdout_has_one_line

+
- then: "stdout has {n:uint} lines containing \"{text:text}\""
+
  impl:
+
    rust:
+
      function: stdout_has_n_lines_containing
+

- then: "stdout is empty"
  impl:
    rust:
modified src/subplot.rs
@@ -398,6 +398,20 @@ fn stdout_has_one_line(runcmd: &Runcmd) {
#[step]
#[context(SubplotContext)]
#[context(Runcmd)]
+
fn stdout_has_n_lines_containing(runcmd: &Runcmd, n: usize, text: &str) {
+
    let linecount = runcmd
+
        .stdout_as_string()
+
        .lines()
+
        .filter(|line| line.contains(text))
+
        .count();
+
    if linecount != n {
+
        throw!(format!("stdout had {linecount} lines, expected {n}"));
+
    }
+
}
+

+
#[step]
+
#[context(SubplotContext)]
+
#[context(Runcmd)]
fn stdout_is_empty(runcmd: &Runcmd) {
    let stdout = runcmd.stdout_as_string();
    if !stdout.is_empty() {