Add a rudimentary test on the building of a PR

This commit is contained in:
Graham Christensen 2018-01-19 20:42:11 -05:00
parent 3979a82b71
commit fc0e89ce01
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
7 changed files with 156 additions and 0 deletions

1
ofborg/.gitignore vendored
View file

@ -1,2 +1,3 @@
target
rust-amqp
test-scratch

View file

@ -21,6 +21,24 @@ pub trait NotificationReceiver {
fn tell(&mut self, action: Action);
}
pub struct DummyNotificationReceiver {
pub actions: Vec<Action>
}
impl DummyNotificationReceiver {
pub fn new() -> DummyNotificationReceiver {
DummyNotificationReceiver {
actions: vec![],
}
}
}
impl NotificationReceiver for DummyNotificationReceiver {
fn tell(&mut self, action: Action) {
self.actions.push(action);
}
}
pub struct ChannelNotificationReceiver<'a> {
channel: &'a mut Channel,
delivery_tag: u64,

View file

@ -210,3 +210,72 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
);
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::{Path,PathBuf};
use ofborg::message::{Pr,Repo};
use notifyworker::SimpleNotifyWorker;
use std::process::{Command, Stdio};
fn nix() -> nix::Nix {
nix::Nix::new("x86_64-linux".to_owned(), "daemon".to_owned(), 1800)
}
fn tpath(component: &str)-> PathBuf {
return Path::new(env!("CARGO_MANIFEST_DIR")).join(component);
}
fn make_pr_repo() -> String{
let output = Command::new("./make-pr.sh")
.current_dir(tpath("./test-srcs"))
.stderr(Stdio::null())
.stdout(Stdio::piped())
.output()
.expect("building the test PR failed");
let hash = String::from_utf8(output.stdout).expect("Should just be a hash");
return hash.trim().to_owned();
}
#[test]
pub fn test_simple_build() {
Command::new("rm")
.arg("-rf")
.arg(&tpath("./test-scratch"))
.status()
.expect("cleanup of test-scratch should work");
// pub fn new(cloner: checkout::CachedCloner, nix: nix::Nix, system: String, identity: String) -> BuildWorker {
let cloner = checkout::cached_cloner(&tpath("./test-scratch"));
let nix = nix();
let worker = BuildWorker::new(
cloner,
nix,
"x86_64-linux".to_owned(),
"cargo-test-build".to_owned()
);
let job = buildjob::BuildJob{
attrs: vec!["success".to_owned()],
pr: Pr{
head_sha: make_pr_repo(),
number: 1,
target_branch: Some("master".to_owned()),
},
repo: Repo{
clone_url: tpath("./test-srcs/bare-repo").to_str().unwrap().to_owned(),
full_name: "test-git".to_owned(),
name: "nixos".to_owned(),
owner: "ofborg-test".to_owned(),
},
subset: None,
};
let mut dummyreceiver = notifyworker::DummyNotificationReceiver::new();
worker.consumer(&job, &mut dummyreceiver);
panic!("{:?}", dummyreceiver.actions);
}
}

2
ofborg/test-srcs/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bare-repo
repo-co

View file

@ -0,0 +1,27 @@
let
nix = import <nix/config.nix>;
in {
success = derivation {
name = "success";
system = builtins.currentSystem;
builder = nix.shell;
args = [
"-c"
"echo hi; printf '1\n2\n3\n4\n'; echo ${toString builtins.currentTime} > $out" ];
};
failed = derivation {
name = "failed";
system = builtins.currentSystem;
builder = nix.shell;
args = [
"-c"
"echo hi; echo ${toString builtins.currentTime}" ];
};
sandbox-violation = derivation {
name = "sandbox-violation";
system = builtins.currentSystem;
builder = ./../../src;
};
}

View file

@ -0,0 +1,4 @@
#!/bin/sh
echo "$@"
echo hi

35
ofborg/test-srcs/make-pr.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/sh
set -eux
(
rm -rf bare-repo repo-co
git init --bare bare-repo
git clone ./bare-repo ./repo-co
(
cp build/* repo-co/
cd repo-co
git add .
git commit --no-gpg-sign -m "initial repo commit"
git push origin master
)
(
cp build-pr/* repo-co/
cd repo-co
git checkout -b my-cool-pr
git add .
git commit --no-gpg-sign -m "check out this cool PR"
git push origin my-cool-pr:refs/pull/1/head
)
) >&2
(
cd repo-co
git rev-parse HEAD
)