Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
refactor: change test shell commands
Fintan Halpenny committed 1 year ago
commit 8cbc1fe3130345479c7719ea45b71558c6c2520e
parent 25a8d24d303f86cec672c792bb702edbd533df34
6 files changed +28 -35
modified README.md
@@ -80,6 +80,7 @@ following programs installed for the test suite:
* `git`
* `sqlite3`
* `rad` (from Radicle)
+
* `git-remote-rad` (from Radicle)

## Configuration

modified ci-broker.md
@@ -105,7 +105,7 @@ the CI broker logs adapter error output, and doesn't harm other uses
of the adapter.

~~~{#dummy.sh .file .sh}
-
#!/bin/bash
+
#!/bin/sh
set -euo pipefail
cat > /dev/null
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
@@ -164,7 +164,7 @@ then command is successful
~~~

~~~{#which.sh .file .sh}
-
#!/bin/bash
+
#!/bin/sh
# We use Bash build-in command as that's portable. "which" is not.
command -v "$1"
~~~
@@ -449,7 +449,7 @@ then stdout has one line
~~~

~~~{#create-patch .file .sh}
-
#!/bin/bash
+
#!/bin/sh
set -euo pipefail

touch foo
@@ -510,7 +510,7 @@ then command is successful
~~~

~~~{#adapter-with-url.sh .file .sh}
-
#!/bin/bash
+
#!/bin/sh
set -euo pipefail
echo '{"response":"triggered","run_id":{"id":"xyzzy"},"info_url":"https://ci.example.com/xyzzy"}'
echo '{"response":"finished","result":"success"}'
@@ -664,7 +664,7 @@ This adapter outputs a broken response message, and after that
something to its stderr. The CI broker is meant to read and log both.

~~~{#broken-adapter.sh .file .sh}
-
#!/bin/bash
+
#!/bin/sh
set -euo pipefail
cat > /dev/null
echo '{"response":"Rivendell"}}'
@@ -973,7 +973,7 @@ then stdout contains "OK\n"
~~~

~~~{#count.sh .file .sh}
-
#!/bin/bash
+
#!/bin/sh

set -euo pipefail

@@ -1682,7 +1682,7 @@ when I run ./env.sh bash -x verify-upgrade run-list.txt HEAD
~~~

~~~{#verify-upgrade .file .sh}
-
#!/bin/bash
+
#!/bin/sh
#
# Given a list of CI runs and a CI broker version, build and run that
# version so that it triggers and runs CI on a given change. Then
modified src/adapter.rs
@@ -391,7 +391,7 @@ mod test {

    #[test]
    fn adapter_reports_success() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
@@ -413,7 +413,7 @@ echo '{"response":"finished","result":"success"}'

    #[test]
    fn adapter_reports_failure() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"failure"}'
@@ -440,7 +440,7 @@ echo '{"response":"finished","result":"failure"}'

    #[test]
    fn adapter_exits_nonzero() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"failure"}'
@@ -466,8 +466,8 @@ exit 1

    #[test]
    fn adapter_is_killed_before_any_messages() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
-
kill -9 $BASHPID
+
        const ADAPTER: &str = r#"#!/bin/sh
+
kill -9 $$
"#;

        let tmp = tempdir()?;
@@ -487,10 +487,10 @@ kill -9 $BASHPID

    #[test]
    fn adapter_is_killed_after_first_message() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
-
kill -9 $BASHPID
+
kill -9 $$
"#;

        let tmp = tempdir()?;
@@ -510,7 +510,7 @@ kill -9 $BASHPID

    #[test]
    fn adapter_ends_ok_before_second_message() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
"#;
@@ -532,11 +532,11 @@ echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'

    #[test]
    fn adapter_is_killed_after_second_message() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
-
kill -9 $BASHPID
+
kill -9 $$
"#;

        let tmp = tempdir()?;
@@ -556,7 +556,7 @@ kill -9 $BASHPID

    #[test]
    fn adapter_produces_as_bad_message() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success","bad":"field"}'
@@ -582,7 +582,7 @@ echo '{"response":"finished","result":"success","bad":"field"}'

    #[test]
    fn adapter_first_message_isnt_triggered() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"finished","result":"success"}'
"#;
@@ -609,7 +609,7 @@ echo '{"response":"finished","result":"success"}'

    #[test]
    fn adapter_outputs_too_many_messages() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
@@ -660,7 +660,7 @@ echo '{"response":"finished","result":"success"}'

    #[test]
    fn adapter_is_not_executable() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
modified src/broker.rs
@@ -197,7 +197,7 @@ mod test {

    #[test]
    fn executes_adapter() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
@@ -227,7 +227,7 @@ echo '{"response":"finished","result":"success"}'

    #[test]
    fn adapter_fails() -> TestResult<()> {
-
        const ADAPTER: &str = r#"#!/bin/bash
+
        const ADAPTER: &str = r#"#!/bin/sh
read
echo '{"response":"triggered","run_id":{"id":"xyzzy"}}'
echo '{"response":"finished","result":"success"}'
modified src/subplot.rs
@@ -114,7 +114,7 @@ fn setup_node(context: &ScenarioContext, config: SubplotDataFile, adapter: Subpl

            println!("create env.sh script");
            {
-
                const SCRIPT: &str = r#"#!/bin/bash
+
                const SCRIPT: &str = r#"#!/bin/sh
echo "env.sh starts"
if [ -e env ]; then . ./env; fi
exec "$@"
modified src/timeoutcmd.rs
@@ -587,7 +587,7 @@ mod tests {
        timeout: Duration,
        stdin: Option<&'static str>,
    ) -> Result<RunningProcess, Box<dyn std::error::Error>> {
-
        let mut cmd = Command::new("bash");
+
        let mut cmd = Command::new("sh");
        cmd.arg("-c").arg(script);
        let mut to = TimeoutCommand::new(timeout);
        if let Some(stdin) = stdin {
@@ -598,11 +598,7 @@ mod tests {

    #[test]
    fn bin_true() -> Result<(), Box<dyn std::error::Error>> {
-
        let running = setup(
-
            "exec /bin/true",
-
            LONG_ENOUGH_THAT_SCRIPT_SURELY_FINISHES,
-
            None,
-
        )?;
+
        let running = setup("exec true", LONG_ENOUGH_THAT_SCRIPT_SURELY_FINISHES, None)?;
        let tor = running.wait()?;
        assert_eq!(tor.status().code(), Some(0));
        assert!(!tor.timed_out());
@@ -611,11 +607,7 @@ mod tests {

    #[test]
    fn bin_false() -> Result<(), Box<dyn std::error::Error>> {
-
        let running = setup(
-
            "exec /bin/false",
-
            LONG_ENOUGH_THAT_SCRIPT_SURELY_FINISHES,
-
            None,
-
        )?;
+
        let running = setup("exec false", LONG_ENOUGH_THAT_SCRIPT_SURELY_FINISHES, None)?;
        let tor = running.wait()?;
        assert_eq!(tor.status().code(), Some(1));
        assert!(!tor.timed_out());