From d0f18585144b84568db858003207edc7448da301 Mon Sep 17 00:00:00 2001 From: Ed Smith Date: Thu, 24 Nov 2022 22:34:49 +0000 Subject: [PATCH] Allow job artifacts to be retrieved from the mock This is useful when testing whether the artifacts uploaded are as expected. In particular, we need this now to test whether masked artifacts are actually being masked as we expect them to be. Note that we are returning the raw binary of the zipfile, and we'll need to use the zipfile crate to actually interpret this data. That seems acceptable for now. --- gitlab-runner-mock/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gitlab-runner-mock/src/lib.rs b/gitlab-runner-mock/src/lib.rs index e75b00f..6030bb2 100644 --- a/gitlab-runner-mock/src/lib.rs +++ b/gitlab-runner-mock/src/lib.rs @@ -134,6 +134,16 @@ impl GitlabRunnerMock { jobs.jobs.push(job); } + pub fn get_job_artifact(&self, id: u64) -> Option> { + let jobs = self.inner.jobs.lock().unwrap(); + + jobs + .jobs + .iter() + .find(|j| j.id() == id) + .map(|j| j.artifact().as_slice().to_vec()) + } + fn grab_pending_job(&self) -> Option { let jobs = self.inner.jobs.lock().unwrap(); for job in jobs.jobs.iter() {