Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
test: add step to install an adapter
Lars Wirzenius committed 1 year ago
commit c377b05a97dc21e212539430b058d8f3891c7b9c
parent d76efe40073b0dcde00c2cb20768259aa10f6f66
3 files changed +46 -14
modified ci-broker.md
@@ -242,6 +242,8 @@ _Who:_ `cib-devs`

~~~scenario
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh
@@ -253,8 +255,6 @@ when I run synthetic-events synt.sock refsfetched.json --log log.txt

given a directory reports
given file broker.yaml
-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh

when I run bash radenv.sh RAD_SOCKET=synt.sock cib --config broker.yaml process-events
then stderr contains "CI broker starts"
@@ -490,6 +490,8 @@ _Who:_ `adapter-devs`, `node-ops`

~~~scenario
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh
@@ -499,8 +501,6 @@ when I run bash radenv.sh cibtool --db ci-broker.db event list --json

given file broker.yaml
given a directory reports
-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh

when I run bash radenv.sh cib --config broker.yaml queued
then stderr contains "Mordor"
@@ -763,13 +763,12 @@ down.

~~~scenario
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

when I run bash radenv.sh cibtool --db ci-broker.db event add --repo testy --ref main --commit HEAD
when I run cibtool --db ci-broker.db event shutdown

@@ -1302,13 +1301,12 @@ when properly set up.

~~~scenario
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

given file broker.yaml
given a directory reports
when I run bash radenv.sh cib --config broker.yaml queued
@@ -1410,6 +1408,8 @@ to be updated when a new release is made.

~~~scenario
given an installed CI broker
+
given a CI adapter adapter.sh from dummy.sh
+

given file radenv.sh
given file setup-node.sh
when I run bash radenv.sh bash setup-node.sh
@@ -1418,9 +1418,6 @@ given file broker.yaml
given file verify-upgrade
given a directory reports

-
given file adapter.sh from dummy.sh
-
when I run chmod +x adapter.sh
-

when I touch file run-list.txt
when I run bash radenv.sh bash -x verify-upgrade run-list.txt 535b1592904125fbe62c3c8c383d7741d9f432ac
when I run bash radenv.sh bash -x verify-upgrade run-list.txt 869b451728d16719b560df142b2d901cbaf3764c
modified ci-broker.yaml
@@ -3,6 +3,11 @@
    rust:
      function: install_ci_broker

+
- given: "a CI adapter {filename:path} from {embedded:file}"
+
  impl:
+
    rust:
+
      function: install_adapter
+

- then: "stdout has one line"
  impl:
    rust:
modified src/subplot.rs
@@ -1,7 +1,14 @@
// Implementations of Subplot scenario steps for the CI broker.

-
use std::path::{Path, PathBuf};
+
use std::{
+
    fs::{set_permissions, Permissions},
+
    io::Write,
+
    os::unix::fs::PermissionsExt,
+
    path::{Path, PathBuf},
+
};

+
use subplotlib::steplibrary::datadir::Datadir;
+
use subplotlib::steplibrary::files::Files;
use subplotlib::steplibrary::runcmd::Runcmd;

#[derive(Debug, Default)]
@@ -37,6 +44,29 @@ fn bindir() -> PathBuf {

#[step]
#[context(SubplotContext)]
+
#[context(Datadir)]
+
#[context(Files)]
+
fn install_adapter(context: &Datadir, filename: &Path, embedded: SubplotDataFile) {
+
    eprintln!(
+
        "install adapter {} from {}:\n{}",
+
        filename.display(),
+
        embedded.name().display(),
+
        String::from_utf8_lossy(embedded.data()),
+
    );
+
    eprintln!("write {}", filename.display());
+
    context.open_write(filename)?.write_all(embedded.data())?;
+
    let realpath = context.canonicalise_filename(filename)?;
+
    eprintln!(
+
        "chmod {} (exists? {})",
+
        realpath.display(),
+
        realpath.exists()
+
    );
+
    let executable = Permissions::from_mode(0o755);
+
    set_permissions(realpath, executable)?;
+
}
+

+
#[step]
+
#[context(SubplotContext)]
#[context(Runcmd)]
fn stdout_has_one_line(runcmd: &Runcmd) {
    let linecount = runcmd.stdout_as_string().lines().count();